diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 6a4d0c6..7044740 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -100,8 +100,8 @@ : loop 1 aliteral postpone +loop ; immediate ( Constants and Variables ) -: constant create , does> @ ; -: variable create 0 , ; +: constant ( n "name" -- ) create , does> @ ; +: variable ( "name" -- ) create 0 , ; ( Stack Convience ) sp@ constant sp0 @@ -114,15 +114,15 @@ variable handler : throw handler @ rp! r> handler ! r> swap >r sp! drop r> ; ' throw 'throw ! -( Deferred Words ) -: defer create 0 , does> @ execute ; -: is ' >body ! ; - ( Values ) : value ( n -- ) create , does> @ ; : to ( n -- ) state @ if postpone ['] postpone >body postpone ! else ' >body ! then ; immediate +( Deferred Words ) +: defer ( "name" -- ) create 0 , does> @ execute ; +: is ( xt "name -- ) postpone to ; immediate + ( Defer I/O to platform specific ) defer type defer key diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index 2f08dfa..a811698 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -5,11 +5,10 @@ create calls ' call0 , ' call1 , ' call2 , ' call3 , ' call4 , ' call5 , ' call6 , ' call7 , ' call8 , ' call9 , -: sofunc ( z n a -- ) swap >r swap dlsym create , r> cells calls + @ , +: sofunc ( z n a "name" -- ) swap >r swap dlsym create , r> cells calls + @ , does> dup @ swap cell+ @ execute ; -: sysfunc ( z n -- ) 0 sofunc ; -: shared-library ( z -- ) RTLD_NOW dlopen create , - ( z n -- ) does> @ sofunc ; +: sysfunc ( z n "name" -- ) 0 sofunc ; +: shared-library ( z "name" -- ) RTLD_NOW dlopen create , does> @ sofunc ; ( Major Syscalls ) z" close" 1 sysfunc close @@ -24,6 +23,22 @@ z" exit" 1 sysfunc sysexit 1 constant stdout 2 constant stderr +( Terminal handling ) +: n. ( n -- ) base @ swap decimal <# #s #> type base ! ; +: esc 27 emit ; +: at-xy ( x y -- ) esc ." [" 1+ n. ." ;" 1+ n. ." H" ; +: page esc ." [2J" esc ." [H" ; +: normal esc ." [0m" ; +: fg ( n -- ) esc ." [38;5;" n. ." m" ; +: bg ( n -- ) esc ." [48;5;" n. ." m" ; +: clear-to-eol esc ." [0K" ; +: scroll-down esc ." D" ; +: scroll-up esc ." M" ; +: hide esc ." [?25l" ; +: show esc ." [?25h" ; +: terminal-save esc ." [?1049h" ; +: terminal-restore esc ." [?1049l" ; + ( Hookup I/O ) : stdout-write ( a n -- ) stdout -rot write drop ; ' stdout-write is type @@ -31,3 +46,4 @@ z" exit" 1 sysfunc sysexit ' stdin-key is key : posix-bye 0 sysexit ; ' posix-bye is bye +