Răsfoiți Sursa

делаю динамические строки

kpmy 10 ani în urmă
părinte
comite
b12c792da7

BIN
code/Cons.oz


BIN
code/Console.oz


BIN
code/Core.oz


BIN
code/Mathe.oz


BIN
code/Out.oz


BIN
code/Start.oz


BIN
code/Start2.oz


BIN
code/Str.oz


BIN
code/TestA0.oz


BIN
code/TestA1.oz


BIN
code/TestA2.oz


BIN
code/TestMath.oz


BIN
code/TestStrDyn.oz


BIN
code/TestStrings.oz


+ 38 - 5
cp/adr.go

@@ -1,14 +1,47 @@
 package cp
 
+import (
+	"fmt"
+)
+
 type ID int
 
 type Id interface {
-	Adr(...int) ID
+	Adr(...ID) ID
 }
 
-var adr int = 0
+func (i ID) String() string {
+	if i > 0 {
+		return fmt.Sprint(int(i), "_", getId(i))
+	} else {
+		return fmt.Sprint(int(i))
+	}
+}
 
-func SomeAdr() ID {
-	adr--
-	return ID(adr)
+func Init() {
+	var (
+		fake int        = 0
+		this int        = 0
+		list map[ID]int = make(map[ID]int)
+	)
+	Next = func(id int) ID {
+		if id >= 0 {
+			this++
+			list[ID(this)] = id
+			return ID(this)
+		} else {
+			return ID(id)
+		}
+	}
+	Some = func() int {
+		fake--
+		return fake
+	}
+	getId = func(id ID) int {
+		return list[id]
+	}
 }
+
+var Next func(id int) ID
+var Some func() int
+var getId func(id ID) int

+ 3 - 3
cp/node/class.go

@@ -85,7 +85,7 @@ func New(class constant.Class, id int) (ret Node) {
 	default:
 		panic("no such class")
 	}
-	ret.Adr(id)
+	ret.Adr(cp.Next(id))
 	return ret
 }
 
@@ -95,10 +95,10 @@ type nodeFields struct {
 	adr               cp.ID
 }
 
