瀏覽代碼

попытка запуска динамических структур
провалилась из-за запутанности структуры пакета rules, кажется, он нуждается в рефакторинге

kpmy 10 年之前
父節點
當前提交
cbe0b70e1e
共有 41 個文件被更改,包括 218 次插入71 次删除
  1. 二進制
      code/Cons.oz
  2. 二進制
      code/Console.oz
  3. 二進制
      code/Core.oz
  4. 二進制
      code/JSonFormatter.oz
  5. 二進制
      code/JSonGenerator.oz
  6. 二進制
      code/JSonObxNoModel.oz
  7. 二進制
      code/JSonParser.oz
  8. 二進制
      code/ListsIterable.oz
  9. 二進制
      code/ListsLinear.oz
  10. 二進制
      code/ListsMap.oz
  11. 二進制
      code/ListsObxIterable.oz
  12. 二進制
      code/ListsObxLinear.oz
  13. 二進制
      code/ListsObxMap.oz
  14. 二進制
      code/Mathe.oz
  15. 二進制
      code/Out.oz
  16. 二進制
      code/Start.oz
  17. 二進制
      code/Start3.oz
  18. 二進制
      code/Str.oz
  19. 二進制
      code/TestA0.oz
  20. 二進制
      code/TestA1.oz
  21. 二進制
      code/TestA2.oz
  22. 二進制
      code/TestMath.oz
  23. 二進制
      code/TestStrDyn.oz
  24. 二進制
      code/TestStrings.oz
  25. 17 4
      cp/object/type.go
  26. 3 1
      fw.go
  27. 11 0
      fw_test_dump.bat
  28. 3 0
      rt2/context/ctx.go
  29. 8 8
      rt2/module/ml.go
  30. 30 10
      rt2/rules/assign.go
  31. 1 1
      rt2/rules/call.go
  32. 22 3
      rt2/rules/deref.go
  33. 10 4
      rt2/rules/expect.go
  34. 3 1
      rt2/rules/field.go
  35. 3 0
      rt2/rules/op.go
  36. 9 8
      rt2/rules/return.go
  37. 1 1
      rt2/scope/area.go
  38. 1 0
      rt2/scope/data.go
  39. 9 18
      rt2/scope/modern/hp.go
  40. 76 8
      rt2/scope/modern/val.go
  41. 11 4
      xev/converter.go

二進制
code/Cons.oz


二進制
code/Console.oz


二進制
code/Core.oz


二進制
code/JSonFormatter.oz


二進制
code/JSonGenerator.oz


二進制
code/JSonObxNoModel.oz


二進制
code/JSonParser.oz


二進制
code/ListsIterable.oz


二進制
code/ListsLinear.oz


二進制
code/ListsMap.oz


二進制
code/ListsObxIterable.oz


二進制
code/ListsObxLinear.oz


二進制
code/ListsObxMap.oz


二進制
code/Mathe.oz


二進制
code/Out.oz


二進制
code/Start.oz


二進制
code/Start3.oz


二進制
code/Str.oz


二進制
code/TestA0.oz


二進制
code/TestA1.oz


二進制
code/TestA2.oz


二進制
code/TestMath.oz


二進制
code/TestStrDyn.oz


二進制
code/TestStrings.oz


+ 17 - 4
cp/object/type.go

