diff options
| author | kitty <nepeta@canaglie.net> | 2026-04-08 17:30:24 +1000 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-04-08 17:30:24 +1000 |
| commit | 9ac53463c56dd57a84036a6944e6b4e5d3829e9c (patch) | |
| tree | 00303e73411d376b2afd78bc1e75f75d65b86960 | |
| parent | 6b4b8ad13b174da2ed172d3eca2f6bd3553f7b71 (diff) | |
some erroring stuff
| -rw-r--r-- | readme.md | 29 | ||||
| -rw-r--r-- | sanctuary.fs | 33 | ||||
| -rw-r--r-- | sanctuary.s | 11 |
3 files changed, 63 insertions, 10 deletions
@@ -58,6 +58,10 @@ have a closing bracket: ). ### `(0handler) ( -- )` the very early error handler, which simply quits the program. +### `(abort") ( ? -- )` +perform the runtime actions of `abort"`: +check for non-zero and print and abort, or do nothing. + ### `(create) ( -- )` the default behaviour of a word made by `create`, which simply pushes the address following the definition to the stack. @@ -121,6 +125,10 @@ of a `value`. (in compile mode u is whatever was on the stack already.) rotate the three topmost values on the stack so that the topmost value is moved to the third highest. +### `." ( -- ) IMMEDIATE COMPILE-ONLY` +compile into the current definition the following string (terminated by `"`) +being written to output. + ### `/buffer ( -- u )` the size of an input buffer. @@ -228,13 +236,13 @@ if a word was found, its link field address is returned along with the true flag. if no word was found or the string is of length zero, abort. -### `?notfound ( -- )` +### `?notfound? ( -- )` produce a word not found error. -### `?overflow ( -- )` +### `?overflow? ( -- )` produce a stack overflow error. -### `?underflow ( -- )` +### `?underflow? ( -- )` produce a stack underflow error. ### `0= ( n -- ? )` @@ -271,6 +279,11 @@ duplicate the two topmost values on the stack. call the error handler (the address of which is in the variable `handler`) +### `abort" ( ? -- ) IMMEDIATE COMPILE-ONLY` +if `?` is non-zero, write the message that follows (terminated by `"`) +to standard out then call the error handler. +(the address of which is in the variable `handler`) + ### `again ( -- ) IMMEDIATE COMPILE-ONLY` complete an infinite loop began by the word `begin`. @@ -418,6 +431,10 @@ remove the value at the top of the stack. ### `dup ( u -- u u )` duplicate the value at the top of the stack. +### `e." ( -- ) IMMEDIATE COMPILE-ONLY` +compile into the current definition the following string (terminated by `"`) +being written to error output. + ### `else ( -- ) IMMEDIATE COMPILE-ONLY` update the current if statement to branch here when the flag is false, @@ -426,6 +443,9 @@ and skip to `then` if the corresponding `if` was true. ### `emit ( c -- )` print the single character c to output. +### `etype ( a u -- )` +write u characters at a to error output. + ### `executable ( a u -- )` marks the u bytes starting at address a as executable. this is used primarily to mark the program break, @@ -638,6 +658,9 @@ yield the address of the stack pointer. note that the address points to the stack *before* this value is pushed. +### `sp-reset ( -- )` +reset the working stack pointer to its starting value. + ### `state ( -- a )` a variable containing a boolean value. if 0 (false), the system is in interpreting mode, diff --git a/sanctuary.fs b/sanctuary.fs index b7e5469..1acb5ee 100644 --- a/sanctuary.fs +++ b/sanctuary.fs @@ -174,14 +174,17 @@ false value nonaming 1 constant stdout 2 constant stderr -: sys-write 0 syscall3 ; -: sys-read 1 syscall3 ; +: sys-read 0 syscall3 ; +: sys-write 1 syscall3 ; : sys-open 2 syscall3 ; : sys-close 3 syscall1 ; -: type swap stdout sys-read drop ; +: type swap stdout sys-write drop ; +: etype swap stderr sys-write drop ; : emit sp 1 type drop ; +: cr 10 emit ; + 0 constant r/o 1 constant w/o 2 constant r/w @@ -198,7 +201,29 @@ false value nonaming -1 constant string-source init-source value source-id -: ." ; \ todo doc +\ syntax highlighting cannot handle this. oops,, +: ." postpone s" postpone type ; immediate compile-only \ " + +: e." postpone s" postpone etype ; immediate compile-only \ " +: (abort") ( ? a u -- ) rot 0<> if etype abort else 2drop then ; +: abort" postpone s" postpone (abort") ; immediate compile-only + +\ stk under/overflow ones need to clear the stack first +\ feels wrong but i think its correct +:noname e." word not found" cr abort ; is ?notfound? +:noname sp-reset e." stack overflow" cr abort ; is ?overflow? +:noname sp-reset e." stack underflow" cr abort ; is ?underflow? + +\ if you need more than 16 layers of included files: go away™ +\ todo doc +16 constant #buffers +0 value include-depth +8192 constant /buffer +2048 constant /line-buffer + +\ this bit is so large that i may increase the default brk +create buffers /buffer #buffers * allot +create line-buffers /line-buffer #buffers * allot \ OLD VERSION I GAVE UP ON BECAUSE IT'S TOO COMPLICATED AND SUCKS SHIT {{{ \ 8192 constant /buffer diff --git a/sanctuary.s b/sanctuary.s index 041a6fe..80b0cbc 100644 --- a/sanctuary.s +++ b/sanctuary.s @@ -149,6 +149,11 @@ defcode "sp", psp, 0 pspush r11 ret +; todo doc +defcode "sp-reset", sp_reset, 0 + lea r15, [wstk] + ret + defcode "rp", rp, 0 mov r11, rsp add r11, 8 @@ -1127,15 +1132,15 @@ defcode "abort", abort, 0 ret ; i don't like these names -defdefer "?underflow", q_underflow, 0 +defdefer "?underflow?", q_underflow, 0 call abort ret -defdefer "?overflow", q_overflow, 0 +defdefer "?overflow?", q_overflow, 0 call abort ret -defdefer "?notfound", q_notfound, 0 +defdefer "?notfound?", q_notfound, 0 call abort ret ; }}} |
