Przeglądaj źródła

отладил форматтер json, теперь можно генерить json легко

kpmy 10 lat temu
rodzic
commit
4bbc4d3c2e

BIN
code/Cons.oz


BIN
code/Console.oz


BIN
code/JSonFormatter.oz


BIN
code/JSonGenerator.oz


BIN
code/JSonObxNoModel.oz


BIN
code/Mathe.oz


BIN
code/Out.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


+ 3 - 3
fw.go

@@ -2,7 +2,6 @@ package main
 
 import (
 	"flag"
-	"fmt"
 	"fw/cp"
 	cpm "fw/cp/module"
 	"fw/rt2/context"
@@ -12,6 +11,7 @@ import (
 	"fw/rt2/scope"
 	_ "fw/rt2/scope/modern"
 	"fw/utils"
+	"log"
 	"time"
 	"ypk/assert"
 )
@@ -27,7 +27,7 @@ func close() {
 	utils.PrintFrame("____")
 	utils.PrintFrame(heap)
 	utils.PrintFrame("^^^^")
-	fmt.Println("closed")
+	log.Println("closed")
 	//fmt.Println(heap)
 }
 
@@ -50,7 +50,7 @@ func main() {
 		init = append(init, m)
 	})
 	t1 := time.Now()
-	fmt.Println("load", t1.Sub(t0))
+	log.Println("load", t1.Sub(t0))
 	assert.For(err == nil, 40)
 	defer close()
 	decision.Run(global, init)

+ 16 - 12
rt2/rules/assign.go

@@ -15,23 +15,27 @@ import (
 	"ypk/halt"
 )
 
-func incSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
+func inc_dec_seq(f frame.Frame, code operation.Operation) (seq frame.Sequence, ret frame.WAIT) {
 	n := rt2.NodeOf(f)
+	a := node.New(constant.ASSIGN, cp.Some()).(node.AssignNode)
+	a.SetStatement(statement.ASSIGN)
+	a.SetLeft(n.Left())
 	op := node.New(constant.DYADIC, cp.Some()).(node.OperationNode)
-	op.SetOperation(operation.PLUS)
+	op.SetOperation(code)
 	op.SetLeft(n.Left())
 	op.SetRight(n.Right())
-	rt2.Push(rt2.New(op), f)
-	seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
+	a.SetRight(op)
+	rt2.Push(rt2.New(a), f)
+	/*seq = func(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		sc := f.Domain().Discover(context.SCOPE).(scope.Manager)
 		sc.Update(n.Left().Object().Adr(), scope.Simple(rt2.ValueOf(f)[op.Adr()]))
 		return frame.End()
 	}
-	ret = frame.LATER
-	return seq, ret
+	ret = frame.LATER */
+	return frame.Tail(frame.STOP), frame.LATER
 }
 
-func decSeq(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, cp.Some()).(node.OperationNode)
 	op.SetOperation(operation.MINUS)
@@ -46,7 +50,7 @@ func decSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	ret = frame.LATER
 	return seq, ret
 }
-
+*/
 func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 	a := rt2.NodeOf(f)
 
@@ -186,15 +190,15 @@ func assignSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 		}
 	case statement.INC, statement.INCL:
 		switch a.Left().(type) {
-		case node.VariableNode, node.ParameterNode:
-			seq, ret = incSeq(f)
+		case node.VariableNode, node.ParameterNode, node.FieldNode:
+			seq, ret = inc_dec_seq(f, operation.PLUS)
 		default:
 			panic(fmt.Sprintln("wrong left", reflect.TypeOf(a.Left())))
 		}
 	case statement.DEC, statement.EXCL:
 		switch a.Left().(type) {
-		case node.VariableNode, node.ParameterNode:
-			seq, ret = decSeq(f)
+		case node.VariableNode, node.ParameterNode, node.FieldNode:
+			seq, ret = inc_dec_seq(f, operation.MINUS)
 		default:
 			panic(fmt.Sprintln("wrong left", reflect.TypeOf(a.Left())))
 		}

+ 6 - 6
rt2/rules/case.go

