diff options
Diffstat (limited to 'sanctuary.s')
| -rw-r--r-- | sanctuary.s | 112 |
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 |
