summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-03-24 14:17:59 +1100
committerkitty <nepeta@canaglie.net>2026-03-24 14:17:59 +1100
commit6819ca743193bb9ae4e32c9c87c98b27d06c0c82 (patch)
treeb44746d48e4fec00241bae78e34bc2f234c32209
parentae1c341e4ce177a83fa678615103f32677888ed8 (diff)
fix s" also rp sp and emit
-rw-r--r--readme.md13
-rw-r--r--sanctuary.fs5
-rw-r--r--sanctuary.s11
3 files changed, 28 insertions, 1 deletions
diff --git a/readme.md b/readme.md
index 00f79dd..beb2a86 100644
--- a/readme.md
+++ b/readme.md
@@ -321,6 +321,9 @@ update the current if statement to branch here
when the flag is false,
and skip to `then` if the corresponding `if` was true.
+### `emit ( c -- )`
+print the single character c to output.
+
### `executable ( a u -- )`
marks the u bytes starting at address a as executable.
this is used primarily to mark the program break,
@@ -420,6 +423,11 @@ in a begin-while-repeat loop, loop back to the condition.
### `rot ( u1 u2 u3 -- u2 u3 u1 )`
rotate the top three values on the stack so that the third highest value is moved to the top.
+### `rp ( -- a )`
+yield the address of the return pointer.
+note that the address points to the return stack *before*
+this word was called.
+
### `s" ( "string" -- ) IMMEDIATE COMPILE-ONLY`
compile into the definition code to push the given string,
terminated by a double quote.
@@ -436,6 +444,11 @@ if -1 (true), the system is in compiling mode.
### `stderr ( -- 2 )`
push the file descriptor of stderr to the stack.
+### `sp ( -- a )`
+yield the address of the stack pointer.
+note that the address points to the stack *before*
+this value is pushed.
+
### `stdout ( -- 1 )`
push the file descriptor of stdout to the stack.
diff --git a/sanctuary.fs b/sanctuary.fs
index 6bc19e1..2715912 100644
--- a/sanctuary.fs
+++ b/sanctuary.fs
@@ -57,7 +57,7 @@
-1 constant true
: cmove, dup >r here swap cmove r> allot ;
-: s" 1 >in +! [ char " ] literal parse ( a u )
+: s" [ char " ] literal parse ( a u )
branch >mark >r 2dup cmove, nip ( u ) ( R: mark )
r> dup >resolve 4 + ( u a )
postpone literal ( a ) postpone literal ( u ) ; immediate compile-only
@@ -65,4 +65,7 @@
1 constant stdout
2 constant stderr
+: type swap stdout 1 syscall3 ;
+: emit sp 1 swap stdout 1 syscall3 2drop ;
+
bye
diff --git a/sanctuary.s b/sanctuary.s
index d5e387f..b333966 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -125,6 +125,17 @@ defcode "here", here, 0
pspush r11
ret
+defcode "sp", psp, 0
+ mov r11, r15
+ pspush r11
+ ret
+
+defcode "rp", rp, 0
+ mov r11, rsp
+ add r11, 8
+ pspush r11
+ ret
+
defcode "bye", bye, 0
mov rdi, 0
mov rax, __NR_exit