1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-17 16:24:42 +00:00

Add CTRL-C keyboard interrupt

This commit is contained in:
David Schmenk 2024-07-22 08:44:46 -07:00
parent 23aae45787
commit a5d2fdc17b
3 changed files with 25 additions and 4 deletions

Binary file not shown.

View File

@ -1,6 +1,8 @@
include "inc/cmdsys.plh"
include "inc/args.plh"
include "inc/fileio.plh"
include "inc/conio.plh"
include "inc/longjmp.plh"
import sexpr
const TYPE_MASK = $70
@ -51,7 +53,7 @@ import sexpr
predef print_expr(expr)#0
predef parse_expr(evalptr, level, refill)#2
predef eval_expr(expr)#1
predef eval_quote(expr)#1
predef eval_quote(expr, hook)#1
predef bool_pred(bool)#1
end
@ -59,11 +61,12 @@ import smath
predef eval_int(expr)#1
end
var prog, prog_expr, prog_return // Current PROG expressions
var sym_cond, sym_if, sym_fpint, sym_fpfrac
var pred_true
res[t_except] break_repl // Breeak out of eval processing
const csw = $0036 // Output switch vector
var scrncsw = 0 // Output screen value
@ -282,6 +285,19 @@ def parse_cmdline#0
fin
end
def hookfn
if conio:keypressed() == $83 // CTRL-C
conio:getkey() // Clear KB
puts("\n^C\n")
if fileref
fileio:close(fileref)
readfn = @read_keybd
fin
throw(@break_repl, FALSE)
fin
return 0
end
//
// REPL
//
@ -306,8 +322,9 @@ new_sym("PRINTER")=>natv = @natv_printer
new_sym("QUIT")=>natv = @natv_bye
parse_cmdline
except(@break_repl)
while not quit
putln; print_expr(eval_quote(readfn()))
putln; print_expr(eval_quote(readfn(), @hookfn))
loop
putln
done

View File

@ -50,6 +50,8 @@ struc t_array
word arraymem
end
var hook_eval = NULL // Installable hook for eval_expr()
byte trace = FALSE
const fmt_fp = FPSTR_FIXED|FPSTR_STRIP|FPSTR_FLEX
@ -862,6 +864,7 @@ end
export def eval_expr(expr)#1
var alist_enter, curl, expr_car
if hook_eval; hook_eval(); fin
if gc_pull > GC_TRIGGER; gc; fin
alist_enter = assoc_list
curl = NULL // Current lambda
@ -952,7 +955,8 @@ export def eval_expr(expr)#1
return expr
end
export def eval_quote(expr)#1
export def eval_quote(expr, hook)#1
hook_eval = hook
push_sweep_stack(assoc_list)
assoc_list = NULL
push_sweep_stack(expr) // Keep expr from being GC'ed