Преглед изворни кода

разбираюсь с набором методов из типов-предков

kpmy пре 10 година
родитељ
комит
514714e6f2
6 измењених фајлова са 60 додато и 16 уклоњено
  1. 41 11
      cp/module/module.go
  2. 10 2
      cp/object/comp.go
  3. 1 1
      cp/object/type.go
  4. 3 2
      rt2/rules/call.go
  5. 2 0
      rt2/rules/field.go
  6. 3 0
      rt2/scope/modern/val.go

+ 41 - 11
cp/module/module.go

@@ -2,9 +2,12 @@ package module
 
 import (
 	"fmt"
+	"fw/cp"
+	"fw/cp/constant/enter"
 	"fw/cp/node"
 	"fw/cp/object"
 	"reflect"
+	"strconv"
 	"ypk/assert"
 	"ypk/halt"
 )
@@ -91,25 +94,52 @@ func (m *Module) NodeByObject(obj object.Object) (ret []node.Node) {
 }
 
 func (m *Module) Init() {
+	typeName := func(id cp.ID) string {
+		for _, s := range m.Objects {
+			for _, o := range s {
+				switch t := o.(type) {
+				case object.TypeObject:
+					if o.Complex().Adr() == id {
+						return t.Name()
+					}
+				}
+			}
+		}
+		for _, i := range m.Imports {
+			for _, o := range i.Objects {
+				switch t := o.(type) {
+				case object.TypeObject:
+					if o.Complex().Adr() == id {
+						return t.Name()
+					}
+				}
+			}
+		}
+		return strconv.Itoa(int(id))
+	}
+
+	//fmt.Println("init", m.Name)
 	for k, s := range m.Types {
 		q := ""
-		if m.Enter.Adr() == k.Adr() {
-			q = m.Name
-		} else {
-			switch e := k.(type) {
-			case node.EnterNode:
-				fmt.Println(e.Adr(), e.Enter())
-			default:
-				halt.As(100, reflect.TypeOf(e))
+		switch e := k.(type) {
+		case node.EnterNode:
+			switch e.Enter() {
+			case enter.MODULE:
+				q = m.Name
+			case enter.PROCEDURE:
+				q = m.Name + "..." + e.Object().Name()
 			}
+		default:
+			halt.As(100, reflect.TypeOf(e))
 		}
 		for _, t := range s {
-			t.Qualident(q)
+			t.Qualident(q + "." + typeName(t.Adr()))
 		}
 	}
-	for i, s := range m.Imports {
+	for _, s := range m.Imports {
+		q := s.Name
 		for _, t := range s.Types {
-			fmt.Println(i, t)
+			t.Qualident(q + "." + typeName(t.Adr()))
 		}
 	}
 }

+ 10 - 2
cp/object/comp.go

@@ -12,6 +12,7 @@ import (
 func (a *basic) Equals(x ComplexType) bool {
 	switch b := x.(type) {
 	case *basic:
+		fmt.Println("basic comp", a.Qualident(), ",", b.Qualident())
 		return a == b
 	default:
 		halt.As(100, reflect.TypeOf(b))
@@ -22,6 +23,7 @@ func (a *basic) Equals(x ComplexType) bool {
 func (a *arr) Equals(x ComplexType) bool {
 	switch b := x.(type) {
 	case *arr:
+		fmt.Println("arr comp", ":", a.Qualident(), ",", b.Qualident())
 		return a == b
 	default:
 		halt.As(100, reflect.TypeOf(b))
@@ -32,6 +34,7 @@ func (a *arr) Equals(x ComplexType) bool {
 func (a *dyn) Equals(x ComplexType) bool {
 	switch b := x.(type) {
 	case *dyn:
+		fmt.Println("dyn comp", a.Qualident(), ",", b.Qualident())
 		return a == b
 	default:
 		halt.As(100, reflect.TypeOf(b))
@@ -42,7 +45,10 @@ func (a *dyn) Equals(x ComplexType) bool {
 func (a *rec) Equals(x ComplexType) bool {
 	switch b := x.(type) {
 	case *rec:
+		fmt.Println("rec comp", a.Name(), ":", a.Qualident(), ",", b.Name(), ":", b.Qualident())
 		return a == b
+	case *ptr:
+		return false
 	default:
 		halt.As(100, reflect.TypeOf(b))
 	}
@@ -52,8 +58,10 @@ func (a *rec) Equals(x ComplexType) bool {
 func (a *ptr) Equals(x ComplexType) bool {
 	switch b := x.(type) {
 	case *ptr:
-		fmt.Println(a.Name(), ":", a.Qualident(), ",", b.Name(), ":", b.Qualident())
-		return a == b
+		fmt.Println("pointer comp", a.Name(), ":", a.Qualident(), ",", b.Name(), ":", b.Qualident())
+		return a.Qualident() == b.Qualident()
+	case *rec:
+		return false
 	default:
 		halt.As(100, reflect.TypeOf(b))
 	}

+ 1 - 1
cp/object/type.go

@@ -200,7 +200,7 @@ func (r *rec) Base() string { return r.base }
 
 func NewRecordType(n string, id int, par ...string) (ret RecordType) {
 	if len(par) == 0 {
-		ret = &rec{}
+		ret = &rec{name: n}
 		ret.Adr(cp.Next(id))
 	} else {
 		ret = &rec{name: n, base: par[0]}

+ 3 - 2
rt2/rules/call.go

@@ -167,6 +167,8 @@ func callSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f)
 
 	call := func(proc node.Node, d context.Domain) {
+		_, ok := proc.(node.EnterNode)
+		assert.For(ok, 20, "try call", reflect.TypeOf(proc), proc.Adr(), proc.Object().Adr())
 		nf := rt2.New(proc)
 		rt2.Push(nf, f)
 		if d != nil {
@@ -205,9 +207,9 @@ func callSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 					assert.For(proc != nil, 40)
 					call(proc[0], nil)
 				case object.TYPE_PROC:
-					var proc []node.Node
 					//sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 					return This(expectExpr(f, n.Right(), func(...IN) (out OUT) {
+						var proc []node.Node
 						v := rt2.ValueOf(f)[n.Right().Adr()]
 						var dm context.Domain
 						var fn object.ProcedureObject
@@ -222,7 +224,6 @@ func callSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 									if po.Link() != nil && po.Link().Complex().Equals(c) {
 										fn = po
 									} else if po.Link() != nil {
-
 									}
 								}
 							}

+ 2 - 0
rt2/rules/field.go

@@ -1,6 +1,7 @@
 package rules
 
 import (
+	"fmt"
 	"reflect"
 )
 
@@ -26,6 +27,7 @@ func fieldSeq(in ...IN) (out OUT) {
 	case node.VariableNode, node.ParameterNode:
 		sc.Select(l.Object().Adr(), func(v scope.Value) {
 			rt2.ValueOf(f.Parent())[n.Adr()] = v.(scope.Record).Get(n.Object().Adr())
+			fmt.Println(n.Object().Adr())
 		})
 		out = End()
 	case node.FieldNode, node.DerefNode:

+ 3 - 0
rt2/scope/modern/val.go

@@ -1237,6 +1237,7 @@ func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
 				switch {
 				case x.Name() == a.Name():
 					//	fmt.Println("eq")
+					//fmt.Println("qid ", _x.Qualident(), _a.Qualident(), "names ", x.Name(), a.Name())
 					return true //опасно сравнивать имена конеш
 				case x.BaseType() != nil:
 					//	fmt.Println("go base")
@@ -1244,6 +1245,8 @@ func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
 				default:
 					return false
 				}
+			case object.PointerType:
+				return false
 			default:
 				halt.As(100, reflect.TypeOf(a))
 			}