github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/vm/cvm/ast/ast.go (about) 1 package ast 2 3 import ( 4 "github.com/sixexorg/magnetic-ring/common/sink" 5 ) 6 7 type PositionHolder interface { 8 Line() int 9 SetLine(int) 10 LastLine() int 11 SetLastLine(int) 12 } 13 14 type Node struct { 15 CodeLine int 16 CodeLastline int 17 } 18 19 func (n *Node) Line() int { 20 return n.CodeLine 21 } 22 23 func (n *Node) SetLine(line int) { 24 n.CodeLine = line 25 } 26 27 func (n *Node) LastLine() int { 28 return n.CodeLastline 29 } 30 31 func (n *Node) SetLastLine(line int) { 32 n.CodeLastline = line 33 } 34 35 func Serialize(chunk []Stmt) []byte { 36 sk := sink.NewZeroCopySink(nil) 37 sk.WriteVarUint(uint64(len(chunk))) 38 for _, stmt := range chunk { 39 stmt.Serialization(sk) 40 } 41 return sk.Bytes() 42 } 43 func Deserizlize(data []byte) []Stmt { 44 45 source := sink.NewZeroCopySource(data) 46 length, _, _, _ := source.NextVarUint() 47 chunk := make([]Stmt, length) 48 var i uint64 49 for i = 0; i < length; i++ { 50 chunk[i], _ = StmtDeserialize(source) 51 } 52 return chunk 53 }