@@ -16,7 +16,7 @@ func caseSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 
 	in := func(in ...IN) (out OUT) {
 		cond := n.Right().(node.ElseNode)
-		fmt.Println("case?", e, cond.Min(), cond.Max())
+		//fmt.Println("case?", e, cond.Min(), cond.Max())
 		if e < cond.Min() || e > cond.Max() { //case?
 			if cond.Right() != nil {
 				rt2.Push(rt2.New(cond.Right()), f)
@@ -29,16 +29,16 @@ func caseSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 				//				_c := next.Left()
 				for _c := next.Left(); _c != nil && !ok; _c = _c.Link() {
 					c := _c.(node.ConstantNode)
-					fmt.Println("const", c.Data(), c.Min(), c.Max())
+					//fmt.Println("const", c.Data(), c.Min(), c.Max())
 					if (c.Min() != nil) && (c.Max() != nil) {
-						fmt.Println(e, *c.Max(), "..", *c.Min())
+						//fmt.Println(e, *c.Max(), "..", *c.Min())
 						ok = e >= *c.Min() && e <= *c.Max()
 					} else {
-						fmt.Println(e, c.Data())
+						//fmt.Println(e, c.Data())
 						ok = int32Of(c.Data()) == int32(e)
 					}
 				}
-				fmt.Println(ok)
+				//fmt.Println(ok)
 				if ok {
 					rt2.Push(rt2.New(next.Right()), f)
 					out.do = Tail(STOP)
@@ -62,7 +62,7 @@ func caseSeq(f frame.Frame) (frame.Sequence, frame.WAIT) {
 			panic("nil")
 		case int32:
 			e = int(x)
-			fmt.Println("case", e)
+			//fmt.Println("case", e)
 			out.do = in
 			out.next = NOW
 			return out

+ 1 - 1
rt2/rules/op.go

@@ -79,7 +79,7 @@ func mopSeq(f frame.Frame) (seq frame.Sequence, ret frame.WAIT) {
 			assert.For(x != nil, 40)
 			conv(scope.ValueFrom(x))
 			return frame.End()
-		case node.OperationNode, node.DerefNode, node.CallNode:
+		case node.OperationNode, node.DerefNode, node.CallNode, node.IndexNode:
 			return This(expectExpr(f, n.Left(), func(...IN) OUT {
 				conv(rt2.ValueOf(f)[n.Left().Adr()])
 				return End()

+ 3 - 2
rt2/rules/table.go

@@ -14,6 +14,7 @@ import (
 	"fw/rt2/frame/std"
 	"fw/rt2/scope"
 	"fw/utils"
+	"log"
 	"reflect"
 	"time"
 	"ypk/assert"
@@ -257,8 +258,8 @@ func run(global context.Domain, init []*module.Module) {
 			i++
 		}
 		t1 := time.Now()
-		fmt.Println("total steps", i)
-		fmt.Println("spent", t1.Sub(t0))
+		log.Println("total steps", i)
+		log.Println("spent", t1.Sub(t0))
 	}
 }
 

+ 42 - 7
rt2/scope/modern/val.go

@@ -63,6 +63,17 @@ func (i *idx) link() object.Object {
 	}
 }
 
+func (i *idx) base() (object.Type, object.ComplexType) {
+	switch a := i.link().Complex().(type) {
+	case object.ArrayType:
+		return a.Base(), a.Complex()
+	case object.DynArrayType:
+		return a.Base(), nil
+	default:
+		panic(0)
+	}
+}
+
 func (i *idx) val() []interface{} {
 	switch a := i.some.(type) {
 	case *arr:
@@ -145,17 +156,23 @@ func (a *dynarr) Set(v scope.Value) {
 		a.Set(x.Get())
 	case STRING:
 		z := []rune(string(x))
-		v := make([]interface{}, len(z))
+		v := make([]interface{}, len(z)+1)
 		for i := 0; i < len(z); i++ {
 			v[i] = CHAR(z[i])
 		}
+		if len(v) > 1 {
+			v[len(v)-1] = CHAR(0)
+		}
 		a.val = v
 	case SHORTSTRING:
 		z := []rune(string(x))
-		v := make([]interface{}, len(z))
+		v := make([]interface{}, len(z)+1)
 		for i := 0; i < len(z); i++ {
 			v[i] = SHORTCHAR(z[i])
 		}
+		if len(v) > 0 {
+			v[len(v)-1] = SHORTCHAR(0)
+		}
 		a.val = v
 	case INTEGER:
 		a.val = make([]interface{}, int(x))
@@ -733,6 +750,8 @@ func gfrom(v scope.Value) interface{} {
 		return bool(n)
 	case STRING:
 		return string(n)
+	case CHAR:
+		return rune(n)
 	default:
 		halt.As(100, reflect.TypeOf(n))
 	}
@@ -1310,7 +1329,10 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
 	case object.INTEGER:
 		switch x := a.(type) {
 		case *data:
-			return o.Conv(vfrom(x), typ)
+			return o.Conv(vfrom(x), typ, comp...)
+		case *idx:
+			//t, c := x.base()
+			return o.Conv(x.val()[x.idx].(scope.Value), typ, comp...)
 		case BYTE:
 			return INTEGER(x)
 		case SET:
@@ -1319,13 +1341,15 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
 			return INTEGER(x)
 		case LONGINT:
 			return INTEGER(x)
+		case CHAR:
+			return INTEGER(x)
 		default:
 			halt.As(100, reflect.TypeOf(x))
 		}
 	case object.LONGINT:
 		switch x := a.(type) {
 		case *data:
-			return o.Conv(vfrom(x), typ)
+			return o.Conv(vfrom(x), typ, comp...)
 		case INTEGER:
 			return LONGINT(x)
 		case REAL:
@@ -1336,7 +1360,7 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
 	case object.SET:
 		switch x := a.(type) {
 		case *data:
-			return o.Conv(vfrom(x), typ)
+			return o.Conv(vfrom(x), typ, comp...)
 		case INTEGER:
 			return SET{bits: big.NewInt(int64(x))}
 		default:
@@ -1345,7 +1369,7 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
 	case object.REAL:
 		switch x := a.(type) {
 		case *data:
-			return o.Conv(vfrom(x), typ)
+			return o.Conv(vfrom(x), typ, comp...)
 		case INTEGER:
 			return REAL(float64(x))
 		default:
@@ -1354,11 +1378,13 @@ func (o *ops) Conv(a scope.Value, typ object.Type, comp ...object.ComplexType) s
 	case object.CHAR:
 		switch x := a.(type) {
 		case *data:
-			return o.Conv(vfrom(x), typ)
+			return o.Conv(vfrom(x), typ, comp...)
 		case LONGINT:
 			return CHAR(rune(x))
 		case INTEGER:
 			return CHAR(rune(x))
+		case CHAR:
+			return x
 		default:
 			halt.As(100, reflect.TypeOf(x))
 		}
@@ -1608,6 +1634,15 @@ func (o *ops) Lss(a, b scope.Value) scope.Value {
 				default:
 					panic(fmt.Sprintln(reflect.TypeOf(y)))
 				}
+			case CHAR:
+				switch y := b.(type) {
+				case CHAR:
+					return BOOLEAN(x < y)
+				case INTEGER:
+					return BOOLEAN(uint(x) < uint(y))
+				default:
+					panic(fmt.Sprintln(reflect.TypeOf(y)))
+				}
 			default:
 				panic(fmt.Sprintln(reflect.TypeOf(x)))
 			}

+ 2 - 2
xev/cmds.go

@@ -2,9 +2,9 @@ package xev
 
 import (
 	"archive/zip"
-	"fmt"
 	"fw/cp/module"
 	"io"
+	"log"
 	"path/filepath"
 	"ypk/assert"
 )
@@ -12,7 +12,7 @@ import (
 const CODE = "code"
 
 func Load(path, name string) (ret *module.Module) {
-	fmt.Println(path + ` ` + name)
+	log.Println(path + ` ` + name)
 	//var data []byte
 	var rd io.Reader
 	r, err := zip.OpenReader(filepath.Join(path, CODE, name))