misc fixes
Some checks failed
Build / build (push) Successful in 10m45s
Publish Image / publish (push) Failing after 42s
Test / build (push) Successful in 11m9s

This commit is contained in:
2024-04-01 17:44:15 -04:00
parent 99f7553d67
commit fe33fda0ab
8 changed files with 91 additions and 10 deletions

32
repl.go
View File

@@ -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())
}
}