@@ -109,7 +109,7 @@ type BasicType interface {
 
 type PointerType interface {
 	ComplexType
-	Base(...ComplexType) ComplexType
+	Complex(...ComplexType) ComplexType
 	Name() string
 }
 
@@ -123,13 +123,14 @@ type ArrayType interface {
 type DynArrayType interface {
 	ComplexType
 	Base() Type
+	Complex(...ComplexType) ComplexType
 }
 
 type RecordType interface {
 	ComplexType
 	BaseName() string
 	BaseRec() RecordType
-	Base(t ...ComplexType) ComplexType
+	Complex(t ...ComplexType) ComplexType
 	Name() string
 }
 
@@ -161,6 +162,16 @@ func NewDynArrayType(b Type, id int) (ret DynArrayType) {
 type dyn struct {
 	comp
 	base Type
+	cmp  ComplexType
+}
+
+func (a *dyn) Complex(t ...ComplexType) ComplexType {
+	if len(t) == 1 {
+		a.cmp = t[0]
+	} else if len(t) > 1 {
+		panic("too many args")
+	}
+	return a.cmp
 }
 
 func (d *dyn) Base() Type { return d.base }
@@ -210,7 +221,8 @@ func NewRecordType(n string, id int, par ...string) (ret RecordType) {
 }
 
 func (r *rec) BaseRec() RecordType { return r.basetyp }
-func (r *rec) Base(t ...ComplexType) ComplexType {
+
+func (r *rec) Complex(t ...ComplexType) ComplexType {
 	if len(t) == 1 {
 		r.basetyp = t[0].(RecordType)
 	}
@@ -231,7 +243,8 @@ func NewPointerType(n string, id int) PointerType {
 }
 
 func (p *ptr) Name() string { return p.name }
-func (p *ptr) Base(x ...ComplexType) ComplexType {
+
+func (p *ptr) Complex(x ...ComplexType) ComplexType {
 	if len(x) == 1 {
 		p.basetyp = x[0]
 		//fmt.Println("pbasetyp", p.basetyp, reflect.TypeOf(p.basetyp))

+ 3 - 1
fw.go

@@ -17,10 +17,12 @@ import (
 )
 
 var name string
+var debug bool = false
 var heap scope.Manager
 
 func init() {
 	flag.StringVar(&name, "i", "", "-i name.ext")
+	flag.BoolVar(&debug, "d", false, "-d true/false")
 }
 
 func close() {
@@ -35,8 +37,8 @@ func main() {
 	flag.Parse()
 	if name == "" {
 		name = "Start3"
-		utils.Debug(false)
 	}
+	utils.Debug(debug)
 	global := &stdDomain{god: true}
 	global.global = global
 	modList := rtm.New()

+ 11 - 0
fw_test_dump.bat

@@ -0,0 +1,11 @@
+@echo off 
+fw -i=%1 -d=true > .1
+IF ERRORLEVEL 1 GOTO err
+
+GOTO ok
+:err
+echo FAILED %1
+pause
+
+:ok
+exit

+ 3 - 0
rt2/context/ctx.go

@@ -8,6 +8,9 @@ const (
 	HEAP     = "fw/rt2/scope,heap"
 	MT       = "fw/rt2/table,flow"
 	DIGEST   = "fw/cp"
+
+	RETURN = "RETURN"
+	META   = "META"
 )
 
 type Factory interface {

+ 8 - 8
rt2/module/ml.go

@@ -211,7 +211,7 @@ type tc struct {
 }
 
 type inherited interface {
-	Base(...object.ComplexType) object.ComplexType
+	Complex(...object.ComplexType) object.ComplexType
 }
 
 func (c *tc) ConnectTo(x interface{}) {
@@ -255,7 +255,7 @@ func (c *tc) MethodList() (ret map[int][]Method) {
 							break
 						}
 						if _, ok := pt.(inherited); ok {
-							pt = pt.(inherited).Base()
+							pt = pt.(inherited).Complex()
 						} else {
 							pt = nil
 						}
@@ -285,7 +285,7 @@ func (c *tc) MethodList() (ret map[int][]Method) {
 		tmp = make(map[string]object.Object, 0)
 		for t := x; t != nil; {
 			list(m, t)
-			z := t.(inherited).Base()
+			z := t.(inherited).Complex()
 			if z != nil {
 				t = z
 			} else {
@@ -348,7 +348,7 @@ func (c *tc) String() (ret string) {
 					pt := po.Link().Complex()
 					var pb object.ComplexType
 					if _, ok := pt.(inherited); ok {
-						pb = pt.(inherited).Base()
+						pb = pt.(inherited).Complex()
 					}
 					if t.Equals(pt) || t.Equals(pb) {
 						ret = fmt.Sprintln(ret, po.Name(), local)
@@ -358,15 +358,15 @@ func (c *tc) String() (ret string) {
 		}
 		switch z := t.(type) {
 		case object.PointerType:
-			if z.Base() != nil {
-				t = z.Base()
+			if z.Complex() != nil {
+				t = z.Complex()
 			} else {
 				foreign(t)
 				t = nil
 			}
 		case object.RecordType:
-			if z.Base() != nil {
-				t = z.Base()
+			if z.Complex() != nil {
+				t = z.Complex()
 			} else {
 				foreign(t)
 				t = nil

+ 30 - 10
rt2/rules/assign.go

@@ -7,11 +7,13 @@ import (
 	"fw/cp/constant/operation"
 	"fw/cp/constant/statement"
 	"fw/cp/node"
+	"fw/cp/object"
 	"fw/rt2"
 	"fw/rt2/context"
 	"fw/rt2/frame"
 	"fw/rt2/scope"
 	"reflect"
+	"ypk/assert"
 	"ypk/halt"
 )
 
@@ -77,13 +79,13 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		case node.OperationNode, node.CallNode, node.DerefNode, node.FieldNode:
 			rt2.Push(rt2.New(a.Right()), f)
 			rt2.Assert(f, func(f frame.Frame) (bool, int) {
-				return rt2.ValueOf(f)[a.Right().Adr()] != nil || rt2.RegOf(f)["RETURN"] != nil, 61
+				return rt2.ValueOf(f)[a.Right().Adr()] != nil || rt2.RegOf(f)[context.RETURN] != nil, 61
 			})
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				//sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 				val := rt2.ValueOf(f)[a.Right().Adr()]
 				if val == nil {
-					val = rt2.RegOf(f)["RETURN"].(scope.Value)
+					val = rt2.RegOf(f)[context.RETURN].(scope.Value)
 				}
 				vleft.Set(val)
 				return frame.End()
@@ -147,7 +149,14 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			}
 			ret = frame.LATER
 		case node.IndexNode:
-			rt2.Push(rt2.New(a.Left()), f)
+			return This(expectExpr(f, l, func(in ...IN) (out OUT) {
+				v := rt2.ValueOf(f)[l.Adr()]
+				left = v
+				out.do = Expose(right)
+				out.next = NOW
+				return
+			}))
+			/*rt2.Push(rt2.New(a.Left()), f)
 			rt2.Assert(f, func(f frame.Frame) (bool, int) {
 				return rt2.ValueOf(f)[l.Adr()] != nil, 64
 			})
@@ -161,7 +170,9 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 					return right(f)
 				case node.DerefNode:
 					return This(expectExpr(f, z, func(in ...IN) (out OUT) {
-						arr := rt2.ValueOf(f)[z.Adr()].(scope.Array)
+						v := rt2.ValueOf(f)[z.Adr()]
+						arr, ok := v.(scope.Array)
+						assert.For(ok, 40, v)
 						left = arr.Get(left)
 						out.do = Expose(right)
 						out.next = NOW
@@ -171,8 +182,8 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 					halt.As(100, reflect.TypeOf(z), z)
 				}
 				panic(0)
-			}
-			ret = frame.LATER
+			}*/
+
 		case node.DerefNode:
 			//			rt2.DataOf(f)[a.Left()] = scope.ID{}
 			rt2.Push(rt2.New(a.Left()), f)
@@ -205,17 +216,17 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		}
 	case statement.NEW:
 		heap := f.Domain().Discover(context.HEAP).(scope.Manager).Target().(scope.HeapAllocator)
-		if a.Right() != nil {
+		if a.Right() != nil { //размер массива справа, если его нет, значит это NEW для рекорда
 			seq, ret = This(expectExpr(f, a.Right(), func(in ...IN) (out OUT) {
 				//fmt.Println("NEW", rt2.ValueOf(f)[a.Right().Adr()], "here")
 				switch z := a.Left().(type) {
 				case node.VariableNode:
 					sc := rt2.ScopeFor(f, a.Left().Object().Adr())
-					fn := heap.Allocate(a.Left(), rt2.ValueOf(f)[a.Right().Adr()])
+					fn := heap.Allocate(z.Object(), z.Object().Complex().(object.PointerType), rt2.ValueOf(f)[a.Right().Adr()])
 					sc.Update(a.Left().Object().Adr(), fn)
 					return End()
 				case node.FieldNode:
-					fn := heap.Allocate(a.Left(), rt2.ValueOf(f)[a.Right().Adr()])
+					fn := heap.Allocate(z.Object(), z.Object().Complex().(object.PointerType), rt2.ValueOf(f)[a.Right().Adr()])
 					rt2.Push(rt2.New(z), in[0].frame)
 					rt2.Assert(f, func(f frame.Frame) (bool, int) {
 						return rt2.ValueOf(f)[z.Adr()] != nil, 65
@@ -227,6 +238,15 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 					}
 					out.next = LATER
 					return
+				case node.IndexNode:
+					return expectExpr(in[0].frame, z, func(...IN) OUT {
+						obj, ok := rt2.RegOf(in[0].frame)[context.META].(object.Object)
+						assert.For(ok, 40, rt2.RegOf(in[0].frame))
+						fn := heap.Allocate(obj, obj.Complex().(object.PointerType), rt2.ValueOf(f)[a.Right().Adr()])
+						idx := rt2.ValueOf(in[0].frame)[z.Adr()].(scope.Variable)
+						idx.Set(fn(nil))
+						return End()
+					})
 				default:
 					halt.As(100, reflect.TypeOf(z))
 				}
@@ -234,7 +254,7 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			}))
 		} else {
 			//fmt.Println("NEW here", a.Left().Adr())
-			fn := heap.Allocate(a.Left())
+			fn := heap.Allocate(a.Left().Object(), a.Left().Object().Complex().(object.PointerType))
 			sc := rt2.ScopeFor(f, a.Left().Object().Adr())
 			sc.Update(a.Left().Object().Adr(), fn)
 			return frame.End()

+ 1 - 1
rt2/rules/call.go

@@ -152,7 +152,7 @@ func go_math(f frame.Frame, par node.Node) (seq frame.Sequence, ret frame.WAIT)
 	default:
 		halt.As(100, reflect.TypeOf(p))
 	}
-	rt2.RegOf(f.Parent())["RETURN"] = scope.TypeFromGo(res)
+	rt2.RegOf(f.Parent())[context.RETURN] = scope.TypeFromGo(res)
 	return frame.End()
 }
 

+ 22 - 3
rt2/rules/deref.go

@@ -5,6 +5,7 @@ import (
 	"fw/cp/object"
 	"fw/cp/traps"
 	"fw/rt2"
+	"fw/rt2/context"
 	"fw/rt2/frame"
 	"fw/rt2/scope"
 	"reflect"
@@ -15,7 +16,6 @@ import (
 func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f).(node.DerefNode)
 
-	//fmt.Println("deref from ptr", n.Ptr())
 	if n.Ptr() {
 		switch l := n.Left().(type) {
 		case node.ParameterNode, node.VariableNode:
@@ -24,6 +24,7 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				ptr, ok := v.(scope.Pointer)
 				assert.For(ok, 60, reflect.TypeOf(v))
 				rt2.ValueOf(f.Parent())[n.Adr()] = ptr.Get()
+				rt2.RegOf(f.Parent())[context.META] = l.Object()
 				if scope.GoTypeFrom(ptr.Get()) == nil {
 					seq, ret = doTrap(f, traps.NILderef)
 				} else {
@@ -31,19 +32,34 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				}
 			})
 			return seq, ret
+		case node.IndexNode:
+			return This(expectExpr(f, l, func(...IN) (out OUT) {
+				v := rt2.ValueOf(f)[l.Adr()]
+				ptr, ok := v.(scope.Pointer)
+				assert.For(ok, 60, reflect.TypeOf(v))
+				rt2.ValueOf(f.Parent())[n.Adr()] = ptr.Get()
+				rt2.RegOf(f.Parent())[context.META] = rt2.RegOf(f)[context.META]
+				if scope.GoTypeFrom(ptr.Get()) == nil {
+					out = thisTrap(f, traps.NILderef)
+				} else {
+					out = End()
+				}
+				return
+			}))
 		case node.FieldNode, node.CallNode:
 			rt2.Push(rt2.New(l), f)
 			rt2.Assert(f, func(f frame.Frame) (bool, int) {
-				return rt2.ValueOf(f)[l.Adr()] != nil || rt2.RegOf(f)["RETURN"] != nil, 63
+				return rt2.ValueOf(f)[l.Adr()] != nil || rt2.RegOf(f)[context.RETURN] != nil, 63
 			})
 			seq = func(f frame.Frame) (frame.Sequence, frame.WAIT) {
 				v := rt2.ValueOf(f)[l.Adr()]
 				if v == nil {
-					v = rt2.RegOf(f)["RETURN"].(scope.Value)
+					v = rt2.RegOf(f)[context.RETURN].(scope.Value)
 				}
 				ptr, ok := v.(scope.Pointer)
 				assert.For(ok, 60, reflect.TypeOf(v))
 				rt2.ValueOf(f.Parent())[n.Adr()] = ptr.Get()
+				rt2.RegOf(f.Parent())[context.META] = rt2.RegOf(f)[context.META]
 				if scope.GoTypeFrom(ptr.Get()) == nil {
 					seq, ret = doTrap(f, traps.NILderef)
 				} else {
@@ -75,6 +91,7 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			case object.ParameterObject, object.VariableObject:
 				sc := rt2.ScopeFor(f, l.Adr())
 				val := sc.Select(l.Adr())
+				rt2.RegOf(f.Parent())[context.META] = l
 				deref(val)
 				return frame.End()
 			default:
@@ -89,6 +106,7 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				})
 				seq = Propose(func(...IN) OUT {
 					deref(rt2.ValueOf(f)[left.Adr()])
+					rt2.RegOf(f.Parent())[context.META] = rt2.RegOf(f)[context.META]
 					return End()
 				})
 				ret = LATER.wait()
@@ -101,6 +119,7 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 					val := rt2.ValueOf(f)[left.Adr()]
 					sc := rt2.ScopeFor(f, left.Left().Object().Adr())
 					arr := sc.Select(left.Left().Object().Adr()).(scope.Array)
+					rt2.RegOf(f.Parent())[context.META] = left.Object()
 					deref(arr.Get(val).(scope.Pointer).Get())
 					//rt2.ValueOf(f.Parent())[n.Adr()] = rt2.ValueOf(f)[left.Adr()]
 					//halt.As(100, reflect.TypeOf(rt2.ValueOf(f)[left.Adr()]))

+ 10 - 4
rt2/rules/expect.go

@@ -5,6 +5,7 @@ import (
 	"fw/cp/node"
 	"fw/cp/object"
 	"fw/rt2"
+	"fw/rt2/context"
 	"fw/rt2/frame"
 	rtm "fw/rt2/module"
 	"fw/rt2/scope"
@@ -44,7 +45,7 @@ func expectExpr(parent frame.Frame, expr node.Node, next Do) OUT {
 		rt2.Push(rt2.New(expr), parent)
 		wait := func(...IN) OUT {
 			if rt2.RegOf(parent)[expr] == nil && rt2.ValueOf(parent)[expr.Adr()] == nil {
-				raw := rt2.RegOf(parent)["RETURN"]
+				raw := rt2.RegOf(parent)[context.RETURN]
 				if val, ok := raw.(scope.Value); !ok {
 					halt.As(100, "no result from ", expr.Adr(), raw)
 				} else {
@@ -62,9 +63,14 @@ func expectExpr(parent frame.Frame, expr node.Node, next Do) OUT {
 		wait := func(in ...IN) OUT {
 			idx := rt2.ValueOf(parent)[e.Adr()]
 			return expectExpr(in[0].frame, e.Left(), func(...IN) OUT {
-				arr := rt2.ValueOf(in[0].frame)[e.Left().Adr()].(scope.Array)
-				idx = arr.Get(idx)
-				rt2.ValueOf(parent)[e.Adr()] = idx
+				v := rt2.ValueOf(in[0].frame)[e.Left().Adr()]
+				switch vv := v.(type) {
+				case scope.Array:
+					idx = vv.Get(idx)
+					rt2.ValueOf(parent)[e.Adr()] = idx
+				default:
+					halt.As(100, reflect.TypeOf(vv), vv, rt2.ValueOf(in[0].frame))
+				}
 				return OUT{do: next, next: NOW}
 			})
 		}

+ 3 - 1
rt2/rules/field.go

@@ -7,6 +7,7 @@ import (
 import (
 	"fw/cp/node"
 	"fw/rt2"
+	"fw/rt2/context"
 	"fw/rt2/frame"
 	"fw/rt2/scope"
 	"ypk/halt"
@@ -25,7 +26,7 @@ func fieldSeq(in ...IN) (out OUT) {
 		sc := rt2.ScopeFor(f, l.Object().Adr())
 		sc.Select(l.Object().Adr(), func(v scope.Value) {
 			rt2.ValueOf(f.Parent())[n.Adr()] = v.(scope.Record).Get(n.Object().Adr())
-			//fmt.Println(n.Object().Adr())
+			rt2.RegOf(f.Parent())[context.META] = n.Object()
 		})
 		out = End()
 	case node.FieldNode, node.DerefNode:
@@ -37,6 +38,7 @@ func fieldSeq(in ...IN) (out OUT) {
 		out.do = func(in ...IN) OUT {
 			v := rt2.ValueOf(in[0].frame)[l.Adr()].(scope.Record)
 			rt2.ValueOf(f.Parent())[n.Adr()] = v.Get(n.Object().Adr())
+			rt2.RegOf(f.Parent())[context.META] = rt2.RegOf(in[0].frame)[context.META]
 			return End()
 		}
 		out.next = LATER

+ 3 - 0
rt2/rules/op.go

@@ -172,6 +172,9 @@ func dopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		case operation.MOD:
 			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.ALIEN_MSK:
+			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Msk(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
+			return frame.End()
 		case operation.TIMES:
 			rt2.ValueOf(f.Parent())[n.Adr()] = scope.Ops.Mult(rt2.ValueOf(f)[n.Left().Adr()], rt2.ValueOf(f)[n.Right().Adr()])
 			return frame.End()

+ 9 - 8
rt2/rules/return.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"fw/cp/node"
 	"fw/rt2"
+	"fw/rt2/context"
 	"fw/rt2/frame"
 	"reflect"
 )
@@ -17,7 +18,7 @@ func returnSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				//rt2.DataOf(f.Parent())[a.Object()] = a.Left().(node.ConstantNode).Data()
 				rt2.ValueOf(f.Parent())[a.Object().Adr()] = rt2.ThisScope(f).Provide(a.Left())(nil)
-				rt2.RegOf(f.Parent())["RETURN"] = rt2.ValueOf(f.Parent())[a.Object().Adr()]
+				rt2.RegOf(f.Parent())[context.RETURN] = rt2.ValueOf(f.Parent())[a.Object().Adr()]
 				return frame.End()
 			}
 			ret = frame.NOW
@@ -25,7 +26,7 @@ func returnSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				sc := rt2.ScopeFor(f, a.Left().Object().Adr())
 				rt2.ValueOf(f.Parent())[a.Object().Adr()] = sc.Select(a.Left().Object().Adr())
-				rt2.RegOf(f.Parent())["RETURN"] = rt2.ValueOf(f.Parent())[a.Object().Adr()]
+				rt2.RegOf(f.Parent())[context.RETURN] = rt2.ValueOf(f.Parent())[a.Object().Adr()]
 				return frame.End()
 			}
 			ret = frame.NOW
@@ -33,9 +34,9 @@ func returnSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 			rt2.Push(rt2.New(a.Left()), f)
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				rt2.ValueOf(f.Parent())[a.Object().Adr()] = rt2.ValueOf(f)[a.Left().Adr()]
-				rt2.RegOf(f.Parent())["RETURN"] = rt2.ValueOf(f)[a.Left().Adr()]
-				if rt2.RegOf(f.Parent())["RETURN"] == nil {
-					rt2.RegOf(f.Parent())["RETURN"] = rt2.RegOf(f)["RETURN"]
+				rt2.RegOf(f.Parent())[context.RETURN] = rt2.ValueOf(f)[a.Left().Adr()]
+				if rt2.RegOf(f.Parent())[context.RETURN] == nil {
+					rt2.RegOf(f.Parent())[context.RETURN] = rt2.RegOf(f)[context.RETURN]
 				}
 				return frame.End()
 			}
@@ -43,9 +44,9 @@ func returnSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 		case node.IndexNode:
 			return This(expectExpr(f, a.Left(), func(...IN) OUT {
 				rt2.ValueOf(f.Parent())[a.Object().Adr()] = rt2.ValueOf(f)[a.Left().Adr()]
-				rt2.RegOf(f.Parent())["RETURN"] = rt2.ValueOf(f)[a.Left().Adr()]
-				if rt2.RegOf(f.Parent())["RETURN"] == nil {
-					rt2.RegOf(f.Parent())["RETURN"] = rt2.RegOf(f)["RETURN"]
+				rt2.RegOf(f.Parent())[context.RETURN] = rt2.ValueOf(f)[a.Left().Adr()]
+				if rt2.RegOf(f.Parent())[context.RETURN] == nil {
+					rt2.RegOf(f.Parent())[context.RETURN] = rt2.RegOf(f)[context.RETURN]
 				}
 				return End()
 			}))

+ 1 - 1
rt2/scope/area.go

@@ -40,7 +40,7 @@ type ScopeAllocator interface {
 
 type HeapAllocator interface {
 	Allocator
-	Allocate(n node.Node, par ...interface{}) ValueFor //указатель лежит в скоупе процедуры/модуля, а рекорд - в куче, поэтому нужно после создания экземпляра обновить указатель
+	Allocate(object.Object, object.PointerType, ...interface{}) ValueFor //указатель лежит в скоупе процедуры/модуля, а рекорд - в куче, поэтому нужно после создания экземпляра обновить указатель
 	Dispose(id cp.ID)
 }
 

+ 1 - 0
rt2/scope/data.go

@@ -17,6 +17,7 @@ type Operations interface {
 	Min(Value, Value) Value
 	Div(Value, Value) Value
 	Mod(Value, Value) Value
+	Msk(Value, Value) Value
 	Mult(Value, Value) Value
 	Divide(Value, Value) Value
 	In(Value, Value) Value

+ 9 - 18
rt2/scope/modern/hp.go

@@ -57,9 +57,11 @@ func fin(x interface{}) {
 	}
 }
 
-func (h *halloc) Allocate(n node.Node, par ...interface{}) scope.ValueFor {
+func (h *halloc) Allocate(o object.Object, t object.PointerType, par ...interface{}) scope.ValueFor {
 	//fmt.Println("HEAP ALLOCATE")
-	mod := rtm.ModuleOfNode(h.area.d, n)
+	mod := rtm.ModuleOfType(h.area.d, t)
+	assert.For(t != nil, 20)
+	assert.For(o != nil, 21)
 	if h.area.data == nil {
 		h.area.data = append(h.area.data, newlvl())
 	}
@@ -72,14 +74,14 @@ func (h *halloc) Allocate(n node.Node, par ...interface{}) scope.ValueFor {
 	}
 	var talloc func(t object.PointerType)
 	talloc = func(t object.PointerType) {
-		switch bt := t.Base().(type) {
+		switch bt := t.Complex().(type) {
 		case object.RecordType:
 			fake := object.New(object.VARIABLE, cp.Some())
 			fake.SetComplex(bt)
 			fake.SetType(object.COMPLEX)
-			fake.SetName("{" + n.Object().Name() + "}")
+			fake.SetName("{" + o.Name() + "}")
 			l.alloc(h.area.d, mod, nil, append(ol, fake), skip)
-			res = &ptrValue{scope: h.area, id: fake.Adr(), link: n.Object()}
+			res = &ptrValue{scope: h.area, id: fake.Adr(), link: o}
 		case object.DynArrayType:
 			assert.For(len(par) > 0, 20)
 			fake := object.New(object.VARIABLE, cp.Some())
@@ -92,23 +94,12 @@ func (h *halloc) Allocate(n node.Node, par ...interface{}) scope.ValueFor {
 				assert.For(ok, 60)
 				arr.Set(par[0].(scope.Value))
 			})
-			res = &ptrValue{scope: h.area, id: fake.Adr(), link: n.Object()}
+			res = &ptrValue{scope: h.area, id: fake.Adr(), link: o}
 		default:
 			halt.As(100, fmt.Sprintln("cannot allocate", reflect.TypeOf(bt)))
 		}
 	}
-	switch v := n.(type) {
-	case node.VariableNode, node.FieldNode:
-		switch t := v.Object().Complex().(type) {
-		case object.PointerType:
-			talloc(t)
-			//h.area.data[0].alloc(mod, nil, )
-		default:
-			halt.As(100, reflect.TypeOf(t))
-		}
-	default:
-		halt.As(101, reflect.TypeOf(v), v)
-	}
+	talloc(t)
 	assert.For(res != nil, 60)
 	runtime.SetFinalizer(res, fin)
 	return f_res

+ 76 - 8
rt2/scope/modern/val.go

@@ -213,7 +213,9 @@ func (a *arr) String() (ret string) {
 		case SHORTCHAR:
 			ret = fmt.Sprint(ret, string([]rune{rune(x)}))
 		case REAL:
-			ret = fmt.Sprint(ret, ", ", a.val[i])
+			ret = fmt.Sprint(ret, ", ", x)
+		case *ptr:
+			ret = fmt.Sprintln(ret, ", ", x)
 		default:
 			halt.As(100, reflect.TypeOf(x))
 		}
@@ -301,6 +303,15 @@ func (i *idx) Set(v scope.Value) {
 		i.val()[i.idx].(*arr).Set(x)
 	case REAL:
 		i.val()[i.idx] = x
+	case *ptrValue:
+		switch tt := t.(type) {
+		case object.DynArrayType:
+			_, ok := tt.Complex().(object.PointerType)
+			assert.For(ok, 20)
+			i.val()[i.idx] = &ptr{link: x.link, val: x}
+		default:
+			halt.As(100, reflect.TypeOf(tt))
+		}
 	default:
 		halt.As(100, reflect.TypeOf(x), x, t)
 	}
@@ -311,6 +322,8 @@ func (i *idx) Get() scope.Value {
 	switch z := x.(type) {
 	case *arr:
 		return z
+	case *ptr:
+		return z
 	case CHAR:
 		return z
 	case nil:
@@ -356,6 +369,8 @@ func (a *dynarr) String() (ret string) {
 			ret = fmt.Sprint(ret, string([]rune{rune(x)}))
 		case SHORTCHAR:
 			ret = fmt.Sprint(ret, string([]rune{rune(x)}))
+		case *ptr:
+			ret = fmt.Sprint(ret, ", ", x)
 		default:
 			halt.As(100, reflect.TypeOf(x))
 		}
@@ -679,6 +694,8 @@ func gfrom(v scope.Value) interface{} {
 		}
 	case *rec:
 		return n
+	case *ptr:
+		return n
 	case *proc:
 		return n.link
 	case *dynarr:
@@ -695,6 +712,8 @@ func gfrom(v scope.Value) interface{} {
 			} else {
 				return ""
 			}
+		case object.COMPLEX:
+			return n.val
 		default:
 			halt.As(100, n.link.Complex().(object.DynArrayType).Base())
 		}
@@ -1121,7 +1140,56 @@ func (o *ops) Mod(a, b scope.Value) scope.Value {
 			case LONGINT:
 				switch y := b.(type) {
 				case LONGINT:
-					return LONGINT(x % y)
+					z := x % y
+					switch {
+					case (x < 0) != (y < 0):
+						z = z + y
+					}
+					return LONGINT(z)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			default:
+				panic(fmt.Sprintln(reflect.TypeOf(x)))
+			}
+		}
+	}
+	panic(0)
+}
+
+func (o *ops) Msk(a, b scope.Value) scope.Value {
+	switch a.(type) {
+	case *data:
+		return o.Msk(vfrom(a), b)
+	default:
+		switch b.(type) {
+		case *data:
+			return o.Msk(a, vfrom(b))
+		default:
+			switch x := a.(type) {
+			case INTEGER:
+				switch y := b.(type) {
+				case INTEGER:
+					y = -y
+					z := x % y
+					switch {
+					case (x < 0) != (y < 0):
+						z = z + y
+					}
+					return INTEGER(z)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
+			case LONGINT:
+				switch y := b.(type) {
+				case LONGINT:
+					y = -y
+					z := x % y
+					switch {
+					case (x < 0) != (y < 0):
+						z = z + y
+					}
+					return LONGINT(z)
 				default:
 					panic(fmt.Sprintln(reflect.TypeOf(y)))
 				}
@@ -1277,15 +1345,15 @@ func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
 					//	fmt.Println("eq")
 					//fmt.Println("qid ", _x.Qualident(), _a.Qualident(), "names ", x.Name(), a.Name())
 					return true //опасно сравнивать имена конеш
-				case x.Base() != nil:
+				case x.Complex() != nil:
 					//	fmt.Println("go base")
-					return compare(x.Base(), a)
+					return compare(x.Complex(), a)
 				default:
 					return false
 				}
 			case object.PointerType:
-				if a.Base() != nil {
-					return compare(x, a.Base())
+				if a.Complex() != nil {
+					return compare(x, a.Complex())
 				} else {
 					fmt.Println("here")
 					return false
@@ -1300,9 +1368,9 @@ func (o *ops) Is(a scope.Value, typ object.ComplexType) scope.Value {
 				case x.Name() == a.Name():
 					//	fmt.Println("eq")
 					return true //опасно сравнивать имена конеш
-				case x.Base() != nil:
+				case x.Complex() != nil:
 					//	fmt.Println("go base")
-					return compare(x.Base(), a)
+					return compare(x.Complex(), a)
 				default:
 					return false
 				}

+ 11 - 4
xev/converter.go

@@ -219,8 +219,8 @@ func (r *Result) doType(n *Node) (ret object.ComplexType) {
 				t := object.NewPointerType(n.Data.Typ.Name, n.Id)
 				base := r.findLink(n, "base")
 				if base != nil {
-					t.Base(r.doType(base))
-					assert.For(t.Base() != nil, 41)
+					t.Complex(r.doType(base))
+					assert.For(t.Complex() != nil, 41)
 				}
 				ret = t
 			default:
@@ -236,8 +236,15 @@ func (r *Result) doType(n *Node) (ret object.ComplexType) {
 				ret = object.NewDynArrayType(object.SHORTCHAR, n.Id)
 			case "REAL":
 				ret = object.NewDynArrayType(object.REAL, n.Id)
+			case "POINTER":
+				ret = object.NewDynArrayType(object.COMPLEX, n.Id)
+				base := r.findLink(n, "base")
+				if base != nil {
+					ret.(object.DynArrayType).Complex(r.doType(base))
+					assert.For(ret.(object.DynArrayType).Complex() != nil, 41)
+				}
 			default:
-				panic(fmt.Sprintln("unknown dyn type", n.Data.Typ.Base, n.Data.Typ.Typ))
+				panic(fmt.Sprintln("unknown dyn type", n.Id, n.Data.Typ.Base, n.Data.Typ.Typ))
 			}
 		case "ARRAY":
 			switch n.Data.Typ.Base {
@@ -272,7 +279,7 @@ func (r *Result) doType(n *Node) (ret object.ComplexType) {
 			}
 			base := r.findLink(n, "base")
 			if base != nil {
-				ret.(object.RecordType).Base(r.doType(base))
+				ret.(object.RecordType).Complex(r.doType(base))
 				assert.For(ret.(object.RecordType).BaseRec() != nil, 41)
 			}
 		default: