瀏覽代碼

заработал with и демо11

kpmy 10 年之前
父節點
當前提交
f7ad5ad290
共有 7 個文件被更改,包括 53 次插入6 次删除
  1. 3 0
      rt2/nodeframe/frame.go
  2. 6 0
      rt2/rules/if.go
  3. 1 2
      rt2/rules/op.go
  4. 6 0
      rt2/rules/with.go
  5. 2 0
      rt2/scope/data.go
  6. 26 0
      rt2/scope/modern/val.go
  7. 9 4
      rt2/utils.go

+ 3 - 0
rt2/nodeframe/frame.go

@@ -117,7 +117,10 @@ func (f *nodeFrame) OnPop() {
 			ok, code := ff.assertion(ff)
 			ok, code := ff.assertion(ff)
 			if !ok {
 			if !ok {
 				panic(fmt.Sprintln("assert", code, "for", reflect.TypeOf(ff.ir)))
 				panic(fmt.Sprintln("assert", code, "for", reflect.TypeOf(ff.ir)))
+			} else {
+				fmt.Println("assert passed", code, "for", reflect.TypeOf(ff.ir))
 			}
 			}
+			ff.assertion = nil
 		}
 		}
 	}
 	}
 }
 }

+ 6 - 0
rt2/rules/if.go

@@ -30,6 +30,9 @@ func ifSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f)
 	n := rt2.NodeOf(f)
 	rt2.RegOf(f)[0] = n.Left() //if
 	rt2.RegOf(f)[0] = n.Left() //if
 	rt2.Push(rt2.New(n.Left()), f)
 	rt2.Push(rt2.New(n.Left()), f)
