Browse Source

добавил и отладил работу итератора и прохода по итератору

kpmy 10 years ago
parent
commit
2fb0cfe36a

BIN
code/XevLog.oz


BIN
code/XevStrings.oz


BIN
code/XevTest0.oz


+ 3 - 0
cp/object/type.go

@@ -26,6 +26,7 @@ const (
 	COMPLEX
 	COMPLEX
 	STRING
 	STRING
 	SHORTSTRING
 	SHORTSTRING
+	NIL
 )
 )
 
 
 func (t Type) String() string {
 func (t Type) String() string {
@@ -60,6 +61,8 @@ func (t Type) String() string {
 		return "STRING"
 		return "STRING"
 	case SHORTSTRING:
 	case SHORTSTRING:
 		return "SHORTSTRING"
 		return "SHORTSTRING"
+	case NIL:
+		return "NIL"
 	default:
 	default:
 		return fmt.Sprint("looks like new type here", int(t))
 		return fmt.Sprint("looks like new type here", int(t))
 	}
 	}

+ 7 - 1
fw.go

@@ -10,17 +10,22 @@ import (
 	_ "fw/rt2/rules"
 	_ "fw/rt2/rules"
 	"fw/rt2/scope"
 	"fw/rt2/scope"
 	_ "fw/rt2/scope/modern"
 	_ "fw/rt2/scope/modern"
+	"fw/utils"
 	"time"
 	"time"
 	"ypk/assert"
 	"ypk/assert"
 )
 )
 
 
 var name string
 var name string
+var heap scope.Manager
 
 
 func init() {
 func init() {
 	flag.StringVar(&name, "i", "", "-i name.ext")
 	flag.StringVar(&name, "i", "", "-i name.ext")
 }
 }
 
 
 func close() {
 func close() {
+	utils.PrintFrame("____")
+	utils.PrintFrame(heap)
+	utils.PrintFrame("^^^^")
 	fmt.Println("closed")
 	fmt.Println("closed")
 }
 }
 
 
