Make option to switch between compiling program and eval program directly.
@@ -10,10 +10,12 @@ import (
"strings"
"flag"
"github.com/st0012/GVM"
+ "github.com/st0012/Rooby/evaluator"
)
func main() {
- execOptionPtr := flag.Bool("c", false, "Compile to bytecode")
+ compileOptionPtr := flag.Bool("c", false, "Compile to bytecode")
+ evalOptionPtr := flag.Bool("eval", true, "Eval program directly without using VM")
flag.Parse()
@@ -27,17 +29,22 @@ func main() {
p := parser.New(l)
program := p.ParseProgram()
p.CheckErrors()
+
+ if *evalOptionPtr && !*compileOptionPtr {
+ evaluator.Eval(program, evaluator.MainObj.Scope)
+ return
+ }
+
cg := code_generator.New(program)
bytecodes := cg.GenerateByteCode(program)
- if !*execOptionPtr {
+ if !*compileOptionPtr {
gvm.Exec(bytecodes)
return
}
writeByteCode(bytecodes, filepath)
- //evaluator.Eval(program, evaluator.MainObj.Scope)
}
func writeByteCode(bytecodes string, filepath string) {
