1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; and now
for something completely different
...
3 ;; UrForth
/C Forth Engine
!
4 ;; Copyright
(C
) 2023 Ketmar Dark
// Invisible Vector
6 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
23 DEPTH ?DUP
IF ." (" 0 .R
." )" ENDIF
26 FLUSH
-EMIT TTY
:RAW
-FLUSH
31 RP0
! RESTART
-WORD
-CFA EXECUTE
-TAIL
35 " \r\e[0;1;5m>\e[0m" TTY
:RAW
-TYPE
39 ..: LINORE
:ON
-BEFORE
-DRAW
( FALSE
-- FALSE
/ TRUE
)
41 DUP IFNOT DRAW
-PROMPT
ENDIF
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
55 TTY
:TTY?
" cannot run REPL on non-TTY" ?not
-error
58 TRUE
TO UFO
-REPL
-SUPPORT
:EDITOR
-ACTIVE?
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
70 UFO-REPL-SUPPORT:INTERP-DONE
75 ' REPL
-LOOP
TO UFO
-REPL
-SUPPORT
:RESTART
-WORD
-CFA
81 SP0
! RP0
! ['] UFO-REPL-SUPPORT:REPL-LOOP EXECUTE-TAIL