summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--readme.md52
-rw-r--r--sanctuary.fs26
-rw-r--r--sanctuary.s2
3 files changed, 79 insertions, 1 deletions
diff --git a/readme.md b/readme.md
index b41ba3a..d7b5341 100644
--- a/readme.md
+++ b/readme.md
@@ -118,6 +118,12 @@ 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.
+### `/buffer ( -- u )`
+the size of an input buffer.
+
+### `/linebuf ( -- u )`
+the size of a line buffer.
+
### `/mod ( u1 u2 -- u3 u4 )`
divide u1 by u2. result is in u4, remainder is in u3.
@@ -260,6 +266,12 @@ perform bitwise AND on u1 and u2.
a variable containing the current numeric input/output base.
by default this is 10.
+### `base-buffer ( -- a )`
+the address of the base input buffer which reads from the terminal.
+
+### `base-linebuffer ( -- a )`
+the address of the base line input buffer.
+
### `begin ( -- ) IMMEDIATE COMPILE-ONLY`
mark the beginning of a begin-again, begin-until,
or begin-while-repeat loop.
@@ -274,6 +286,22 @@ a 32 bit branch offset must be written immediately after.
### `brk@ ( -- a )`
yields current program break.
+### `buf>buf ( a -- a' )`
+transform an input buffer pointer into the *true buffer pointer*,
+skipping past the header.
+
+### `buf>fd ( a -- a' )`
+transform an input buffer pointer into the file descriptor that the buffer is read from.
+
+### `buf>in ( a -- a' )`
+transform an input buffer pointer into the number of read characters from that input buffer.
+
+### `buf>line ( a -- a' )`
+transform an input buffer pointer into the corresponding line buffer variable pointer.
+
+### `buf>used ( a -- a' )`
+transform an input buffer pointer into the number of characters contained in the input buffer.
+
### `bye ( -- )`
exits the forth system.
@@ -426,6 +454,9 @@ add the given charater into the numeric output buffer.
if the flag is true, execute the following if statement,
terminated by `else` or `then`.
+### `init-source ( -- n )`
+yield the value of source-id when processing the initialisation script.
+
### `immediate ( -- )`
mark the most recently defined word as immediate.
@@ -446,6 +477,18 @@ set the deferred word name to execute xt.
a variable containing the execution token of
the most recently created word.
+### `latest-input-buffer ( -- a )`
+a variable: the address of the highest recursed (current) input buffer.
+
+### `linebuf>used ( a -- a' )`
+transform a line buffer pointer into the number of used characters of the buffer.
+
+### `linebuf>buf ( a -- a' )`
+transform a line buffer pointer into the real line buffer pointer, skipping the header cells.
+
+### `buf>used ( a -- a' )`
+transform an input buffer pointer into the number of characters contained in the input buffer.
+
### `literal ( n -- ) IMMEDIATE COMPILE-ONLY`
compile a push of the literal value n into the currently compiling word.
@@ -554,6 +597,12 @@ add a minus sign to the numeric output buffer if n is less than zero.
### `smudge ( -- )`
toggles the smudge bit on the xt in latest.
+### `source-id ( -- n )`
+yield either the file descriptor of the current input file,
+-1 if the current input is from a string,
+or -2 if the current input is the initialisation script
+built into the binary.
+
### `sp ( -- a )`
yield the address of the stack pointer.
note that the address points to the stack *before*
@@ -573,6 +622,9 @@ push the file descriptor of stdin to the stack.
### `stdout ( -- 1 )`
push the file descriptor of stdout to the stack.
+### `string-source ( -- n )`
+yield the value of source-id when processing a string.
+
### `swap ( u1 u2 -- u2 u1 )`
swap the two topmost values on the stack.
diff --git a/sanctuary.fs b/sanctuary.fs
index 0199296..08a1c15 100644
--- a/sanctuary.fs
+++ b/sanctuary.fs
@@ -180,6 +180,32 @@ variable hld
: close-file sys-close ;
: read-file >r swap r> sys-read >errno ;
: write-file >r swap r> sys-write >errno ;
+
+-2 constant init-source
+-1 constant string-source
+init-source value source-id
+
+8192 constant /buffer
+create base-buffer /buffer allot \ stdin input buffer
+variable latest-input-buffer
+
+\ format: LINK LINEBUF-PTR >IN USED FD [BUFFER (8152B)]
+: buf>line cell+ ;
+: buf>in 2 cells + ;
+: buf>used 3 cells + ;
+: buf>fd 4 cells + ;
+: buf>buf 5 cells + ;
+
+4096 constant /linebuf
+create base-linebuffer /linebuf allot
+\ format >IN USED
+: linebuf>used cell+ ;
+: linebuf>buf 2 cells + ;
+
+base-linebuffer base-buffer buf>in !
+base-buffer latest-input-buffer !
+
+: accept ;
\ }}}
bye
diff --git a/sanctuary.s b/sanctuary.s
index 02fb961..aa52ce3 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -512,7 +512,7 @@ defcode ":", colon, 0
; fix to follow ans: reading from colon-sys
; this will not work with :noname or i think does>.
-defcode ";", semicolon, immediate_mask
+defdefer ";", semicolon, immediate_mask
mov r12, [latest]
add r12, 8
mov r13b, [r12]