Ver Fonte

поддержка COMPOUND

kpmy há 10 anos atrás
pai
commit
4af7d69828

BIN
code/PrivDemo18.oz


BIN
code/XevDemo1.oz


BIN
code/XevDemo11.oz


BIN
code/XevDemo12.oz


BIN
code/XevDemo14.oz


BIN
code/XevDemo15.oz


BIN
code/XevDemo16.oz


BIN
code/XevDemo17.oz


BIN
code/XevDemo18.oz


BIN
code/XevDemo4.oz


BIN
code/XevDemo5.oz


BIN
code/XevDemo6.oz


BIN
code/XevDemo7.oz


BIN
code/XevDemo8.oz


+ 22 - 0
cp/node/class.go

@@ -9,12 +9,18 @@ import (
 )
 
 const INIT constant.Class = -1
+const COMPOUND constant.Class = -2
 
 type InitNode interface {
 	Node
 	self() InitNode
 }
 
+type CompNode interface {
+	Node
+	self() CompNode
+}
+
 func New(class constant.Class) Node {
 	switch class {
 	case constant.ENTER:
@@ -71,6 +77,8 @@ func New(class constant.Class) Node {
 		return new(doNode)
 	case constant.RANGE:
 		return new(rangeNode)
+	case COMPOUND:
+		return new(compNode)
 	default:
 		panic("no such class")
 	}
@@ -230,10 +238,18 @@ func (v *loopNode) self() LoopNode { return v }
 
 type derefNode struct {
 	nodeFields
+	ptr bool
 }
 
 func (v *derefNode) self() DerefNode { return v }
 
+func (c *derefNode) Ptr(x ...string) bool {
+	if len(x) > 0 {
+		c.ptr = x[0] == "ptr"
+	}
+	return c.ptr
+}
+
 type fieldNode struct {
 	nodeFields
 }
@@ -246,6 +262,12 @@ type initNode struct {
 
 func (v *initNode) self() InitNode { return v }
 
+type compNode struct {
+	nodeFields
+}
+
+func (v *compNode) self() CompNode { return v }
+
 type indexNode struct {
 	nodeFields
 }

+ 1 - 0
cp/node/node.go

@@ -121,6 +121,7 @@ type LoopNode interface {
 type DerefNode interface {
 	self() DerefNode
 	Node
+	Ptr(...string) bool
 }
 
 type FieldNode interface {

+ 1 - 1
fw.go

@@ -26,7 +26,7 @@ func close() {
 func main() {
 	flag.Parse()
 	if name == "" {
-		name = "XevDemo17"
+		name = "XevDemo18"
 	}
 	global := new(stdDomain)
 	modList := module.New()

+ 1 - 1
rt2/rules/assign.go

@@ -77,7 +77,7 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				return frame.End()
 			}
 			ret = frame.NOW
-		case node.OperationNode, node.CallNode:
+		case node.OperationNode, node.CallNode, node.DerefNode:
 			fu.Push(fu.New(a.Right()), f)
 			seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				sc := f.Domain().Discover(context.SCOPE).(scope.Manager)

+ 4 - 4
rt2/rules/call.go

@@ -9,7 +9,7 @@ import (
 	"fw/rt2"
 	"fw/rt2/context"
 	"fw/rt2/frame"
-	mod "fw/rt2/module"
+	rt_mod "fw/rt2/module"
 	"fw/rt2/nodeframe"
 	"fw/rt2/scope"
 	"ypk/assert"
@@ -37,7 +37,7 @@ func callHandler(f frame.Frame, obj object.Object, data interface{}) {
 	if obj == nil {
 		return
 	}
-	m := mod.DomainModule(f.Domain())
+	m := rt_mod.DomainModule(f.Domain())
 	cn := node.New(constant.CALL)
 	cn.SetLeft(m.NodeByObject(obj))
 	cc := node.New(constant.CONSTANT).(node.ConstantNode)
@@ -101,11 +101,11 @@ func callSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 
 	switch n.Left().(type) {
 	case node.ProcedureNode:
-		m := mod.DomainModule(f.Domain())
+		m := rt_mod.DomainModule(f.Domain())
 		proc := m.NodeByObject(n.Left().Object())
 		call(proc)
 	case node.VariableNode:
-		m := mod.DomainModule(f.Domain())
+		m := rt_mod.DomainModule(f.Domain())
 		sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 		obj := sc.Select(scope.Designator(n.Left()))
 

+ 3 - 0
rt2/rules/deref.go

@@ -1,6 +1,8 @@
 package rules
 
 import (
+	"fmt"
+	"fw/cp/node"
 	"fw/rt2"
 	"fw/rt2/context"
 	"fw/rt2/frame"
@@ -13,6 +15,7 @@ func derefSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 	data := sc.Select(scope.Designator(n.Left()))
 	assert.For(data != nil, 40)
+	fmt.Println("deref from ptr", n.(node.DerefNode).Ptr())
 	rt2.DataOf(f.Parent())[n] = data
 	return frame.End()
 }

+ 124 - 0
rt2/rules/op.go

@@ -40,6 +40,22 @@ func int32Of(x interface{}) (a int32) {
 		a = x.(int32)
 	case *big.Int:
 		a = int32(v.Int64())
+	default:
+		//panic(fmt.Sprintln("unsupported type", reflect.TypeOf(x)))
+	}
+	return a
+}
+
+func float64Of(x interface{}) (a float64) {
+	//fmt.Println(reflect.TypeOf(x))
+	switch v := x.(type) {
+	case *int32:
+		z := *x.(*int32)
+		a = float64(z)
+	case int32:
+		a = float64(x.(int32))
+	case float64:
+		a = v
 	default:
 		panic(fmt.Sprintln("unsupported type", reflect.TypeOf(x)))
 	}
@@ -62,6 +78,55 @@ func max(_a interface{}, _b interface{}) interface{} {
 	return int32(math.Max(float64(a), float64(b)))
 }
 
+func div(_a interface{}, _b interface{}) interface{} {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a int32 = int32Of(_a)
+	var b int32 = int32Of(_b)
+	return a / b
+}
+
+func mod(_a interface{}, _b interface{}) interface{} {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a int32 = int32Of(_a)
+	var b int32 = int32Of(_b)
+	return a % b
+}
+
+func times(_a interface{}, _b interface{}) interface{} {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a int32 = int32Of(_a)
+	var b int32 = int32Of(_b)
+	return a * b
+}
+
+func slash(_a interface{}, _b interface{}) interface{} {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a float64 = float64Of(_a)
+	var b float64 = float64Of(_b)
+	return a / b
+}
+
+func ash(_a interface{}, _b interface{}) interface{} {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a int32 = int32Of(_a)
+	var b int32 = int32Of(_b)
+	return a << uint(b)
+}
+
+func in(_a interface{}, _b interface{}) bool {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a int32 = int32Of(_a)
+	var b int32 = int32Of(_b)
+	fmt.Println("операция IN все врет")
+	return a == b
+}
+
 func sum(_a interface{}, _b interface{}) interface{} {
 	assert.For(_a != nil, 20)
 	assert.For(_b != nil, 21)
@@ -86,6 +151,22 @@ func eq(_a interface{}, _b interface{}) bool {
 	return a == b
 }
 
+func and(_a interface{}, _b interface{}) bool {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a bool = boolOf(_a)
+	var b bool = boolOf(_b)
+	return a && b
+}
+
+func or(_a interface{}, _b interface{}) bool {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a bool = boolOf(_a)
+	var b bool = boolOf(_b)
+	return a || b
+}
+
 func lss(_a interface{}, _b interface{}) bool {
 	assert.For(_a != nil, 20)
 	assert.For(_b != nil, 21)
@@ -101,6 +182,15 @@ func gtr(_a interface{}, _b interface{}) bool {
 	var b int32 = int32Of(_b)
 	return a > b
 }
+
+func geq(_a interface{}, _b interface{}) bool {
+	assert.For(_a != nil, 20)
+	assert.For(_b != nil, 21)
+	var a int32 = int32Of(_a)
+	var b int32 = int32Of(_b)
+	return a >= b
+}
+
 func leq(_a interface{}, _b interface{}) bool {
 	assert.For(_a != nil, 20)
 	assert.For(_b != nil, 21)
@@ -257,6 +347,13 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 				default:
 					panic(fmt.Sprintln("ooops", reflect.TypeOf(x)))
 				}
+			case object.REAL:
+				switch v := x.(type) {
+				case int32:
+					fu.DataOf(f.Parent())[n] = float64(v)
+				default:
+					panic(fmt.Sprintln("ooops", reflect.TypeOf(x)))
+				}
 			default:
 				panic(fmt.Sprintln("wrong type", n.Type()))
 			}
@@ -351,6 +448,33 @@ func dopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		case operation.MIN:
 			fu.DataOf(f.Parent())[n] = min(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
 			return frame.End()
+		case operation.DIV:
+			fu.DataOf(f.Parent())[n] = div(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.MOD:
+			fu.DataOf(f.Parent())[n] = mod(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.TIMES:
+			fu.DataOf(f.Parent())[n] = times(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.SLASH:
+			fu.DataOf(f.Parent())[n] = slash(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.IN:
+			fu.DataOf(f.Parent())[n] = in(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.ASH:
+			fu.DataOf(f.Parent())[n] = ash(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.AND:
+			fu.DataOf(f.Parent())[n] = and(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.OR:
+			fu.DataOf(f.Parent())[n] = or(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
+		case operation.GREAT_EQUAL:
+			fu.DataOf(f.Parent())[n] = geq(fu.DataOf(f)[n.Left()], fu.DataOf(f)[n.Right()])
+			return frame.End()
 		default:
 			panic(fmt.Sprintln("unknown operation", n.(node.OperationNode).Operation()))
 		}

+ 20 - 1
rt2/rules/table.go

@@ -4,6 +4,7 @@ package rules
 import (
 	"fmt"
 	"fw/cp/node"
+	"fw/rt2"
 	"fw/rt2/context"
 	"fw/rt2/decision"
 	"fw/rt2/frame"
@@ -69,6 +70,24 @@ func prologue(n node.Node) frame.Sequence {
 		return caseSeq
 	case node.RangeNode:
 		return rangeSeq
+	case node.CompNode:
+		return func(f frame.Frame) (frame.Sequence, frame.WAIT) {
+			right := func(f frame.Frame) (frame.Sequence, frame.WAIT) {
+				if next.Right() != nil {
+					rt2.Push(rt2.New(next.Right()), f)
+					return frame.Tail(frame.STOP), frame.LATER
+				}
+				return frame.End()
+			}
+			left := func(f frame.Frame) (frame.Sequence, frame.WAIT) {
+				if next.Left() != nil {
+					rt2.Push(rt2.New(next.Left()), f)
+					return right, frame.LATER
+				}
+				return right, frame.NOW
+			}
+			return left, frame.NOW
+		}
 	default:
 		panic(fmt.Sprintln("unknown node", reflect.TypeOf(n)))
 	}
@@ -78,7 +97,7 @@ func epilogue(n node.Node) frame.Sequence {
 	var fu nodeframe.FrameUtils
 	switch n.(type) {
 	case node.AssignNode, node.InitNode, node.CallNode, node.ConditionalNode, node.WhileNode,
-		node.RepeatNode, node.ExitNode, node.WithNode, node.CaseNode:
+		node.RepeatNode, node.ExitNode, node.WithNode, node.CaseNode, node.CompNode:
 		return func(f frame.Frame) (frame.Sequence, frame.WAIT) {
 			next := n.Link()
 			//fmt.Println("from", reflect.TypeOf(n))

+ 9 - 0
rt2/scope/std/scope.go

@@ -9,6 +9,7 @@ import (
 	rt_mod "fw/rt2/module"
 	"fw/rt2/scope"
 	"reflect"
+	"runtime"
 	"ypk/assert"
 )
 
@@ -28,6 +29,10 @@ type area struct {
 	ready bool
 }
 
+func area_fin(a interface{}) {
+	fmt.Println("scope cleared")
+}
+
 func (a *area) set(k scope.ID, v interface{}) {
 	key := scope.ID{Name: k.Name}
 	a.x[key] = v
@@ -192,6 +197,7 @@ func obj(o object.Object) (key scope.ID, val interface{}) {
 
 func (m *manager) Allocate(n node.Node, final bool) {
 	h := &area{ready: final, root: n, x: make(map[scope.ID]interface{})}
+	runtime.SetFinalizer(h, area_fin)
 	mod := rt_mod.DomainModule(m.Domain())
 	var alloc func(h KVarea, o object.Object)
 	alloc = func(h KVarea, o object.Object) {
@@ -337,6 +343,9 @@ func arrConv(x interface{}) []interface{} {
 		return ret
 	case []interface{}:
 		return a
+	case int32:
+		fmt.Println("not an array")
+		return []interface{}{rune(0)}
 	default:
 		panic(fmt.Sprintln("unsupported", reflect.TypeOf(x)))
 	}

+ 3 - 0
xev/converter.go

@@ -384,6 +384,7 @@ func (r *Result) buildNode(n *Node) (ret node.Node) {
 			ret = node.New(constant.EXIT)
 		case "dereferencing":
 			ret = node.New(constant.DEREF)
+			ret.(node.DerefNode).Ptr(n.Data.Nod.From)
 		case "field":
 			ret = node.New(constant.FIELD)
 		case "init":
@@ -420,6 +421,8 @@ func (r *Result) buildNode(n *Node) (ret node.Node) {
 			ret = node.New(constant.DO)
 		case "range":
 			ret = node.New(constant.RANGE)
+		case "compound":
+			ret = node.New(node.COMPOUND)
 		default:
 			fmt.Println(n.Data.Nod.Class)
 			panic("no such node type")