Sfoglia il codice sorgente

добавлены операции сравнения, заработали демо 9, 10

kpmy 10 anni fa
parent
commit
04e0e26f22
4 ha cambiato i file con 42 aggiunte e 3 eliminazioni
  1. 1 1
      fw.go
  2. 2 2
      rt2/rules/op.go
  3. 2 0
      rt2/scope/data.go
  4. 37 0
      rt2/scope/modern/val.go

+ 1 - 1
fw.go

@@ -28,7 +28,7 @@ func close() {
 func main() {
 	flag.Parse()
 	if name == "" {
-		name = "XevDemo8"
+		name = "XevDemo10"
 	}
 	global := &stdDomain{god: true}
 	modList := rtmod.New()

+ 2 - 2
rt2/rules/op.go

@@ -248,7 +248,7 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		n := rt2.NodeOf(f)
 		switch n.(node.OperationNode).Operation() {
 		case operation.NOT:
-			rt2.DataOf(f.Parent())[n] = not(rt2.DataOf(f)[n.Left()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Not(rt2.ValueOf(f)[n.Left().Adr()])
 			return frame.End()
 		case operation.IS:
 			/*	x := sc.Select(scope.Designator(n.Left())).(object.Object)
@@ -397,7 +397,7 @@ func dopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Len(n.Left().Object(), rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.NOT_EQUAL:
-			rt2.DataOf(f.Parent())[n] = neq(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Neq(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.GREATER:
 			rt2.DataOf(f.Parent())[n] = gtr(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])

+ 2 - 0
rt2/scope/data.go

@@ -10,9 +10,11 @@ type Operations interface {
 	Sub(Value, Value) Value
 
 	Eq(Value, Value) Value
+	Neq(Value, Value) Value
 	Lss(Value, Value) Value
 	Leq(Value, Value) Value
 
+	Not(Value) Value
 	Conv(Value, object.Type) Value
 	Len(object.Object, Value, Value) Value
 }

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

@@ -516,6 +516,18 @@ func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
 	panic(100)
 }
 
+func (o *ops) Not(a scope.Value) scope.Value {
+	switch x := a.(type) {
+	case *data:
+		return o.Not(vfrom(x))
+	case BOOLEAN:
+		return BOOLEAN(!x)
+	default:
+		halt.As(100, reflect.TypeOf(x))
+	}
+	panic(100)
+}
+
 func (o *ops) Eq(a, b scope.Value) scope.Value {
 	switch a.(type) {
 	case *data:
@@ -541,6 +553,31 @@ func (o *ops) Eq(a, b scope.Value) scope.Value {
 	panic(0)
 }
 
+func (o *ops) Neq(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Neq(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Neq(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					return BOOLEAN(x != y)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
 func (o *ops) Lss(a, b scope.Value) scope.Value {
 	switch a.(type) {
 	case *data: