Pārlūkot izejas kodu

добавил вызов процедур с выполнением кода в них, область видимости пока глобальная, надо разделять срочно

kpmy 10 gadi atpakaļ
vecāks
revīzija
3118d60ec2
8 mainītis faili ar 66 papildinājumiem un 6 dzēšanām
  1. 14 0
      cp/module/module.go
  2. 5 0
      cp/node/class.go
  3. 0 0
      fw/PrivDemo1.oxf
  4. 6 0
      rt/heap.go
  5. 10 0
      rt/proc.go
  6. 25 1
      rt/seq.go
  7. 1 2
      xev/cmds.go
  8. 5 3
      xev/converter.go

+ 14 - 0
cp/module/module.go

@@ -8,4 +8,18 @@ import (
 type Module struct {
 type Module struct {
 	Enter   node.Node
 	Enter   node.Node
 	Objects []object.Object
 	Objects []object.Object
+	Nodes   []node.Node
+}
+
+func (m *Module) NodeByObject(obj object.Object) (ret node.Node) {
+	if obj == nil {
+		panic("obj must not be nil")
+	}
+	for i := 0; (i < len(m.Nodes)) && (ret == nil); i++ {
+		node := m.Nodes[i]
+		if node.Object() == obj {
+			ret = node
+		}
+	}
+	return ret
 }
 }

+ 5 - 0
cp/node/class.go

@@ -8,6 +8,7 @@ import (
 )
 )
 
 
 type EnterNode interface {
 type EnterNode interface {
+	Enter() enter.Enter
 	SetEnter(enter enter.Enter)
 	SetEnter(enter enter.Enter)
 }
 }
 
 
@@ -51,6 +52,10 @@ func (e *enterNode) SetEnter(enter enter.Enter) {
 	e.enter = enter
 	e.enter = enter
 }
 }
 
 
+func (e *enterNode) Enter() enter.Enter {
+	return e.enter
+}
+
 type constantNode struct {
 type constantNode struct {
 	nodeFields
 	nodeFields
 	typ  object.Type
 	typ  object.Type

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
fw/PrivDemo1.oxf


+ 6 - 0
rt/heap.go

@@ -3,6 +3,7 @@ package rt
 import (
 import (
 	"cp/object"
 	"cp/object"
 	"fmt"
 	"fmt"
+	"reflect"
 )
 )
 
 
 type INTEGER int
 type INTEGER int
@@ -18,7 +19,12 @@ func (i *INTEGER) Set(val interface{}) {
 	switch val.(type) {
 	switch val.(type) {
 	case int:
 	case int:
 		*i = INTEGER(val.(int))
 		*i = INTEGER(val.(int))
+	case INTEGER:
+		*i = val.(INTEGER)
+	case *INTEGER:
+		*i = *val.(*INTEGER)
 	default:
 	default:
+		fmt.Print(reflect.TypeOf(val), " ")
 		panic("wrong type for INTEGER")
 		panic("wrong type for INTEGER")
 	}
 	}
 	fmt.Println("set", int(*i))
 	fmt.Println("set", int(*i))

+ 10 - 0
rt/proc.go

@@ -1,10 +1,12 @@
 package rt
 package rt
 
 
 import (
 import (
+	"cp/constant/enter"
 	"cp/module"
 	"cp/module"
 	"cp/node"
 	"cp/node"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
+	"reflect"
 )
 )
 
 
 type Result int
 type Result int
@@ -53,7 +55,15 @@ func (f *frame) OnPush() {
 		f.seq = new(opSeq)
 		f.seq = new(opSeq)
 	case node.CallNode:
 	case node.CallNode:
 		f.seq = new(callSeq)
 		f.seq = new(callSeq)
+	case node.EnterNode:
+		if f.ir.(node.EnterNode).Enter() == enter.PROCEDURE {
+			fmt.Println("proc")
+		} else {
+			panic("cannot enter to module")
+		}
+		f.seq = new(enterSeq)
 	default:
 	default:
+		fmt.Println(reflect.TypeOf(f.ir))
 		panic("unknown ir")
 		panic("unknown ir")
 	}
 	}
 }
 }

