misc fixes
This commit is contained in:
32
repl.go
32
repl.go
@@ -30,13 +30,20 @@ func VmREPL(args []string, debug, trace bool) error {
|
||||
fmt.Println(err)
|
||||
return fmt.Errorf("error opening terminal: %w", err)
|
||||
}
|
||||
defer term.Restore(0, initState)
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("recovered from panic: %s", err)
|
||||
}
|
||||
term.Restore(0, initState)
|
||||
}()
|
||||
atexit.Register(func() {
|
||||
term.Restore(0, initState)
|
||||
})
|
||||
|
||||
t := term.NewTerminal(os.Stdin, ">>> ")
|
||||
t.AutoCompleteCallback = autoComplete
|
||||
|
||||
object.Args = args
|
||||
object.Stdout = t
|
||||
object.ExitFunction = atexit.Exit
|
||||
|
||||
@@ -71,6 +78,10 @@ func VmREPL(args []string, debug, trace bool) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if debug {
|
||||
log.Printf("Bytecode:\n%s\n", c.Bytecode())
|
||||
}
|
||||
|
||||
mvm := vm.NewWithState("<stdin>", c.Bytecode(), state)
|
||||
mvm.Debug = debug
|
||||
mvm.Trace = trace
|
||||
@@ -80,7 +91,7 @@ func VmREPL(args []string, debug, trace bool) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if val := mvm.LastPoppedStackElem(); val.Type() != object.NullType {
|
||||
if val := mvm.LastPoppedStackElem(); val != nil && val.Type() != object.NullType {
|
||||
fmt.Fprintln(t, val.Inspect())
|
||||
}
|
||||
}
|
||||
@@ -137,7 +148,18 @@ func SimpleVmREPL(args []string, debug, trace bool) {
|
||||
reader = bufio.NewReader(os.Stdin)
|
||||
)
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("recovered from panic: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
t := term.NewTerminal(os.Stdin, ">>> ")
|
||||
t.AutoCompleteCallback = autoComplete
|
||||
|
||||
object.Args = args
|
||||
object.Stdout = t
|
||||
object.ExitFunction = atexit.Exit
|
||||
|
||||
PrintVersionInfo(os.Stdout)
|
||||
for {
|
||||
@@ -171,6 +193,10 @@ func SimpleVmREPL(args []string, debug, trace bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
if debug {
|
||||
log.Printf("Bytecode:\n%s\n", c.Bytecode())
|
||||
}
|
||||
|
||||
mvm := vm.NewWithState("<stdin>", c.Bytecode(), state)
|
||||
mvm.Debug = debug
|
||||
mvm.Trace = trace
|
||||
@@ -180,7 +206,7 @@ func SimpleVmREPL(args []string, debug, trace bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
if val := mvm.LastPoppedStackElem(); val.Type() != object.NullType {
|
||||
if val := mvm.LastPoppedStackElem(); val != nil && val.Type() != object.NullType {
|
||||
fmt.Println(val.Inspect())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user