UrForth: fixed "(BASED-NUMBER)" with radix postfix
[urasm.git] / urflibs / repl.f
blob782f9b837b3103706984e4dfe1e1eea026015bf2
1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; and now for something completely different...
3 ;; UrForth/C Forth Engine!
4 ;; Copyright (C) 2023 Ketmar Dark // Invisible Vector
5 ;; GPLv3 ONLY
6 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;; simple REPL
8 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10 $INCLUDE-ONCE <linore.f>
11 $INCLUDE-ONCE <debugger.f>
14 VOCABULARY UFO-REPL-SUPPORT
15 ALSO-DEFS: UFO-REPL-SUPPORT
17 FALSE VALUE EDITOR-ACTIVE?
18 0 VALUE RESTART-WORD-CFA
20 : .OK ( -- )
21 STATE @ IFNOT
22 ." ok"
23 DEPTH ?DUP IF ." (" 0 .R ." )" ENDIF
24 ELSE ." more..."
25 ENDIF CR
26 FLUSH-EMIT TTY:RAW-FLUSH
29 : INTERP-DONE ( -- )
30 .OK
31 RP0! RESTART-WORD-CFA EXECUTE-TAIL
34 : DRAW-PROMPT ( -- )
35 " \r\e[0;1;5m>\e[0m" TTY:RAW-TYPE
39 ..: LINORE:ON-BEFORE-DRAW ( FALSE -- FALSE / TRUE )
40 EDITOR-ACTIVE? IF
41 DUP IFNOT DRAW-PROMPT ENDIF
42 ENDIF
43 ;..
46 ;; do not allow debugger to abort on bad forth word
47 ..: FORTH:(INTERPRET-WORD-NOT-FOUND) ( addr count FALSE -- addr count FALSE / TRUE )
48 DROP SPACE XTYPE ." ? -- wut?!" CR
49 STATE 0! SP0!
50 INTERP-DONE
51 ;..
54 : REPL-LOOP
55 TTY:TTY? " cannot run REPL on non-TTY" ?not-error
56 BEGIN
57 LINORE:RESET
58 TRUE TO UFO-REPL-SUPPORT:EDITOR-ACTIVE?
59 1 TO LINORE:START-X
60 TTY:SIZE DROP TO LINORE:DRAW-WIDTH
61 FLUSH-EMIT LINORE:EDIT-LINE
62 FALSE TO UFO-REPL-SUPPORT:EDITOR-ACTIVE?
63 LINORE:ACCEPT-RESULT LINORE:RESULT-^D = IF BREAK ENDIF
64 LINORE:ACCEPT-RESULT +IF
65 ['] UFO-REPL-SUPPORT:INTERP-DONE (USER-INTERPRET-NEXT-LINE) !
66 0 LINORE:LINE + C! ;; finish TIB with 0 byte
67 LINORE:LINE DROP TIB ! >IN 0! ;; setup TIB
68 CR TTY:RAW-FLUSH
69 INTERPRET
70 UFO-REPL-SUPPORT:INTERP-DONE
71 ENDIF
72 AGAIN
75 ' REPL-LOOP TO UFO-REPL-SUPPORT:RESTART-WORD-CFA
77 PREV-DEFS
80 : UFO-RUN-REPL ( -- )
81 SP0! RP0! ['] UFO-REPL-SUPPORT:REPL-LOOP EXECUTE-TAIL