@@ -33,7 +38,8 @@ func main() {
 	global.global = global
 	global.global = global
 	modList := rtmod.New()
 	modList := rtmod.New()
 	global.Attach(context.MOD, modList)
 	global.Attach(context.MOD, modList)
-	global.Attach(context.HEAP, scope.New(context.HEAP))
+	heap = scope.New(context.HEAP)
+	global.Attach(context.HEAP, heap)
 	t0 := time.Now()
 	t0 := time.Now()
 	var init []*mod.Module
 	var init []*mod.Module
 	_, err := modList.Load(name, func(m *mod.Module) {
 	_, err := modList.Load(name, func(m *mod.Module) {

+ 3 - 3
rt2/nodeframe/frame.go

@@ -72,8 +72,8 @@ type nodeFrame struct {
 func done(f frame.Frame) {
 func done(f frame.Frame) {
 	utils.PrintFrame("____")
 	utils.PrintFrame("____")
 	utils.PrintFrame(f.Domain().Discover(context.SCOPE))
 	utils.PrintFrame(f.Domain().Discover(context.SCOPE))
-	utils.PrintFrame("--")
-	utils.PrintFrame(f.Domain().Discover(context.HEAP))
+	//	utils.PrintFrame("--")
+	//	utils.PrintFrame(f.Domain().Discover(context.HEAP))
 	utils.PrintFrame("^^^^")
 	utils.PrintFrame("^^^^")
 }
 }
 
 
@@ -99,7 +99,7 @@ func (f *nodeFrame) Do() frame.WAIT {
 func (f *nodeFrame) onPush() {
 func (f *nodeFrame) onPush() {
 	f.num = count
 	f.num = count
 	count++
 	count++
-	assert.For(count < 15, 40)
+	//	assert.For(count < 15, 40)
 	utils.PrintFrame("_", "PUSH", reflect.TypeOf(f.ir))
 	utils.PrintFrame("_", "PUSH", reflect.TypeOf(f.ir))
 	f.seq = decision.PrologueFor(f.ir)
 	f.seq = decision.PrologueFor(f.ir)
 }
 }

+ 2 - 2
rt2/rules/assign.go

@@ -69,7 +69,7 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				return frame.End()
 				return frame.End()
 			}
 			}
 			ret = frame.NOW
 			ret = frame.NOW
-		case node.OperationNode, node.CallNode, node.DerefNode:
+		case node.OperationNode, node.CallNode, node.DerefNode, node.FieldNode:
 			rt2.Push(rt2.New(a.Right()), f)
 			rt2.Push(rt2.New(a.Right()), f)
 			rt2.Assert(f, func(f frame.Frame) (bool, int) {
 			rt2.Assert(f, func(f frame.Frame) (bool, int) {
 				return rt2.ValueOf(f)[a.Right().Adr()] != nil, 61
 				return rt2.ValueOf(f)[a.Right().Adr()] != nil, 61
@@ -177,7 +177,7 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				return End()
 				return End()
 			}))
 			}))
 		} else {
 		} else {
-			fmt.Println("NEW here")
+			//fmt.Println("NEW here")
 			fn := heap.Allocate(a.Left())
 			fn := heap.Allocate(a.Left())
 			sc.Update(a.Left().Object().Adr(), fn)
 			sc.Update(a.Left().Object().Adr(), fn)
 			return frame.End()
 			return frame.End()

+ 1 - 1
rt2/rules/call.go

@@ -61,7 +61,7 @@ func process(f frame.Frame, par node.Node) (frame.Sequence, frame.WAIT) {
 			if err := json.Unmarshal([]byte(val), msg); err == nil {
 			if err := json.Unmarshal([]byte(val), msg); err == nil {
 				switch msg.Type {
 				switch msg.Type {
 				case "log":
 				case "log":
-					fmt.Println(msg.Data)
+					fmt.Print(msg.Data)
 					callHandler(f, scope.FindObjByName(sm, "go_handler"), `{"type":"log"}`)
 					callHandler(f, scope.FindObjByName(sm, "go_handler"), `{"type":"log"}`)
 				default:
 				default:
 					panic(40)
 					panic(40)

+ 3 - 3
rt2/rules/table.go

@@ -10,7 +10,7 @@ import (
 	"fw/rt2/decision"
 	"fw/rt2/decision"
 	"fw/rt2/frame"
 	"fw/rt2/frame"
 	"fw/rt2/frame/std"
 	"fw/rt2/frame/std"
-	rt_module "fw/rt2/module"
+	//	rt_module "fw/rt2/module"
 	"fw/rt2/scope"
 	"fw/rt2/scope"
 	"fw/utils"
 	"fw/utils"
 	"reflect"
 	"reflect"
@@ -114,7 +114,7 @@ func epilogue(n node.Node) frame.Sequence {
 		}
 		}
 	case node.EnterNode:
 	case node.EnterNode:
 		return func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		return func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
-			fmt.Println(rt_module.DomainModule(f.Domain()).Name)
+			//fmt.Println(rt_module.DomainModule(f.Domain()).Name)
 			sm := f.Domain().Discover(context.SCOPE).(scope.Manager)
 			sm := f.Domain().Discover(context.SCOPE).(scope.Manager)
 			sm.Target().(scope.ScopeAllocator).Dispose(n)
 			sm.Target().(scope.ScopeAllocator).Dispose(n)
 			//возвращаем результаты вызова функции
 			//возвращаем результаты вызова функции
@@ -228,7 +228,7 @@ func run(global context.Domain, init []*module.Module) {
 		t0 := time.Now()
 		t0 := time.Now()
 		for x := frame.NOW; x == frame.NOW; x = root.Do() {
 		for x := frame.NOW; x == frame.NOW; x = root.Do() {
 			utils.PrintFrame("STEP", i)
 			utils.PrintFrame("STEP", i)
-			assert.For(i < 1000, 40)
+			//assert.For(i < 1000, 40)
 			i++
 			i++
 		}
 		}
 		t1 := time.Now()
 		t1 := time.Now()

+ 15 - 2
rt2/scope/modern/ms.go

@@ -191,13 +191,13 @@ func (a *salloc) Initialize(n node.Node, par scope.PARAM) (seq frame.Sequence, r
 	ret = frame.NOW
 	ret = frame.NOW
 	var sm scope.Manager
 	var sm scope.Manager
 	for next := par.Objects; next != nil; next = next.Link() {
 	for next := par.Objects; next != nil; next = next.Link() {
+		global := f.Domain().Discover(context.UNIVERSE).(context.Domain)
 		mod := rtm.ModuleOfNode(f.Domain(), val)
 		mod := rtm.ModuleOfNode(f.Domain(), val)
 		if mod != nil {
 		if mod != nil {
-			global := f.Domain().Discover(context.UNIVERSE).(context.Domain)
 			//fmt.Println(mod.Name)
 			//fmt.Println(mod.Name)
 			global = global.Discover(mod.Name).(context.Domain)
 			global = global.Discover(mod.Name).(context.Domain)
 			sm = global.Discover(context.SCOPE).(scope.Manager)
 			sm = global.Discover(context.SCOPE).(scope.Manager)
-		} else {
+		} else { //для фиктивных узлов, которые созданы рантаймом, типа INC/DEC
 			sm = a.area
 			sm = a.area
 		}
 		}
 		switch o := next.(type) {
 		switch o := next.(type) {
@@ -209,6 +209,19 @@ func (a *salloc) Initialize(n node.Node, par scope.PARAM) (seq frame.Sequence, r
 			case node.VariableNode:
 			case node.VariableNode:
 				v := sm.Select(nv.Object().Adr())
 				v := sm.Select(nv.Object().Adr())
 				l.v[l.k[o.Adr()]].Set(v)
 				l.v[l.k[o.Adr()]].Set(v)
+			case node.FieldNode:
+				nf := rt2.New(nv)
+				rt2.Push(nf, f)
+				rt2.Assert(f, func(f frame.Frame) (bool, int) {
+					return rt2.ValueOf(f)[nv.Adr()] != nil, 60
+				})
+				rt2.ReplaceDomain(nf, global)
+				seq = func(f frame.Frame) (frame.Sequence, frame.WAIT) {
+					v := rt2.ValueOf(f)[nv.Adr()]
+					l.v[l.k[o.Adr()]].Set(v)
+					return end, frame.NOW
+				}
+				ret = frame.LATER
 			default:
 			default:
 				halt.As(40, reflect.TypeOf(nv))
 				halt.As(40, reflect.TypeOf(nv))
 			}
 			}

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

@@ -474,6 +474,8 @@ func newConst(n node.Node) scope.Value {
 			return STRING(x.Data().(string))
 			return STRING(x.Data().(string))
 		case object.SHORTSTRING:
 		case object.SHORTSTRING:
 			return SHORTSTRING(x.Data().(string))
 			return SHORTSTRING(x.Data().(string))
+		case object.NIL:
+			return NIL
 		default:
 		default:
 			panic(fmt.Sprintln(x.Type()))
 			panic(fmt.Sprintln(x.Type()))
 		}
 		}
@@ -1214,6 +1216,14 @@ func (o *ops) Neq(a, b scope.Value) scope.Value {
 			return o.Neq(a, vfrom(b))
 			return o.Neq(a, vfrom(b))
 		default:
 		default:
 			switch x := a.(type) {
 			switch x := a.(type) {
+			case *ptr:
+				switch y := b.(type) {
+				case PTR:
+					assert.For(y == NIL, 40)
+					return BOOLEAN(x.val != nil && x.val.id != 0)
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
 			case INTEGER:
 			case INTEGER:
 				switch y := b.(type) {
 				switch y := b.(type) {
 				case INTEGER:
 				case INTEGER:

+ 2 - 2
utils/debug.go

@@ -14,12 +14,12 @@ func PrintFrame(x ...interface{}) {
 
 
 func PrintScope(x ...interface{}) {
 func PrintScope(x ...interface{}) {
 	if debugScope {
 	if debugScope {
-		fmt.Println(x[0], x[1])
+		fmt.Println(x...)
 	}
 	}
 }
 }
 
 
 func PrintTrap(x ...interface{}) {
 func PrintTrap(x ...interface{}) {
 	if debugTrap {
 	if debugTrap {
-		fmt.Println(x[0], x[1])
+		fmt.Println(x...)
 	}
 	}
 }
 }

+ 2 - 0
xev/converter.go

@@ -166,6 +166,8 @@ func convertData(typ string, val string, conv convertable) {
 		conv.SetData(val)
 		conv.SetData(val)
 	case "":
 	case "":
 		conv.SetType(object.NOTYPE)
 		conv.SetType(object.NOTYPE)
+	case "NIL":
+		conv.SetType(object.NIL)
 	default:
 	default:
 		panic(fmt.Sprintln("no such constant type", typ))
 		panic(fmt.Sprintln("no such constant type", typ))
 	}
 	}