Make inspecting instructions more easier.
@@ -99,21 +99,29 @@ func (g *Generator) InitTopLevelScope(program *ast.Program) {
// GenerateByteCode returns compiled instructions in string format
func (g *Generator) GenerateByteCode(stmts []ast.Statement) string {
g.compileStatements(stmts, g.scope, g.scope.localTable)
- var out bytes.Buffer
- for _, is := range g.instructionSets {
- out.WriteString(is.compile())
- }
-
- return strings.TrimSpace(strings.Replace(out.String(), "\n\n", "\n", -1))
+ return strings.TrimSpace(strings.Replace(g.instructionsToString(), "\n\n", "\n", -1))
}
// GenerateInstructions returns compiled instructions
func (g *Generator) GenerateInstructions(stmts []ast.Statement) []*InstructionSet {
g.compileStatements(stmts, g.scope, g.scope.localTable)
+
+ //fmt.Println(g.instructionsToString())
+ //fmt.Print()
return g.instructionSets
}
+func (g *Generator) instructionsToString() string {
+ var out bytes.Buffer
+
+ for _, is := range g.instructionSets {
+ out.WriteString(is.compile())
+ }
+
+ return out.String()
+}
+
func (g *Generator) compileCodeBlock(is *InstructionSet, stmt *ast.BlockStatement, scope *scope, table *localTable) {
for i, s := range stmt.Statements {
/*
