CodeGen is the function that compiles the program to bytecode and data.
(name string, n ast.Node)
| 34 | |
| 35 | // CodeGen is the function that compiles the program to bytecode and data. |
| 36 | func CodeGen(name string, n ast.Node) (*code.Object, error) { |
| 37 | c := &codegen{name: name} |
| 38 | _ = ast.Walk(c, n) |
| 39 | c.writeJumps() |
| 40 | if len(c.errors) > 0 { |
| 41 | return nil, c.errors |
| 42 | } |
| 43 | return &c.obj, nil |
| 44 | } |
| 45 | |
| 46 | func (c *codegen) errorf(pos *position.Position, format string, args ...interface{}) { |
| 47 | e := "Internal compiler error, aborting compilation: " + fmt.Sprintf(format, args...) |