This repository was archived by the owner on Oct 3, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package compiler
22
33import (
4+ "encoding/gob"
45 "github.com/looplanguage/compiler/code"
56 "github.com/looplanguage/loop/models/object"
67)
@@ -179,3 +180,9 @@ type Bytecode struct {
179180 Instructions code.Instructions
180181 Constants []object.Object
181182}
183+
184+ func RegisterGobTypes () {
185+ gob .Register (& object.String {})
186+ gob .Register (& object.Integer {})
187+ gob .Register (& object.CompiledFunction {})
188+ }
Original file line number Diff line number Diff line change @@ -48,12 +48,18 @@ func main() {
4848 log .Fatalln (err )
4949 }
5050
51- var compiled bytes2.Buffer
52- enc := gob .NewEncoder (& compiled )
51+ compiler .RegisterGobTypes ()
5352
54- enc . Encode ( comp . Bytecode ())
53+ var constantBytes bytes2. Buffer
5554
56- ioutil .WriteFile (filepath .Dir (os .Args [1 ])+ "/" + fileNameWithoutExtension (filepath .Base (os .Args [1 ]))+ ".lpx" , compiled .Bytes (), 0644 )
55+ enc := gob .NewEncoder (& constantBytes )
56+ err = enc .Encode (comp .Bytecode ())
57+
58+ if err != nil {
59+ log .Fatal (err )
60+ }
61+
62+ ioutil .WriteFile (filepath .Dir (os .Args [1 ])+ "/" + fileNameWithoutExtension (filepath .Base (os .Args [1 ]))+ ".lpx" , constantBytes .Bytes (), 0644 )
5763}
5864
5965func fileNameWithoutExtension (fileName string ) string {
You can’t perform that action at this time.
0 commit comments