+	rt2.Assert(f, func(f frame.Frame) (bool, int) {
+		return rt2.ValueOf(f)[n.Left().Adr()] != nil, 60
+	})
 	seq = func(f frame.Frame) (frame.Sequence, frame.WAIT) {
 	seq = func(f frame.Frame) (frame.Sequence, frame.WAIT) {
 		last := rt2.RegOf(f)[0].(node.Node)
 		last := rt2.RegOf(f)[0].(node.Node)
 		done := scope.GoTypeFrom(rt2.ValueOf(f)[last.Adr()]).(bool)
 		done := scope.GoTypeFrom(rt2.ValueOf(f)[last.Adr()]).(bool)
@@ -42,6 +45,9 @@ func ifSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		} else if last.Link() != nil { //elsif
 		} else if last.Link() != nil { //elsif
 			rt2.RegOf(f)[0] = last.Link()
 			rt2.RegOf(f)[0] = last.Link()
 			rt2.Push(rt2.New(last.Link()), f)
 			rt2.Push(rt2.New(last.Link()), f)
+			rt2.Assert(f, func(f frame.Frame) (bool, int) {
+				return rt2.ValueOf(f)[last.Link().Adr()] != nil, 61
+			})
 			return seq, frame.LATER
 			return seq, frame.LATER
 		} else if n.Right() != nil { //else
 		} else if n.Right() != nil { //else
 			rt2.Push(rt2.New(n.Right()), f)
 			rt2.Push(rt2.New(n.Right()), f)

+ 1 - 2
rt2/rules/op.go

@@ -251,8 +251,7 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Not(rt2.ValueOf(f)[n.Left().Adr()])
 			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Not(rt2.ValueOf(f)[n.Left().Adr()])
 			return frame.End()
 			return frame.End()
 		case operation.IS:
 		case operation.IS:
-			/*	x := sc.Select(scope.Designator(n.Left())).(object.Object)
-				rt2.DataOf(f.Parent())[n] = is(x, n.Object())*/
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Is(sc.Select(n.Left().Object().Adr()), n.Object())
 			return frame.End()
 			return frame.End()
 		case operation.ABS:
 		case operation.ABS:
 			rt2.DataOf(f.Parent())[n] = abs(rt2.DataOf(f)[n.Left()])
 			rt2.DataOf(f.Parent())[n] = abs(rt2.DataOf(f)[n.Left()])

+ 6 - 0
rt2/rules/with.go

@@ -11,6 +11,9 @@ func withSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f)
 	n := rt2.NodeOf(f)
 	rt2.RegOf(f)[0] = n.Left() //if
 	rt2.RegOf(f)[0] = n.Left() //if
 	rt2.Push(rt2.New(n.Left()), f)
 	rt2.Push(rt2.New(n.Left()), f)
+	rt2.Assert(f, func(f frame.Frame) (bool, int) {
+		return rt2.ValueOf(f)[n.Left().Adr()] != nil, 60
+	})
 	seq = func(f frame.Frame) (frame.Sequence, frame.WAIT) {
 	seq = func(f frame.Frame) (frame.Sequence, frame.WAIT) {
 		last := rt2.RegOf(f)[0].(node.Node)
 		last := rt2.RegOf(f)[0].(node.Node)
 		done := scope.GoTypeFrom(rt2.ValueOf(f)[last.Adr()]).(bool)
 		done := scope.GoTypeFrom(rt2.ValueOf(f)[last.Adr()]).(bool)
@@ -23,6 +26,9 @@ func withSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		} else if last.Link() != nil { //elsif
 		} else if last.Link() != nil { //elsif
 			rt2.RegOf(f)[0] = last.Link()
 			rt2.RegOf(f)[0] = last.Link()
 			rt2.Push(rt2.New(last.Link()), f)
 			rt2.Push(rt2.New(last.Link()), f)
+			rt2.Assert(f, func(f frame.Frame) (bool, int) {
+				return rt2.ValueOf(f)[last.Link().Adr()] != nil, 61
+			})
 			return seq, frame.LATER
 			return seq, frame.LATER
 		} else if n.Right() != nil { //else
 		} else if n.Right() != nil { //else
 			rt2.Push(rt2.New(n.Right()), f)
 			rt2.Push(rt2.New(n.Right()), f)

+ 2 - 0
rt2/scope/data.go

@@ -15,6 +15,8 @@ type Operations interface {
 	Leq(Value, Value) Value
 	Leq(Value, Value) Value
 
 
 	Not(Value) Value
 	Not(Value) Value
+
+	Is(Value, object.ComplexType) Value
 	Conv(Value, object.Type) Value
 	Conv(Value, object.Type) Value
 	Len(object.Object, Value, Value) Value
 	Len(object.Object, Value, Value) Value
 }
 }

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

@@ -499,6 +499,32 @@ func (o *ops) Len(a object.Object, _a, _b scope.Value) (ret scope.Value) {
 	return ret
 	return ret
 }
 }
 
 
+func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
+	var compare func(x, a object.RecordType) bool
+	compare = func(x, a object.RecordType) bool {
+		switch {
+		case x.Name() == a.Name():
+			//	fmt.Println("eq")
+			return true //опасно сравнивать имена конеш
+		case x.BaseType() != nil:
+			//	fmt.Println("go base")
+			return compare(x.BaseType(), a)
+		default:
+			return false
+		}
+	}
+	switch x := a.(type) {
+	case *rec:
+		z, a := x.link.Complex().(object.RecordType)
+		y, b := typ.(object.RecordType)
+		fmt.Println("compare", x.link.Complex(), typ, a, b, a && b && compare(z, y))
+		return BOOLEAN(a && b && compare(z, y))
+	default:
+		halt.As(100, reflect.TypeOf(x))
+	}
+	panic(0)
+}
+
 func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
 func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
 	switch typ {
 	switch typ {
 	case object.INTEGER:
 	case object.INTEGER:

+ 9 - 4
rt2/utils.go

@@ -1,22 +1,27 @@
 package rt2
 package rt2
 
 
 import (
 import (
+	"fmt"
 	"fw/cp"
 	"fw/cp"
 	"fw/cp/node"
 	"fw/cp/node"
 	"fw/rt2/context"
 	"fw/rt2/context"
 	"fw/rt2/frame"
 	"fw/rt2/frame"
 	"fw/rt2/nodeframe"
 	"fw/rt2/nodeframe"
 	"fw/rt2/scope"
 	"fw/rt2/scope"
+	"reflect"
 )
 )
 
 
 var utils nodeframe.NodeFrameUtils
 var utils nodeframe.NodeFrameUtils
 
 
 func DataOf(f frame.Frame) map[interface{}]interface{} { panic(100) }
 func DataOf(f frame.Frame) map[interface{}]interface{} { panic(100) }
 func RegOf(f frame.Frame) map[interface{}]interface{}  { return utils.DataOf(f) }
 func RegOf(f frame.Frame) map[interface{}]interface{}  { return utils.DataOf(f) }
-func ValueOf(f frame.Frame) map[cp.ID]scope.Value      { return utils.ValueOf(f) }
-func NodeOf(f frame.Frame) node.Node                   { return utils.NodeOf(f) }
-func Push(f, p frame.Frame)                            { utils.Push(f, p) }
-func New(n node.Node) frame.Frame                      { return utils.New(n) }
+func ValueOf(f frame.Frame) map[cp.ID]scope.Value {
+	fmt.Println("getval ", reflect.TypeOf(NodeOf(f)))
+	return utils.ValueOf(f)
+}
+func NodeOf(f frame.Frame) node.Node { return utils.NodeOf(f) }
+func Push(f, p frame.Frame)          { utils.Push(f, p) }
+func New(n node.Node) frame.Frame    { return utils.New(n) }
 func ScopeOf(f frame.Frame) scope.Manager {
 func ScopeOf(f frame.Frame) scope.Manager {
 	return f.Domain().Discover(context.SCOPE).(scope.Manager)
 	return f.Domain().Discover(context.SCOPE).(scope.Manager)
 }
 }