Sfoglia il codice sorgente

добрался до указателей, пока все идет успешно

kpmy 10 anni fa
parent
commit
ea1fb563bc

+ 1 - 1
fw.go

@@ -36,7 +36,7 @@ func main() {
 	flag.Parse()
 	utils.Debug(debug)
 	if name == "" {
-		name = "XevDemo7"
+		name = "XevDemo19"
 		utils.Debug(false)
 	}
 	global := &stdDomain{god: true}

+ 0 - 0
rt2/rules2/wrap/data/level.go → rt2/_modern/level.go


+ 1 - 1
rt2/nodeframe/frame.go

@@ -143,7 +143,7 @@ func (f *nodeFrame) OnPop() {
 				if !ok {
 					panic(fmt.Sprintln("assert for", reflect.TypeOf(ff.ir), ff.ir, fmt.Sprint(msg...)))
 				} else {
-					utils.PrintFrame("assert passed for", reflect.TypeOf(ff.ir), ff.ir, fmt.Sprint(msg...))
+					utils.PrintFrame("assert passed for", reflect.TypeOf(ff.ir), ff.ir)
 				}
 			}
 			ff.assertion(ff, check)

+ 10 - 5
rt2/rules2/wrap/data/items/items.go

@@ -3,6 +3,7 @@ package items
 import (
 	"container/list"
 	"fmt"
+	"fw/utils"
 	"ypk/assert"
 	"ypk/halt"
 )
@@ -45,9 +46,11 @@ type Data interface {
 
 	Exists(Key) bool
 	ForEach(func(Value) bool)
+
 	Begin()
 	End()
 	Drop()
+	Check()
 }
 
 func New() Data {
@@ -109,7 +112,7 @@ func (d *data) ForEach(f func(Value) bool) {
 
 func (d *data) Get(k Key, opts ...Opts) (ret Item) {
 	if len(opts) == 0 {
-		d.check()
+		d.Check()
 	} else {
 		switch opts[0] {
 		case INIT: //do nothing
@@ -206,19 +209,21 @@ type limit_key struct{}
 func (l *limit_key) EqualTo(Key) int { return -1 }
 func (l *limit) KeyOf(...Key) Key    { return &limit_key{} }
 
-func (d *data) check() {
+func (d *data) Check() {
 	t := d.x.Front()
 	if t != nil {
 		_, ok := t.Value.(*limit)
-		assert.For(ok, 30)
+		assert.For(ok, 30, "data not ready")
 	}
 }
 
 func (d *data) Begin() {
-	d.check()
+	utils.PrintScope("BEGIN")
+	d.Check()
 }
 
 func (d *data) End() {
+	utils.PrintScope("END")
 	for x := d.x.Front(); x != nil; {
 		d, ok := x.Value.(*dummy)
 		assert.For(!ok, 40, "missing value for item ", d)
@@ -232,7 +237,7 @@ func (d *data) End() {
 	d.x.PushFront(&limit{})
 }
 func (d *data) Drop() {
-	d.check()
+	d.Check()
 	for x := d.x.Front(); x != nil; {
 		d.x.Remove(x)
 		x = d.x.Front()

+ 54 - 12
rt2/rules2/wrap/data/stack.go

@@ -19,9 +19,10 @@ import (
 )
 
 type area struct {
-	d   context.Domain
-	all scope.Allocator
-	il  items.Data
+	d    context.Domain
+	all  scope.Allocator
+	il   items.Data
+	init bool
 }
 
 type salloc struct {
@@ -74,7 +75,11 @@ func (i *item) Value() scope.Value {
 
 func (a *area) Select(this cp.ID, val scope.ValueOf) {
 	utils.PrintScope("SELECT", this)
-	d, ok := a.il.Get(&key{id: this}).(*item)
+	opts := make([]items.Opts, 0)
+	if a.init {
+		opts = append(opts, items.INIT)
+	}
+	d, ok := a.il.Get(&key{id: this}, opts...).(*item)
 	assert.For(ok, 20, this)
 	val(d.Value())
 }
@@ -84,27 +89,60 @@ func (a *area) Exists(this cp.ID) bool {
 	return a.il.Exists(&key{id: this})
 }
 
-func (a *salloc) push(_o object.Object) {
+func push(dom context.Domain, il items.Data, _o object.Object) {
 	switch o := _o.(type) {
-	case object.VariableObject:
+	case object.VariableObject, object.FieldObject:
 		switch t := o.Complex().(type) {
 		case nil, object.BasicType:
 			x := newData(o)
 			d := &item{}
 			d.Data(x)
-			a.area.il.Set(&key{id: o.Adr()}, d)
+			il.Set(&key{id: o.Adr()}, d)
 		case object.ArrayType, object.DynArrayType:
 			x := newData(o)
 			d := &item{}
 			d.Data(x)
-			a.area.il.Set(&key{id: o.Adr()}, d)
-		//case object.RecordType:
-
+			il.Set(&key{id: o.Adr()}, d)
+		case object.RecordType:
+			ml := dom.Global().Discover(context.MOD).(rtm.List)
+			x := newRec(o)
+			d := &item{}
+			d.Data(x)
+			il.Set(&key{id: o.Adr()}, d)
+			fl := make([]object.Object, 0)
+			for rec := t; rec != nil; {
+				for x := rec.Link(); x != nil; x = x.Link() {
+					switch x.(type) {
+					case object.FieldObject:
+						//fmt.Println(o.Name(), ".", x.Name(), x.Adr())
+						fl = append(fl, x)
+					case object.ParameterObject, object.ProcedureObject, object.VariableObject:
+						//do nothing
+					default:
+						halt.As(100, reflect.TypeOf(x))
+					}
+				}
+				if rec.BaseRec() == nil {
+					x := ml.NewTypeCalc()
+					x.ConnectTo(rec)
+					_, frec := x.ForeignBase()
+					//fmt.Println(frec)
+					rec, _ = frec.(object.RecordType)
+				} else {
+					rec = rec.BaseRec()
+				}
+			}
+			x.fi = items.New()
+			x.fi.Begin()
+			for _, f := range fl {
+				push(dom, x.fi, f)
+			}
+			x.fi.End()
 		default:
 			halt.As(100, reflect.TypeOf(t))
 		}
 	case object.ParameterObject:
-		a.area.il.Hold(&key{id: o.Adr()})
+		il.Hold(&key{id: o.Adr()})
 	default:
 		halt.As(100, reflect.TypeOf(o))
 	}
@@ -154,18 +192,21 @@ func (a *salloc) Allocate(n node.Node, final bool) {
 		}
 	}
 	a.area.il.Begin()
+	a.area.init = true
 	for _, o := range ol {
 		if skip[o.Adr()] == nil {
 			utils.PrintScope(o.Adr(), o.Name())
-			a.push(o)
+			push(a.area.d, a.area.il, o)
 		}
 	}
 	if final {
 		a.area.il.End()
+		a.area.init = false
 	}
 }
 
 func (a *salloc) Dispose(n node.Node) {
+	utils.PrintScope("DISPOSE")
 	a.area.il.Drop()
 }
 
@@ -174,6 +215,7 @@ func (a *salloc) proper_init(root node.Node, _val node.Node, _par object.Object,
 	const link = "initialize:par"
 	end := func(in eval.IN) eval.OUT {
 		a.area.il.End()
+		a.area.init = false
 		return eval.Later(tail)
 	}
 	var next eval.Do

+ 6 - 11
rt2/rules2/wrap/data/val.go

@@ -5,7 +5,7 @@ import (
 	"fw/cp"
 	"fw/cp/node"
 	"fw/cp/object"
-	//	rtm "fw/rt2/module"
+	"fw/rt2/rules2/wrap/data/items"
 	"fw/rt2/scope"
 	"fw/utils"
 	"math"
@@ -39,7 +39,7 @@ type proc struct {
 type rec struct {
 	link object.Object
 	scope.Record
-	l *level
+	fi items.Data
 }
 
 type ptr struct {
@@ -98,15 +98,10 @@ func (r *rec) Set(v scope.Value) {
 	panic(0)
 }
 
-func (r *rec) Get(id cp.ID) scope.Value {
-	k := r.l.k[id]
-	if r.l.v[k] == nil { //ref
-		//fmt.Println(r.Id(), id)
-		assert.For(r.l.r[k] != nil, 20, id, k)
-		return r.l.r[k]
-	} else {
-		return r.l.v[k]
-	}
+func (r *rec) Get(i cp.ID) scope.Value {
+	x, ok := r.fi.Get(&key{id: i}).(*item)
+	assert.For(ok, 40)
+	return x.Value()
 }
 
 func newRec(o object.Object) *rec {