Sfoglia il codice sorgente

добавил сущность модуля, сменил компилятор go на версию 1.4, ничего не сломалось

kpmy 10 anni fa
parent
commit
bc6c2c9185
5 ha cambiato i file con 33 aggiunte e 14 eliminazioni
  1. 11 0
      cp/module/module.go
  2. 6 3
      fw/fw.go
  3. 9 5
      rt/proc.go
  4. 4 3
      xev/cmds.go
  5. 3 3
      xev/converter.go

+ 11 - 0
cp/module/module.go

@@ -0,0 +1,11 @@
+package module
+
+import (
+	"cp/node"
+	"cp/object"
+)
+
+type Module struct {
+	Enter   node.Node
+	Objects []object.Object
+}

+ 6 - 3
fw/fw.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"fmt"
 	"os"
 	"rt"
 	"xev"
@@ -12,13 +11,17 @@ func main() {
 	ret := xev.Load(path, "PrivDemo1.oxf")
 	if ret != nil {
 		p := rt.NewProcessor()
-		p.ConnectTo(ret)
+		err := p.ConnectTo(ret)
+		if err != nil {
+			panic("not connected")
+		}
 		for {
 			res, _ := p.Do()
 			if res != rt.OK {
 				break
 			}
 		}
-		fmt.Println("")
+	} else {
+		panic("no module")
 	}
 }

+ 9 - 5
rt/proc.go

@@ -1,6 +1,7 @@
 package rt
 
 import (
+	"cp/module"
 	"cp/node"
 	"errors"
 	"fmt"
@@ -15,7 +16,7 @@ const (
 )
 
 type Processor interface {
-	ConnectTo(head node.Node) error
+	ConnectTo(mod *module.Module) error
 	Do() (Result, error)
 }
 
@@ -85,9 +86,10 @@ func NewFrame(p *procImpl, ir node.Node) Frame {
 }
 
 type procImpl struct {
-	stack Stack
-	heap  Heap
-	cycle int64
+	stack   Stack
+	heap    Heap
+	cycle   int64
+	thisMod *module.Module
 }
 
 func (p *procImpl) Init() *procImpl {
@@ -96,7 +98,9 @@ func (p *procImpl) Init() *procImpl {
 	return p
 }
 
-func (p *procImpl) ConnectTo(head node.Node) (err error) {
+func (p *procImpl) ConnectTo(mod *module.Module) (err error) {
+	p.thisMod = mod
+	head := p.thisMod.Enter
 	if head != nil {
 		switch head.(type) {
 		// особый случай, после enter вправо, а не вниз

+ 4 - 3
xev/cmds.go

@@ -1,20 +1,21 @@
 package xev
 
 import (
-	"cp/node"
+	"cp/module"
 	"fmt"
 	"io/ioutil"
 	"path/filepath"
 )
 
-func Load(path, name string) (ret node.Node) {
+func Load(path, name string) (ret *module.Module) {
 	fmt.Println(path + ` ` + name)
 	var data []byte
 	data, _ = ioutil.ReadFile(filepath.Join(path, name))
 	fmt.Println(len(data))
 	if data != nil {
 		result := LoadOXF(data)
-		ret = DoAST(result)
+		ret = new(module.Module)
+		ret.Enter, ret.Objects = DoAST(result)
 	}
 	return ret
 }

+ 3 - 3
xev/converter.go

@@ -197,12 +197,12 @@ func buildMod(r *Result) (nodeList []node.Node, objList []object.Object, root no
 	return nodeList, objList, root
 }
 
-func DoAST(r *Result) (ret node.Node) {
+func DoAST(r *Result) (ent node.Node, obj []object.Object) {
 	nodeMap = make(map[string]node.Node)
 	objectMap = make(map[string]object.Object)
-	_, _, ret = buildMod(r)
+	_, obj, ent = buildMod(r)
 	fmt.Println(len(nodeMap), len(objectMap))
 	nodeMap = nil
 	objectMap = nil
-	return ret
+	return ent, obj
 }