-func (nf *nodeFields) Adr(a ...int) cp.ID {
+func (nf *nodeFields) Adr(a ...cp.ID) cp.ID {
 	assert.For(len(a) <= 1, 20)
 	if len(a) == 1 {
-		nf.adr = cp.ID(a[0])
+		nf.adr = a[0]
 	}
 	return nf.adr
 }

+ 4 - 4
cp/object/object.go

@@ -64,7 +64,7 @@ type Object interface {
 }
 
 type Ref interface {
-	Adr(...int) cp.ID
+	cp.Id
 }
 
 type VariableObject interface {
@@ -128,7 +128,7 @@ func New(mode Mode, id int) (ret Object) {
 		panic("no such object mode")
 	}
 	ret.Mode(mode)
-	ret.Adr(id)
+	ret.Adr(cp.Next(id))
 	return ret
 }
 
@@ -151,10 +151,10 @@ func (of *objectFields) SetLink(o Object)         { of.link = o }
 func (of *objectFields) SetComplex(t ComplexType) { of.comp = t }
 func (of *objectFields) Complex() ComplexType     { return of.comp }
 
-func (of *objectFields) Adr(a ...int) cp.ID {
+func (of *objectFields) Adr(a ...cp.ID) cp.ID {
 	assert.For(len(a) <= 1, 20)
 	if len(a) == 1 {
-		of.adr = cp.ID(a[0])
+		of.adr = a[0]
 	}
 	return of.adr
 }

+ 7 - 7
cp/object/type.go

@@ -82,10 +82,10 @@ type comp struct {
 func (c *comp) Link() Object     { return c.link }
 func (c *comp) SetLink(o Object) { c.link = o }
 
-func (c *comp) Adr(a ...int) cp.ID {
+func (c *comp) Adr(a ...cp.ID) cp.ID {
 	assert.For(len(a) <= 1, 20)
 	if len(a) == 1 {
-		c.adr = cp.ID(a[0])
+		c.adr = a[0]
 	}
 	return c.adr
 }
@@ -124,7 +124,7 @@ type RecordType interface {
 
 func NewBasicType(t Type, id int) BasicType {
 	x := &basic{typ: t}
-	x.Adr(id)
+	x.Adr(cp.Next(id))
 	return x
 }
 
@@ -143,7 +143,7 @@ func (b *basic) Base(x ...Type) Type {
 
 func NewDynArrayType(b Type, id int) (ret DynArrayType) {
 	ret = &dyn{base: b}
-	ret.Adr(id)
+	ret.Adr(cp.Next(id))
 	return ret
 }
 
@@ -156,7 +156,7 @@ func (d *dyn) Base() Type { return d.base }
 
 func NewArrayType(b Type, len int64, id int) (ret ArrayType) {
 	ret = &arr{base: b, length: len}
-	ret.Adr(id)
+	ret.Adr(cp.Next(id))
 	return ret
 }
 
@@ -190,10 +190,10 @@ func (r *rec) Base() string { return r.base }
 func NewRecordType(n string, id int, par ...string) (ret RecordType) {
 	if len(par) == 0 {
 		ret = &rec{}
-		ret.Adr(id)
+		ret.Adr(cp.Next(id))
 	} else {
 		ret = &rec{name: n, base: par[0]}
-		ret.Adr(id)
+		ret.Adr(cp.Next(id))
 	}
 	return ret
 }

+ 3 - 1
fw.go

@@ -3,6 +3,7 @@ package main
 import (
 	"flag"
 	"fmt"
+	"fw/cp"
 	cpm "fw/cp/module"
 	"fw/rt2/context"
 	"fw/rt2/decision"
@@ -33,9 +34,10 @@ func close() {
 func main() {
 	flag.Parse()
 	if name == "" {
-		name = "Start"
+		name = "Start2"
 		utils.Debug(false)
 	}
+	cp.Init()
 	global := &stdDomain{god: true}
 	global.global = global
 	modList := rtm.New()

+ 2 - 2
rt2/rules/assign.go

@@ -16,7 +16,7 @@ import (
 
 func incSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f)
-	op := node.New(constant.DYADIC, int(cp.SomeAdr())).(node.OperationNode)
+	op := node.New(constant.DYADIC, cp.Some()).(node.OperationNode)
 	op.SetOperation(operation.PLUS)
 	op.SetLeft(n.Left())
 	op.SetRight(n.Right())
@@ -32,7 +32,7 @@ func incSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 
 func decSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f)
-	op := node.New(constant.DYADIC, int(cp.SomeAdr())).(node.OperationNode)
+	op := node.New(constant.DYADIC, cp.Some()).(node.OperationNode)
 	op.SetOperation(operation.MINUS)
 	op.SetLeft(n.Left())
 	op.SetRight(n.Right())

+ 2 - 2
rt2/rules/call.go

@@ -45,11 +45,11 @@ func callHandler(f frame.Frame, obj object.Object, data interface{}) {
 		return
 	}
 	m := rtm.DomainModule(f.Domain())
-	cn := node.New(constant.CALL, int(cp.SomeAdr()))
+	cn := node.New(constant.CALL, cp.Some())
 	ol := m.NodeByObject(obj)
 	assert.For(len(ol) <= 1, 40)
 	cn.SetLeft(ol[0])
-	cc := node.New(constant.CONSTANT, int(cp.SomeAdr())).(node.ConstantNode)
+	cc := node.New(constant.CONSTANT, cp.Some()).(node.ConstantNode)
 	cc.SetData(data)
 	cc.SetType(object.SHORTSTRING)
 	cn.SetRight(cc)

+ 9 - 5
rt2/rules/op.go

@@ -296,14 +296,18 @@ func dopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		case node.CallNode:
 			return This(expectExpr(f, l, Expose(short)))
 		case node.FieldNode:
+			rt2.Push(rt2.New(l), f)
+			rt2.Assert(f, func(f frame.Frame) (bool, int) {
+				return rt2.ValueOf(f)[l.Adr()] != nil, 60
+			})
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
-				sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
-				sc.Select(l.Left().Object().Adr(), func(v scope.Value) {
-					rt2.ValueOf(f)[n.Left().Adr()] = v.(scope.Record).Get(l.Object().Adr())
-				})
+				//sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
+				//sc.Select(l.Left().Object().Adr(), func(v scope.Value) {
+				//	rt2.ValueOf(f)[n.Left().Adr()] = v.(scope.Record).Get(l.Object().Adr())
+				//})
 				return short, frame.NOW
 			}
-			ret = frame.NOW
+			ret = frame.LATER
 			return seq, ret
 		case node.IndexNode:
 			return This(expectExpr(f, n.Left(), Expose(short)))

+ 2 - 2
rt2/rules/trap.go

@@ -10,8 +10,8 @@ import (
 )
 
 func doTrap(f frame.Frame, err traps.TRAP) (frame.Sequence, frame.WAIT) {
-	trap := node.New(constant.TRAP, int(cp.SomeAdr())).(node.TrapNode)
-	code := node.New(constant.CONSTANT, int(cp.SomeAdr())).(node.ConstantNode)
+	trap := node.New(constant.TRAP, cp.Some()).(node.TrapNode)
+	code := node.New(constant.CONSTANT, cp.Some()).(node.ConstantNode)
 	code.SetData(int32(err))
 	trap.SetLeft(code)
 	rt2.Push(rt2.New(trap), f)

+ 4 - 4
rt2/scope/modern/hp.go

@@ -40,11 +40,11 @@ func fin(x interface{}) {
 			if fn != nil {
 				global := p.scope.Domain().Discover(context.UNIVERSE).(context.Domain)
 				root := global.Discover(context.STACK).(frame.Stack)
-				cn := node.New(constant.CALL, int(cp.SomeAdr()))
+				cn := node.New(constant.CALL, cp.Some())
 				ol := mod.NodeByObject(fn)
 				assert.For(len(ol) <= 1, 40)
 				cn.SetLeft(ol[0])
-				cc := node.New(constant.CONSTANT, int(cp.SomeAdr())).(node.ConstantNode)
+				cc := node.New(constant.CONSTANT, cp.Some()).(node.ConstantNode)
 				cc.SetData(p)
 				cc.SetType(object.COMPLEX)
 				cn.SetRight(cc)
@@ -74,7 +74,7 @@ func (h *halloc) Allocate(n node.Node, par ...interface{}) scope.ValueFor {
 	talloc = func(t object.PointerType) {
 		switch bt := t.Base().(type) {
 		case object.RecordType:
-			fake := object.New(object.VARIABLE, int(cp.SomeAdr()))
+			fake := object.New(object.VARIABLE, cp.Some())
 			fake.SetComplex(bt)
 			fake.SetType(object.COMPLEX)
 			fake.SetName("{}")
@@ -82,7 +82,7 @@ func (h *halloc) Allocate(n node.Node, par ...interface{}) scope.ValueFor {
 			res = &ptrValue{scope: h.area, id: fake.Adr(), link: n.Object()}
 		case object.DynArrayType:
 			assert.For(len(par) > 0, 20)
-			fake := object.New(object.VARIABLE, int(cp.SomeAdr()))
+			fake := object.New(object.VARIABLE, cp.Some())
 			fake.SetComplex(bt)
 			fake.SetType(object.COMPLEX)
 			fake.SetName("[]")

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

@@ -475,7 +475,7 @@ func newData(o object.Object) (ret scope.Variable) {
 			if a := ret.(*arr); t.Base() == object.COMPLEX {
 				a.val = make([]interface{}, int(t.Len()))
 				for i := 0; i < int(t.Len()); i++ {
-					fake := object.New(object.VARIABLE, int(cp.SomeAdr()))
+					fake := object.New(object.VARIABLE, cp.Some())
 					fake.SetName("[?]")
 					fake.SetType(object.COMPLEX)
 					fake.SetComplex(t.Complex())
@@ -1401,6 +1401,14 @@ func (o *ops) Eq(a, b scope.Value) scope.Value {
 			return o.Eq(a, vfrom(b))
 		default:
 			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:
 				switch y := b.(type) {
 				case INTEGER: