ソースを参照

отладил проверку типов, теперь вылезли какие-то другие косяки

kpmy 10 年 前
コミット
a306e8659a
5 ファイル変更140 行追加90 行削除
  1. 3 1
      cp/object/type.go
  2. 6 1
      fw.go
  3. 3 1
      fw_test_all.bat
  4. 116 82
      rt2/rules2/wrap/data/val.go
  5. 12 5
      rt2/rules2/wrap/eval/expr.go

+ 3 - 1
cp/object/type.go

@@ -112,6 +112,7 @@ type BasicType interface {
 type PointerType interface {
 	ComplexType
 	Complex(...ComplexType) ComplexType
+	self() PointerType
 	Name() string
 }
 
@@ -244,7 +245,8 @@ func NewPointerType(n string, id int) PointerType {
 	return p
 }
 
-func (p *ptr) Name() string { return p.name }
+func (p *ptr) self() PointerType { return p }
+func (p *ptr) Name() string      { return p.name }
 
 func (p *ptr) Complex(x ...ComplexType) ComplexType {
 	if len(x) == 1 {

+ 6 - 1
fw.go

@@ -37,7 +37,12 @@ func main() {
 	flag.Parse()
 	utils.Debug(debug)
 	if name == "" {
-		name = "XevDemo23"
+		//name = "XevDemo23"
+		//name = "XevDemo11"
+		//name = "XevDemo12"
+		//name = "XevDemo13"
+		//name = "XevDemo19"
+		name = "Start3"
 	}
 	global := &stdDomain{god: true}
 	global.global = global

+ 3 - 1
fw_test_all.bat

@@ -22,7 +22,9 @@ start fw_test XevDemo19
 start fw_test XevDemo20
 start fw_test XevDemo21
 start fw_test XevDemo22
+start fw_test XevDemo23
 
 start fw_test TestA0
 start fw_test Start
-start fw_test Start2
+start fw_test Start2
+start fw_test Start3

+ 116 - 82
rt2/rules2/wrap/data/val.go

@@ -458,6 +458,8 @@ func (p *ptr) Set(v scope.Value) {
 	case PTR:
 		assert.For(x == NIL, 40)
 		p.val = nil
+	case *idx:
+		p.Set(x.Get())
 	default:
 		halt.As(100, reflect.TypeOf(x))
 	}
@@ -1351,117 +1353,149 @@ func (o *ops) Len(a object.Object, _a, _b scope.Value) (ret scope.Value) {
 }
 
 func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
-	var compare func(x, a object.ComplexType) bool
-	compare = func(_x, _a object.ComplexType) bool {
-		switch x := _x.(type) {
-		case object.RecordType:
-			switch a := _a.(type) {
+	/*	var compare func(x, a object.ComplexType) bool
+		compare = func(_x, _a object.ComplexType) bool {
+			switch x := _x.(type) {
 			case object.RecordType:
-				tc := o.Domain().Global().Discover(context.MOD).(rtm.List).NewTypeCalc()
-				tc.ConnectTo(a)
-				_, fc := tc.ForeignBase()
-				//fmt.Println(a, fc)
-				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.Complex() != nil:
-					//fmt.Println("go base")
-					//fmt.Println("qid ", x.Complex().Qualident(), a.Qualident())
-					return compare(x.Complex(), a)
-				case fc != nil:
-					//fmt.Println("go foreign")
-					//fmt.Println("qid ", x.Qualident(), fc.Qualident())
-					return compare(x, fc)
+				switch a := _a.(type) {
+				case object.RecordType:
+					tc := o.Domain().Global().Discover(context.MOD).(rtm.List).NewTypeCalc()
+					tc.ConnectTo(a)
+					_, fc := tc.ForeignBase()
+					//fmt.Println(a, fc)
+					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.Complex() != nil:
+						//fmt.Println("go base")
+						//fmt.Println("qid ", x.Complex().Qualident(), a.Qualident())
+						return compare(x.Complex(), a)
+					case fc != nil:
+						//fmt.Println("go foreign")
+						//fmt.Println("qid ", x.Qualident(), fc.Qualident())
+						return compare(x, fc)
+					default:
+						//fmt.Println("go here")
+						return false
+					}
+				case object.PointerType:
+					if a.Complex() != nil {
+						return compare(x, a.Complex())
+					} else {
+						//fmt.Println("to here")
+						return false
+					}
 				default:
-					//fmt.Println("go here")
-					return false
-				}
-			case object.PointerType:
-				if a.Complex() != nil {
-					return compare(x, a.Complex())
-				} else {
-					//fmt.Println("to here")
-					return false
+					halt.As(100, reflect.TypeOf(a))
 				}
-			default:
-				halt.As(100, reflect.TypeOf(a))
-			}
-		case object.PointerType:
-			switch a := _a.(type) {
 			case object.PointerType:
-				switch {
-				case x.Name() == a.Name():
-					//fmt.Println("eq")
-					return true //опасно сравнивать имена конеш
-				case x.Complex() != nil:
-					//fmt.Println("go base")
-					return compare(x.Complex(), a)
+				switch a := _a.(type) {
+				case object.PointerType:
+					switch {
+					case x.Name() == a.Name():
+						//fmt.Println("eq")
+						return true //опасно сравнивать имена конеш
+					case x.Complex() != nil:
+						//fmt.Println("go base")
+						return compare(x.Complex(), a)
+					default:
+						return false
+					}
 				default:
-					return false
+					halt.As(100, reflect.TypeOf(a))
 				}
 			default:
 				halt.As(100, reflect.TypeOf(a))
 			}
-		default:
-			halt.As(100, reflect.TypeOf(a))
-		}
-		panic(0)
-	}
-	comp2 := func(this, with object.ComplexType) {
-		fmt.Println("compare")
+			panic(0)
+		} */
+	comp2 := func(this, with object.ComplexType) (ret bool) {
+		//fmt.Println("compare")
+		tc := o.Domain().Global().Discover(context.MOD).(rtm.List).NewTypeCalc()
+		other := with
 		dump := func(this object.ComplexType) {
-			fmt.Println(this.Adr())
-			tc := o.Domain().Global().Discover(context.MOD).(rtm.List).NewTypeCalc()
-			for x := this; x != nil; {
+			//fmt.Println(this.Adr())
+			for x := this; x != nil && !ret; {
 				tc.ConnectTo(x)
-				fmt.Println(x.Qualident())
+				//fmt.Println(x.Qualident(), other.Qualident(), x.Qualident() == other.Qualident())
+				ret = x.Qualident() == other.Qualident()
 				x = x.(rtm.Inherited).Complex()
 				if x == nil {
 					_, x = tc.ForeignBase()
 				}
 			}
 		}
+		tc.ConnectTo(with)
+		if _, foreign := tc.ForeignBase(); foreign != nil {
+			other = foreign
+		}
 		dump(this)
-		dump(with)
-		fmt.Println()
+		//dump(with)
+		//fmt.Println()
+		return
+	}
+	comp3 := func(this, with object.ComplexType) bool {
+		switch w := with.(type) {
+		case object.PointerType:
+			return comp2(this, w.Complex())
+		default:
+			return comp2(this, with)
+		}
 	}
 	var do func(scope.Value, object.ComplexType) bool
 	do = func(a scope.Value, typ object.ComplexType) (ret bool) {
 		switch x := a.(type) {
 		case *rec:
-			comp2(x.comp, typ)
+			switch tt := typ.(type) {
+			case object.PointerType:
+				ret = comp2(x.comp, tt.Complex())
+			default:
+				ret = comp2(x.comp, typ)
+			}
 		case *ptr:
-			comp2(x.comp, typ)
+			switch xt := x.comp.(type) {
+			case object.PointerType:
+				if xt.Name() == "ANYPTR" {
+					val := x.Get()
+					t, c := o.TypeOf(val)
+					assert.For(t == object.COMPLEX, 40)
+					ret = comp3(c, typ)
+				}
+			default:
+				ret = comp3(x.comp, typ)
+			}
 		case *idx:
-			return do(x.Get(), typ)
+			ret = do(x.Get(), typ)
 		}
 		return
 	}
-	do(a, typ)
-	switch x := a.(type) {
-	case *rec:
-		z, a := x.comp.(object.RecordType)
-		y, b := typ.(object.RecordType)
-		//fmt.Println("compare rec", x.comp, typ, a, b, a && b && compare(z, y))
-		return BOOLEAN(a && b && compare(z, y))
-	case *ptr:
-		z, a := x.comp.(object.PointerType)
-		if val := x.Get(); z.Name() == "ANYPTR" && val != NIL {
-			t, c := o.TypeOf(val)
-			assert.For(t == object.COMPLEX, 40)
-			z, a = c.(object.RecordType)
+	return BOOLEAN(do(a, typ))
+	/*	switch x := a.(type) {
+		case *rec:
+			z, a := x.comp.(object.RecordType)
+			y, b := typ.(object.RecordType)
+			//fmt.Println("compare rec", x.comp, typ, a, b, a && b && compare(z, y))
+			return BOOLEAN(a && b && compare(z, y))
+		case *ptr:
+			var zz object.ComplexType
+			z, a := x.comp.(object.PointerType)
+			zz = z
+			if val := x.Get(); z.Name() == "ANYPTR" && val != NIL {
+				t, c := o.TypeOf(val)
+				assert.For(t == object.COMPLEX, 40)
+				zz, a = c.(object.RecordType)
+			}
+			y, b := typ.(object.PointerType)
+			//fmt.Println("compare ptr", z, typ, a, b, a && b && compare(z, y))
+			return BOOLEAN(a && b && compare(zz, y))
+		case *idx:
+			return o.Is(x.Get(), typ)
+		default:
+			halt.As(100, reflect.TypeOf(x))
 		}
-		y, b := typ.(object.PointerType)
-		//fmt.Println("compare ptr", z, typ, a, b, a && b && compare(z, y))
-		return BOOLEAN(a && b && compare(z, y))
-	case *idx:
-		return o.Is(x.Get(), typ)
-	default:
-		halt.As(100, reflect.TypeOf(x))
-	}
-	panic(0)
+		panic(0)*/
 }
 
 func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) scope.Value {

+ 12 - 5
rt2/rules2/wrap/eval/expr.go

@@ -360,17 +360,24 @@ func getMop(in IN) OUT {
 	return GetExpression(in, left, op.Left(), do)
 }
 
+func narrowValue(in scope.Value) scope.Value {
+	//fmt.Println(reflect.TypeOf(in))
+	switch v := in.(type) {
+	case scope.Pointer:
+		return narrowValue(v.Get())
+	case scope.Index:
+		return narrowValue(v.Get())
+	default:
+		return v
+	}
+}
 func getGuard(in IN) OUT {
 	const left = "guard:left"
 	g := in.IR.(node.GuardNode)
 	return GetDesignator(in, left, g.Left(), func(IN) OUT {
 		v := rt2.ValueOf(in.Frame)[KeyOf(in, left)]
 		assert.For(v != nil, 20)
-		switch vv := v.(type) {
-		case scope.Pointer:
-			v = vv.Get()
-		}
-		if scope.GoTypeFrom(scope.Ops.Is(v, g.Type())).(bool) {
+		if scope.GoTypeFrom(scope.Ops.Is(narrowValue(v), g.Type())).(bool) {
 			rt2.ValueOf(in.Parent)[g.Adr()] = v
 			rt2.RegOf(in.Parent)[in.Key] = g.Adr()
 			rt2.RegOf(in.Parent)[context.META] = rt2.RegOf(in.Frame)[context.META] //&Meta{Id: vv.Id(), }