summaryrefslogtreecommitdiff
path: root/sanctuary.s
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-03-15 23:03:21 +1100
committerkitty <nepeta@canaglie.net>2026-03-15 23:03:21 +1100
commit85199c06b8e104dfed0366389e6b95a7757d0510 (patch)
tree41bae529a7c70d89b81387a19db5407689a9c5d0 /sanctuary.s
parent9f311bce41eb76a46213867b8762ee517d33b6ba (diff)
parse and parse-name (untested)
Diffstat (limited to 'sanctuary.s')
-rw-r--r--sanctuary.s112
1 files changed, 112 insertions, 0 deletions
diff --git a/sanctuary.s b/sanctuary.s
index b511d68..235f384 100644
--- a/sanctuary.s
+++ b/sanctuary.s
@@ -104,6 +104,118 @@ defcode "bye", bye, 0
syscall
ret
+; input parsing {{{
+; r11: string character count
+; rsi: input buffer address
+; al: char being parsed
+; r10: end of input buffer
+defcode "parse-name", parse_name, 0
+ mov rsi, qword [to_in]
+ mov r10, qword [tib]
+ add rsi, r10
+ add r10, qword [n_tib]
+ xor rax, rax
+
+.wsloop:
+ cmp rsi, r10
+ jge .empty
+ lodsb
+ cmp al, 0x20
+ je .wsloop
+ cmp al, 0x09
+ je .wsloop
+ cmp al, 0x0a
+ je .wsloop
+
+ cmp rsi, r10
+ jge .empty
+ mov r11, 1
+ dec rsi ; bring down by one to point to the start
+ push rsi ; will become `a`
+ inc rsi
+.wordloop:
+ cmp al, 0x20
+ je .wordloop_e
+ cmp al, 0x09
+ je .wordloop_e
+ cmp al, 0x0a
+ je .wordloop_e
+
+ ; is there a better way of checking before?
+ cmp rsi, r10
+ jge .wordloop_e
+ inc r11
+ lodsb
+ je .wordloop
+
+.wordloop_e:
+ sub rsi, qword [tib]
+ mov qword [to_in], rsi
+ pop rsi
+ pspush rsi
+ pspush r11
+ ret
+
+.empty:
+ pspush 0
+ pspush 0
+ ret
+
+; r11: string character count
+; rsi: input buffer address
+; al: char being parsed
+; r10: end of input buffer
+defcode "parse", parse, 0
+ mov rsi, qword [to_in]
+ mov r10, qword [tib]
+ add rsi, r10
+ add r10, qword [n_tib]
+ xor rax, rax
+
+.wsloop:
+ cmp rsi, r10
+ jge .empty
+ lodsb
+ cmp al, r15b
+ je .wsloop
+ cmp al, 0x0a
+ je .wsloop
+
+ cmp rsi, r10
+ jge .empty
+ mov r11, 1
+ dec rsi ; bring down by one to point to the start
+ push rsi ; will become `a`
+ inc rsi
+.wordloop:
+ cmp al, r15b
+ je .wordloop_e
+ cmp al, 0x0a
+ je .wordloop_e
+
+ ; is there a better way of checking before?
+ cmp rsi, r10
+ jge .wordloop_e
+ inc r11
+ lodsb
+ je .wordloop
+
+.wordloop_e:
+ sub rsi, qword [tib]
+ mov qword [to_in], rsi
+ pop rsi
+ pspop r8
+ pspush rsi
+ pspush r11
+ ret
+
+.empty:
+ pspop r8
+ pspush 0
+ pspush 0
+ ret
+; }}}
+
defvar "state", state, 0, INTERPRET
defvar "dp", dp, 0, 0
defvar "dp0", dp0, 0, 0