diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index 008b415..5e677f1 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -52,7 +52,7 @@ : ] -1 state ! ; immediate ( Quoting Words ) -: ' bl parse find ; +: ' bl parse find dup 0= 'throw @ execute ; : ['] ' aliteral ; immediate : char bl parse drop c@ ; : [char] char aliteral ; immediate @@ -110,8 +110,10 @@ rp@ constant rp0 ( Exceptions ) variable handler -: catch sp@ >r handler @ >r rp@ handler ! execute r> handler ! r> drop 0 ; -: throw handler @ rp! r> handler ! r> swap >r sp! drop r> ; +: catch ( xt -- n ) + sp@ >r handler @ >r rp@ handler ! execute r> handler ! r> drop 0 ; +: throw ( n -- ) + dup if handler @ rp! r> handler ! r> swap >r sp! drop r> else drop then ; ' throw 'throw ! ( Values ) @@ -120,7 +122,7 @@ variable handler else ' >body ! then ; immediate ( Deferred Words ) -: defer ( "name" -- ) create 0 , does> @ execute ; +: defer ( "name" -- ) create 0 , does> @ dup 0= throw execute ; : is ( xt "name -- ) postpone to ; immediate ( Defer I/O to platform specific ) @@ -185,4 +187,3 @@ create input-buffer input-limit allot : query begin ['] eval-buffer catch if ." ERROR" cr then prompt refill drop again ; : ok ." uEForth" cr prompt refill drop query ; - diff --git a/ueforth/common/core.h b/ueforth/common/core.h index 4303a2a..6283194 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -111,6 +111,7 @@ static void ueforth(const char *src, cell_t src_len) { g_sys.last[-1] = 1; // Make ; IMMEDIATE g_sys.DOLIT_XT = FIND("DOLIT"); g_sys.DOEXIT_XT = FIND("EXIT"); + g_sys.tthrow = FIND("DROP"); ip = g_sys.heap; *g_sys.heap++ = FIND("EVAL1"); *g_sys.heap++ = FIND("BRANCH"); diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index a811698..17d39bf 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -5,24 +5,33 @@ create calls ' call0 , ' call1 , ' call2 , ' call3 , ' call4 , ' call5 , ' call6 , ' call7 , ' call8 , ' call9 , -: sofunc ( z n a "name" -- ) swap >r swap dlsym create , r> cells calls + @ , - does> dup @ swap cell+ @ execute ; +: sofunc ( z n a "name" -- ) + swap >r swap dlsym dup 0= throw create , r> cells calls + @ , + does> dup @ swap cell+ @ execute ; : sysfunc ( z n "name" -- ) 0 sofunc ; -: shared-library ( z "name" -- ) RTLD_NOW dlopen create , does> @ sofunc ; +: shared-library ( z "name" -- ) + RTLD_NOW dlopen 0= throw create , does> @ sofunc ; ( Major Syscalls ) +z" open" 3 sysfunc open +z" creat" 2 sysfunc creat z" close" 1 sysfunc close z" read" 3 sysfunc read z" write" 3 sysfunc write -z" open" 3 sysfunc open -z" creat" 2 sysfunc creat +z" lseek" 3 sysfunc lseek z" exit" 1 sysfunc sysexit +z" fork" 0 sysfunc fork ( Default Pipes ) 0 constant stdin 1 constant stdout 2 constant stderr +( Seek ) +0 constant SEEK_SET +1 constant SEEK_CUR +2 constant SEEK_END + ( Terminal handling ) : n. ( n -- ) base @ swap decimal <# #s #> type base ! ; : esc 27 emit ;