فهرست منبع

добрался до Test0

kpmy 10 سال پیش
والد
کامیت
db09d1a7b1
10فایلهای تغییر یافته به همراه106 افزوده شده و 45 حذف شده
  1. 8 0
      cp/node/class.go
  2. 1 0
      cp/node/node.go
  3. 10 2
      cp/object/type.go
  4. 1 1
      fw.go
  5. 25 6
      rt2/rules/deref.go
  6. 1 1
      rt2/rules/expect.go
  7. 10 32
      rt2/rules/op.go
  8. 1 1
      rt2/scope/data.go
  9. 33 1
      rt2/scope/modern/val.go
  10. 16 1
      xev/converter.go

+ 8 - 0
cp/node/class.go

@@ -209,6 +209,7 @@ type monadicNode struct {
 	nodeFields
 	operation operation.Operation
 	typ       object.Type
+	comp      object.ComplexType
 }
 
 func (v *monadicNode) self() MonadicNode { return v }
@@ -220,6 +221,13 @@ func (v *monadicNode) Operation() operation.Operation { return v.operation }
 func (v *monadicNode) SetType(t object.Type) { v.typ = t }
 func (v *monadicNode) Type() object.Type     { return v.typ }
 
+func (v *monadicNode) Complex(x ...object.ComplexType) object.ComplexType {
+	if len(x) > 0 {
+		v.comp = x[0]
+	}
+	return v.comp
+}
+
 type conditionalNode struct {
 	nodeFields
 }

+ 1 - 0
cp/node/node.go