+ 25 - 1
rt/seq.go

@@ -36,6 +36,11 @@ func (s *assignSeq) Do(f *frame) (ret Wait) {
 						return STOP
 						return STOP
 					}
 					}
 					return SKIP
 					return SKIP
+				case node.VariableNode:
+					a := f.p.heap.This(f.ir.Right().Object())
+					b := f.p.heap.This(f.ret[f.ir.Left()].(object.Object))
+					b.Set(a)
+					return STOP
 				default:
 				default:
 					panic("wrong right")
 					panic("wrong right")
 				}
 				}
@@ -127,10 +132,12 @@ func (s *callSeq) Do(f *frame) Wait {
 	if s.step == nil {
 	if s.step == nil {
 		switch f.ir.Left().(type) {
 		switch f.ir.Left().(type) {
 		case node.ProcedureNode:
 		case node.ProcedureNode:
+			proc := f.p.thisMod.NodeByObject(f.ir.Left().Object())
+			f.push(NewFrame(f.p, proc).(*frame))
 			s.step = func() Wait {
 			s.step = func() Wait {
 				return STOP
 				return STOP
 			}
 			}
-			return DO
+			return SKIP
 		default:
 		default:
 			panic("unknown call left")
 			panic("unknown call left")
 		}
 		}
@@ -138,3 +145,20 @@ func (s *callSeq) Do(f *frame) Wait {
 		return s.step()
 		return s.step()
 	}
 	}
 }
 }
+
+type enterSeq struct {
+	step func() Wait
+}
+
+func (e *enterSeq) Do(f *frame) Wait {
+	if e.step == nil {
+		//for f.ir == EnterNode entering to .Right()
+		f.push(NewFrame(f.p, f.ir.Right()).(*frame))
+		e.step = func() Wait {
+			return STOP
+		}
+		return SKIP
+	} else {
+		return e.step()
+	}
+}

+ 1 - 2
xev/cmds.go

@@ -14,8 +14,7 @@ func Load(path, name string) (ret *module.Module) {
 	fmt.Println(len(data))
 	fmt.Println(len(data))
 	if data != nil {
 	if data != nil {
 		result := LoadOXF(data)
 		result := LoadOXF(data)
-		ret = new(module.Module)
-		ret.Enter, ret.Objects = DoAST(result)
+		ret = DoAST(result)
 	}
 	}
 	return ret
 	return ret
 }
 }

+ 5 - 3
xev/converter.go

@@ -4,6 +4,7 @@ import (
 	"cp/constant"
 	"cp/constant"
 	"cp/constant/enter"
 	"cp/constant/enter"
 	"cp/constant/operation"
 	"cp/constant/operation"
+	"cp/module"
 	"cp/node"
 	"cp/node"
 	"cp/object"
 	"cp/object"
 	"cp/statement"
 	"cp/statement"
@@ -197,12 +198,13 @@ func buildMod(r *Result) (nodeList []node.Node, objList []object.Object, root no
 	return nodeList, objList, root
 	return nodeList, objList, root
 }
 }
 
 
-func DoAST(r *Result) (ent node.Node, obj []object.Object) {
+func DoAST(r *Result) (mod *module.Module) {
 	nodeMap = make(map[string]node.Node)
 	nodeMap = make(map[string]node.Node)
 	objectMap = make(map[string]object.Object)
 	objectMap = make(map[string]object.Object)
-	_, obj, ent = buildMod(r)
+	mod = new(module.Module)
+	mod.Nodes, mod.Objects, mod.Enter = buildMod(r)
 	fmt.Println(len(nodeMap), len(objectMap))
 	fmt.Println(len(nodeMap), len(objectMap))
 	nodeMap = nil
 	nodeMap = nil
 	objectMap = nil
 	objectMap = nil
-	return ent, obj
+	return mod
 }
 }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels