kpmy 10 år sedan
förälder
incheckning
b701f19234
5 ändrade filer med 292 tillägg och 12 borttagningar
  1. 1 1
      fw.go
  2. 1 1
      rt2/rules/deref.go
  3. 9 9
      rt2/rules/op.go
  4. 9 1
      rt2/scope/data.go
  5. 272 0
      rt2/scope/modern/val.go

+ 1 - 1
fw.go

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

+ 1 - 1
rt2/rules/deref.go

@@ -22,7 +22,7 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 
 	} else {
 		switch l := n.Left().Object().(type) {
-		case object.ParameterObject:
+		case object.ParameterObject, object.VariableObject:
 			rt2.ValueOf(f.Parent())[n.Adr()] = sc.Select(l.Adr())
 		default:
 			halt.As(100, l.Adr(), reflect.TypeOf(l))

+ 9 - 9
rt2/rules/op.go

@@ -392,31 +392,31 @@ func dopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Min(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.DIV:
-			rt2.DataOf(f.Parent())[n] = div(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Div(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.MOD:
-			rt2.DataOf(f.Parent())[n] = mod(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Mod(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.TIMES:
-			rt2.DataOf(f.Parent())[n] = times(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Mult(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.SLASH:
-			rt2.DataOf(f.Parent())[n] = slash(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Divide(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.IN:
-			rt2.DataOf(f.Parent())[n] = in(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.In(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.ASH:
-			rt2.DataOf(f.Parent())[n] = ash(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Ash(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.AND:
-			rt2.DataOf(f.Parent())[n] = and(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.And(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.OR:
-			rt2.DataOf(f.Parent())[n] = or(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Or(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		case operation.GREAT_EQUAL:
-			rt2.DataOf(f.Parent())[n] = geq(rt2.DataOf(f)[n.Left()], rt2.DataOf(f)[n.Right()])
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Geq(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()
 		default:
 			panic(fmt.Sprintln("unknown operation", n.(node.OperationNode).Operation()))

+ 9 - 1
rt2/scope/data.go

@@ -8,7 +8,6 @@ import (
 type Operations interface {
 	Sum(Value, Value) Value
 	Sub(Value, Value) Value
-
 	Eq(Value, Value) Value
 	Neq(Value, Value) Value
 	Lss(Value, Value) Value
@@ -16,6 +15,15 @@ type Operations interface {
 	Gtr(Value, Value) Value
 	Max(Value, Value) Value
 	Min(Value, Value) Value
+	Div(Value, Value) Value
+	Mod(Value, Value) Value
+	Mult(Value, Value) Value
+	Divide(Value, Value) Value
+	In(Value, Value) Value
+	Ash(Value, Value) Value
+	And(Value, Value) Value
+	Or(Value, Value) Value
+	Geq(Value, Value) Value
 
 	Not(Value) Value
 	Abs(Value) Value

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

@@ -90,6 +90,8 @@ func (x *dynarr) Id() cp.ID {
 
 func (a *arr) Set(v scope.Value) {
 	switch x := v.(type) {
+	case *arr:
+		a.Set(STRING(x.String()))
 	case STRING:
 		v := make([]interface{}, int(a.length))
 		for i := 0; i < int(a.length) && i < len(x); i++ {
@@ -385,6 +387,8 @@ func vfrom(v scope.Value) scope.Value {
 			return n.val.(CHAR)
 		case object.SET:
 			return n.val.(SET)
+		case object.BOOLEAN:
+			return n.val.(BOOLEAN)
 		default:
 			halt.As(100, n.link.Type())
 		}
@@ -444,6 +448,32 @@ func (o *ops) Sum(a, b scope.Value) scope.Value {
 				default:
 					panic(fmt.Sprintln(reflect.TypeOf(y)))
 				}
+			case *arr:
+				switch y := b.(type) {
+				case *arr:
+					switch {
+					case x.link.Type() == y.link.Type() && x.link.Complex().(object.ArrayType).Base() == object.CHAR:
+						return STRING(x.String() + y.String())
+					default:
+						halt.As(100, x.link.Type(), y.link.Type())
+					}
+				case STRING:
+					switch {
+					case x.link.Complex().(object.ArrayType).Base() == object.CHAR:
+						return STRING(x.String() + string(y))
+					default:
+						halt.As(100, x.link.Type())
+					}
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			case STRING:
+				switch y := b.(type) {
+				case STRING:
+					return STRING(string(x) + string(y))
+				default:
+					halt.As(100, reflect.TypeOf(y))
+				}
 			default:
 				panic(fmt.Sprintln(reflect.TypeOf(x)))
 			}
@@ -486,6 +516,32 @@ func (o *ops) Sub(a, b scope.Value) scope.Value {
 	panic(0)
 }
 
+func (o *ops) In(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.In(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.In(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case SET:
+					fmt.Println("IN врет")
+					return BOOLEAN(false)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
 func (o *ops) Min(a, b scope.Value) scope.Value {
 	switch a.(type) {
 	case *data:
@@ -536,6 +592,188 @@ func (o *ops) Max(a, b scope.Value) scope.Value {
 	panic(0)
 }
 
+func (o *ops) And(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.And(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.And(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case BOOLEAN:
+				switch y := b.(type) {
+				case BOOLEAN:
+					return BOOLEAN(x && y)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Or(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Or(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Or(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case BOOLEAN:
+				switch y := b.(type) {
+				case BOOLEAN:
+					return BOOLEAN(x || y)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Ash(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Max(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Max(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					return INTEGER(x << uint(y))
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Div(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Div(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Div(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					return INTEGER(x / y)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Mod(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Mod(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Mod(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					return INTEGER(x % y)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Mult(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Mult(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Mult(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					return INTEGER(x * y)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Divide(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Divide(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Divide(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					return REAL(float64(x) / float64(y))
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			case REAL:
+				switch y := b.(type) {
+				case REAL:
+					return REAL(float64(x) / float64(y))
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
 func (o *ops) Len(a object.Object, _a, _b scope.Value) (ret scope.Value) {
 	//assert.For(a != nil, 20)
 	assert.For(_b != nil, 21)
@@ -622,6 +860,15 @@ func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
 		default:
 			halt.As(100, reflect.TypeOf(x))
 		}
+	case object.REAL:
+		switch x := a.(type) {
+		case *data:
+			return o.Conv(vfrom(x), typ)
+		case INTEGER:
+			return REAL(float64(x))
+		default:
+			halt.As(100, reflect.TypeOf(x))
+		}
 	default:
 		halt.As(100, typ)
 	}
@@ -812,6 +1059,31 @@ func (o *ops) Leq(a, b scope.Value) scope.Value {
 	panic(0)
 }
 
+func (o *ops) Geq(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Geq(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Geq(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 init() {
 	scope.ValueFrom = vfrom
 	scope.GoTypeFrom = gfrom