@@ -90,6 +90,7 @@ type MonadicNode interface {
 	SetType(typ object.Type)
 	Type() object.Type
 	self() MonadicNode
+	Complex(...object.ComplexType) object.ComplexType
 }
 
 type ConditionalNode interface {

+ 10 - 2
cp/object/type.go

@@ -10,7 +10,8 @@ import (
 type Type int
 
 const (
-	NOTYPE Type = iota
+	WRONG Type = iota
+	NOTYPE
 	INTEGER
 	SHORTINT
 	LONGINT
@@ -90,6 +91,7 @@ func (c *comp) Adr(a ...int) cp.ID {
 type BasicType interface {
 	ComplexType
 	Type() Type
+	Base(...Type) Type
 }
 
 type PointerType interface {
@@ -125,10 +127,16 @@ func NewBasicType(t Type, id int) BasicType {
 
 type basic struct {
 	comp
-	typ Type
+	typ, base Type
 }
 
 func (b *basic) Type() Type { return b.typ }
+func (b *basic) Base(x ...Type) Type {
+	if len(x) > 0 {
+		b.base = x[0]
+	}
+	return b.base
+}
 
 func NewDynArrayType(b Type, id int) (ret DynArrayType) {
 	ret = &dyn{base: b}

+ 1 - 1
fw.go

@@ -27,7 +27,7 @@ func close() {
 func main() {
 	flag.Parse()
 	if name == "" {
-		name = "XevDemo22"
+		name = "XevTest0"
 	}
 	global := &stdDomain{god: true}
 	global.global = global

+ 25 - 6
rt2/rules/deref.go

@@ -26,15 +26,34 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				assert.For(ok, 60, reflect.TypeOf(v))
 				rt2.ValueOf(f.Parent())[n.Adr()] = ptr.Get()
 			})
+			return frame.End()
 		default:
 			halt.As(100, l.Adr(), reflect.TypeOf(l))
 		}
 	} else {
-		switch l := n.Left().Object().(type) {
-		case object.ParameterObject, object.VariableObject:
-			rt2.ValueOf(f.Parent())[n.Adr()] = sc.Select(l.Adr())
-		default:
-			halt.As(100, l.Adr(), reflect.TypeOf(l))
+		if n.Left().Object() != nil {
+			switch l := n.Left().Object().(type) {
+			case object.ParameterObject, object.VariableObject:
+				rt2.ValueOf(f.Parent())[n.Adr()] = sc.Select(l.Adr())
+				return frame.End()
+			default:
+				halt.As(100, l.Adr(), reflect.TypeOf(l))
+			}
+		} else {
+			switch left := n.Left().(type) {
+			case node.DerefNode:
+				rt2.Push(rt2.New(left), f)
+				rt2.Assert(f, func(f frame.Frame) (bool, int) {
+					return rt2.ValueOf(f)[left.Adr()] != nil, 60
+				})
+				seq = Propose(func(...IN) OUT {
+					rt2.ValueOf(f.Parent())[n.Adr()] = rt2.ValueOf(f)[left.Adr()]
+					return End()
+				})
+				ret = LATER.wait()
+			default:
+				halt.As(100, reflect.TypeOf(left))
+			}
 		}
 	}
 	/* if ok {
@@ -52,5 +71,5 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			}
 		}
 	} */
-	return frame.End()
+	return seq, ret
 }

+ 1 - 1
rt2/rules/expect.go

@@ -21,7 +21,7 @@ func expectExpr(parent frame.Frame, expr node.Node, next Do) OUT {
 	case node.VariableNode, node.ParameterNode:
 		rt2.ValueOf(parent)[expr.Adr()] = sm.Select(expr.Object().Adr())
 		return OUT{do: next, next: NOW}
-	case node.OperationNode, node.CallNode:
+	case node.OperationNode, node.CallNode, node.DerefNode:
 		rt2.Push(rt2.New(expr), parent)
 		wait := func(...IN) OUT {
 			if rt2.RegOf(parent)[expr] == nil && rt2.ValueOf(parent)[expr.Adr()] == nil {

+ 10 - 32
rt2/rules/op.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"fw/cp/constant/operation"
 	"fw/cp/node"
+	"fw/cp/object"
 	"fw/rt2"
 	"fw/rt2/context"
 	"fw/rt2/frame"
@@ -63,37 +64,11 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	switch n.Operation() {
 	case operation.ALIEN_CONV:
 		conv := func(x scope.Value) {
-			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Conv(x, n.Type())
-			/*switch n.Type() {
-			case object.INTEGER:
-				switch v := x.(type) {
-				case int8:
-					rt2.DataOf(f.Parent())[n] = int32(x.(int8))
-				case *big.Int:
-					rt2.DataOf(f.Parent())[n] = int32(v.Int64())
-				case int32:
-					rt2.DataOf(f.Parent())[n] = v
-				case
-				default:
-					panic(fmt.Sprintln("ooops", reflect.TypeOf(x)))
-				}
-			case object.SET:
-				switch v := x.(type) {
-				case int32:
-					rt2.DataOf(f.Parent())[n] = big.NewInt(int64(v))
-				default:
-					panic(fmt.Sprintln("ooops", reflect.TypeOf(x)))
-				}
-			case object.REAL:
-				switch v := x.(type) {
-				case int32:
-					rt2.DataOf(f.Parent())[n] = float64(v)
-				default:
-					panic(fmt.Sprintln("ooops", reflect.TypeOf(x)))
-				}
-			default:
-				panic(fmt.Sprintln("wrong type", n.Type()))
-			} */
+			if n.Type() != object.NOTYPE {
+				rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Conv(x, n.Type())
+			} else {
+				rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Conv(x, n.Type(), n.(node.MonadicNode).Complex())
+			}
 		}
 		switch n.Left().(type) {
 		case node.VariableNode, node.ParameterNode:
@@ -101,7 +76,7 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			assert.For(x != nil, 40)
 			conv(scope.ValueFrom(x))
 			return frame.End()
-		case node.OperationNode:
+		case node.OperationNode, node.DerefNode:
 			return This(expectExpr(f, n.Left(), func(...IN) OUT {
 				conv(rt2.ValueOf(f)[n.Left().Adr()])
 				return End()
@@ -118,6 +93,7 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				//				sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 				//				rt2.DataOf(f)[n.Left()] = sc.Select(scope.Designator(n.Left()))
+				panic(0)
 				return op, frame.NOW
 			}
 			ret = frame.NOW
@@ -133,6 +109,7 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				//				sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 				//				rt2.DataOf(f)[n.Left()] = sc.Select(scope.Designator(n.Left()))
+				panic(0)
 				return op, frame.NOW
 			}
 			ret = frame.NOW
@@ -252,6 +229,7 @@ func dopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				//				sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 				//				rt2.DataOf(f)[n.Right()] = sc.Select(scope.Designator(n.Right()))
+				panic(0)
 				return op, frame.NOW
 			}
 			ret = frame.NOW

+ 1 - 1
rt2/scope/data.go

@@ -32,7 +32,7 @@ type Operations interface {
 	Bits(Value) Value
 
 	Is(Value, object.ComplexType) Value
-	Conv(Value, object.Type) Value
+	Conv(Value, object.Type, ...object.ComplexType) Value
 	Len(object.Object, Value, Value) Value
 }
 

+ 33 - 1
rt2/scope/modern/val.go

@@ -107,6 +107,8 @@ func (a *dynarr) Set(v scope.Value) {
 	switch x := v.(type) {
 	case *arr:
 		a.val = x.val
+	case *dynarr:
+		a.val = x.val
 	case STRING:
 		v := make([]interface{}, len(x))
 		for i := 0; i < len(x); i++ {
@@ -522,6 +524,18 @@ func (o *ops) Sum(a, b scope.Value) scope.Value {
 				default:
 					panic(fmt.Sprintln(reflect.TypeOf(y)))
 				}
+			case *dynarr:
+				switch y := b.(type) {
+				case STRING:
+					switch {
+					case x.link.Complex().(object.DynArrayType).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:
@@ -932,7 +946,7 @@ func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
 	panic(0)
 }
 
-func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
+func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) scope.Value {
 	switch typ {
 	case object.INTEGER:
 		switch x := a.(type) {
@@ -965,6 +979,24 @@ func (o *ops) Conv(a scope.Value, typ object.Type) scope.Value {
 		default:
 			halt.As(100, reflect.TypeOf(x))
 		}
+	case object.NOTYPE:
+		assert.For(len(comp) > 0, 20)
+		switch t := comp[0].(type) {
+		case object.BasicType:
+			switch t.Type() {
+			case object.SHORTSTRING:
+				switch x := a.(type) {
+				case *dynarr:
+					return SHORTSTRING(x.String())
+				default:
+					halt.As(100, reflect.TypeOf(x))
+				}
+			default:
+				halt.As(100, t.Type())
+			}
+		default:
+			halt.As(100, reflect.TypeOf(t))
+		}
 	default:
 		halt.As(100, typ)
 	}

+ 16 - 1
xev/converter.go

@@ -201,9 +201,17 @@ func (r *Result) doType(n *Node) (ret object.ComplexType) {
 					t.Link().SetRef(t)
 				}
 				ret = t
+			case "SHORTSTRING":
+				t := object.NewBasicType(object.SHORTSTRING, n.Id)
+				t.Base(object.SHORTCHAR)
+				ret = t
+			case "STRING":
+				t := object.NewBasicType(object.STRING, n.Id)
+				t.Base(object.CHAR)
+				ret = t
 			case "CHAR", "SHORTCHAR", "INTEGER", "LONGINT", "BYTE",
 				"SHORTINT", "BOOLEAN", "REAL", "SHORTREAL", "SET", "UNDEF",
-				"NOTYP", "SHORTSTRING", "STRING":
+				"NOTYP":
 			case "POINTER":
 				t := object.NewPointerType(n.Data.Typ.Name)
 				base := r.findLink(n, "base")
@@ -408,6 +416,13 @@ func (r *Result) buildNode(n *Node) (ret node.Node) {
 			case "CONV":
 				ret.(node.OperationNode).SetOperation(operation.ALIEN_CONV)
 				initType(n.Data.Nod.Typ, ret.(node.MonadicNode))
+				typ := r.findLink(n, "type")
+				if typ != nil {
+					ret.(node.MonadicNode).Complex(r.doType(typ))
+					if ret.(node.MonadicNode).Complex() == nil {
+						panic("error in node")
+					}
+				}
 			}
 		case "conditional":
 			ret = node.New(constant.CONDITIONAL, n.Id)