summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkitty <nepeta@canaglie.net>2026-02-23 14:03:53 +1100
committerkitty <nepeta@canaglie.net>2026-02-23 14:03:53 +1100
commitce86d1196c4936fe67129a3ab2fc57ae131df6f1 (patch)
treeb2e5029f8bbaadec6efd63d5e70e0dc4bf3075a3
parent4b4c00e3b768305220a26ef8912cfeddd771e1b6 (diff)
i reimplemented s" and it still doesnt work right
-rw-r--r--jefs.fs20
-rw-r--r--jefs.s120
2 files changed, 94 insertions, 46 deletions
diff --git a/jefs.fs b/jefs.fs
index 8a5c2d5..9c37038 100644
--- a/jefs.fs
+++ b/jefs.fs
@@ -23,10 +23,6 @@ hex : ret, c3 c, ; decimal
: constant create [compile] lit ret, ;
: variable 1 cells allot create [compile] lit ret, ;
-\ TODO interpret mode strings?
-: s" [ char " ] literal 1 >in +! ( skip spc ) [compile] litstring ; immediate
-: ." [compile] s" ' say compile, ; immediate \ lol this word breaks the highlighting, here have another "
-
\ jump helpers from forth83 (got them from pforth tho ehehe)
\ < backward jump > forward jump
\ adding/subtracting 4 gets to the next instruction.
@@ -46,6 +42,11 @@ hex : ret, c3 c, ; decimal
: ?dup dup 0<> if dup then ;
+\ TODO interpret mode strings?
+\ : s" [ char " ] literal 1 >in +! ( skip spc ) [compile] litstring ; immediate
+: s" 1 >in +! [ char " ] literal cparse branch >mark >r 2dup cmove, r> >resolve swap [compile] lit [compile] lit ; immediate
+: ." [compile] s" ' say compile, ; immediate \ lol this word breaks the highlighting, here have another "
+
\ https://wiki.osdev.org/X86-64_Instruction_Encoding
\ see dusk os asm/x86.fs
\ my idea is that operands are given in the reverse order that
@@ -156,6 +157,13 @@ variable hld
: bytes-allocated hend @ h0 @ - ;
: bytes-used here @ h0 @ - ;
: bytes-free bytes-allocated bytes-used - ;
-: .free bytes-free u. ." of " bytes-allocated u. ." bytes free (used " bytes-used (.) say ." )" cr ; \ segfaults
+\ there is some issue with ." that causes a segfault. strange
+\ it seems to happen if multiple strings appear.
+\ purrhaps something isn't being reset??
+\ it only seems to happen if the called word is a builtin or a number?????
+\ : .free bytes-free u. ." of " bytes-allocated u. ." bytes free (used " bytes-used (.) say ." )" cr ; \ segfaults
+
+\ .free bye
+\ : t s" eue eu eo o eu" drop say .s s" euoe" ;
-.free bye
+t bye
diff --git a/jefs.s b/jefs.s
index c4dcbdf..76d352a 100644
--- a/jefs.s
+++ b/jefs.s
@@ -195,9 +195,6 @@ defword "sp", _sp, 0
pspush r14
ret
-; stage 1 parser. very rudimentary,
-; since it will only parse a little bit of the init file
-; there won't be much error checking either.
defword "parse", parse, 0
mov r13, qword [to_in]
add r13, qword [tib]
@@ -238,6 +235,33 @@ defword "parse", parse, 0
pspush r11 ; u
ret
+defword "cparse", cparse, 0
+ pspop r15 ; c
+ mov r13, qword [to_in]
+ add r13, qword [tib]
+ mov r12b, byte [r13]
+
+.wordloop_start:
+ push r13 ; keep start address of this word for later
+ mov r11, 1 ; W: word length count
+.wordloop:
+ cmp r12b, r15b
+ je .wordloop_end
+
+ inc r11
+ inc r13
+ mov r12b, byte [r13]
+ jmp .wordloop
+
+.wordloop_end:
+ dec r11
+ sub r13, qword [tib]
+ mov qword [to_in], r13
+ pop r13
+ pspush r13 ; c-addr
+ pspush r11 ; u
+ ret
+
defword "find", find, 0
pspop r10 ; u
pspop r11 ; c-addr
@@ -1002,42 +1026,58 @@ defword "0branch", zerobranch, 0
; debugging word; outputs raw bytes so needs to be piped through `x(x)d`
; terrible and awful
; W = r14; W <= wstack_b; W+=8
-; defword ".s", dots, 0
-; push r11
-; push r12
-;
-; mov r12, r14
-; .loop:
-; cmp r12, wstack
-; jge .done
-;
-; mov [.space], r12
-; mov rdx, 8 ; qword
-; mov rsi, .space
-; mov rdi, 1
-; mov rax, __NR_write
-; syscall
-;
-; mov rdx, 8 ; qword
-; mov rsi, r12
-; mov rdi, 1
-; mov rax, __NR_write
-; syscall
-; lea r12, [r12+8]
-; jmp .loop
-;
-; .done:
-; mov rdx, 16 ; 2 qword
-; mov rsi, .dmsg
-; mov rdi, 1
-; mov rax, __NR_write
-; syscall
-;
-; pop r12
-; pop r11
-; ret
-; .space: resq 1
-; .dmsg: db "DONEDONEYIPPEEEE"
+defword ".s", dots, 0
+ push r11
+ push r12
+
+ mov r12, r14
+.loop:
+ cmp r12, wstack
+ jge .done
+
+ mov [.space], r12
+ mov rdx, 8 ; qword
+ mov rsi, .space
+ mov rdi, 1
+ mov rax, __NR_write
+ syscall
+
+ mov rdx, 8 ; qword
+ mov rsi, r12
+ mov rdi, 1
+ mov rax, __NR_write
+ syscall
+ lea r12, [r12+8]
+ jmp .loop
+
+.done:
+ mov rdx, 16 ; 2 qword
+ mov rsi, .dmsg
+ mov rdi, 1
+ mov rax, __NR_write
+ syscall
+
+ pop r12
+ pop r11
+ ret
+.space: resq 1
+.dmsg: db "DONEDONEYIPPEEEE"
+
+defword "TESTSTR", teststr, 0
+ mov r11, .msg
+ pspush r11
+ mov r11, 11
+ pspush r11
+ ret
+.msg: db "test string"
+
+defword "TESTSTR2", teststr2, 0
+ mov r11, .msg
+ pspush r11
+ mov r11, 12
+ pspush r11
+ ret
+.msg: db "other string"
defword "HEREDUMP", heredump, 0
mov rdx, [here]
@@ -1055,7 +1095,7 @@ defvar "#tib", num_tib, 0, initlen
defvar ">in", to_in, 0, 0
defvar "state", state, 0, interpreting
defvar "here", here, 0, umem
-defvar "s0", s0, 0, wstack - 8
+defvar "s0", s0, 0, wstack
defvar "h0", h0, 0, umem ; beginning of user memory area
defvar "hend", hend, 0, umem_e ; ending of user memory area
defvar "base", base, 0, 10