From 9c915b56270ae4fc3b8ee177732f142dd84403a8 Mon Sep 17 00:00:00 2001 From: kitty Date: Sat, 28 Feb 2026 20:46:17 +1100 Subject: NOT, duskos-based rename h0 > herestart hend > heremax --- jefs.fs | 18 +++++++++++++----- jefs.s | 8 ++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/jefs.fs b/jefs.fs index 0ab60d3..ea8f740 100644 --- a/jefs.fs +++ b/jefs.fs @@ -114,8 +114,9 @@ hex : ret, c3 c, ; decimal hex variable rex variable modrm +variable disp -: asm$ 0 rex ! c0 modrm ! ; +: asm$ 0 rex ! c0 modrm ! 0 disp ! ; : rex.w rex @ 48 or rex ! ; : rex.r rex @ 44 or rex ! ; @@ -147,10 +148,11 @@ variable modrm : /2 modrm @ 10 or modrm ! ; : /3 modrm @ 18 or modrm ! ; : /4 modrm @ 20 or modrm ! ; : /5 modrm @ 28 or modrm ! ; : /6 modrm @ 30 or modrm ! ; : /7 modrm @ 38 or modrm ! ; +: modrm, ; \ TODO store and write the displacement if given : mod0 modrm @ 3f and modrm ! ; -: d) mod0 0<> if modrm @ 40 or modrm ! then ; \ disp8 or 0 only for now +: d) disp ! mod0 0<> if modrm @ 40 or modrm ! then ; \ disp8 or 0 only for now : mov, rex, 8b c, modrm @ c, asm$ ; @@ -161,6 +163,7 @@ variable modrm decimal \ }}} +: not 0= ; : / /mod swap drop ; : mod /mod drop ; : negate 0 swap - ; @@ -205,8 +208,9 @@ variable hld : ? @ . ; : .s sp cell+ ( skip sp itself ) begin dup s0 @ > while dup @ .qword cell+ repeat drop cr ; : .rs rp cell+ ( skip rsp itself ) begin dup rs0 @ > while dup @ .qword cell+ repeat drop cr ; -: bytes-allocated hend @ h0 @ - ; -: bytes-used here @ h0 @ - ; + +: bytes-allocated heremax @ herestart @ - ; +: bytes-used here @ herestart @ - ; : bytes-free bytes-allocated bytes-used - ; : .free bytes-free u. ." of " bytes-allocated u. ." bytes free (used " bytes-used (.) say ." )" cr ; @@ -244,7 +248,7 @@ variable hld endcase cr then ; \ }}} -\ FILE I/O {{{ +\ I/O {{{ 0 constant stdin 1 constant stdout 2 constant stderr @@ -263,6 +267,7 @@ make file-buffer file-buffer-length allot \ TODO error handling (0< abs → errno i think) \ flags are zero on success +\ maybe there should be some sort of read buffering support here : open-file ( mode zstr -- ?fd flag ) 0 -rot sysopen errno ; : close-file ( fd -- flag ) sysclose errno-flag ; : read-file ( c-addr u fd -- ?u flag ) >r swap r> sysread errno ; @@ -270,6 +275,9 @@ make file-buffer file-buffer-length allot \ }}} \ INTERACTIVITY {{{ +\ i hate dealing with user input!!! +\ but my idea is: when reading forth from a file, +\ words are read into a buffer, and read from there. \ }}} .free diff --git a/jefs.s b/jefs.s index 16a7e1b..b4dc8d0 100644 --- a/jefs.s +++ b/jefs.s @@ -1153,9 +1153,9 @@ defword ".s", dots, 0 defword "HEREDUMP", heredump, 0 mov rdx, [here] - mov r11, [h0] + mov r11, [herestart] sub rdx, r11 - mov rsi, [h0] + mov rsi, [herestart] mov rdi, 1 mov rax, __NR_write syscall @@ -1169,9 +1169,9 @@ defvar ">in", to_in, 0, 0 defvar "state", state, 0, interpreting defvar "here", here, 0, umem defvar "s0", s0, 0, wstack -defvar "h0", h0, 0, umem ; beginning of user memory area +defvar "herestart", herestart, 0, umem ; beginning of user memory area defvar "rs0", rs0, 0, 0 -defvar "hend", hend, 0, umem_e ; ending of user memory area +defvar "heremax", heremax, 0, umem_e ; ending of user memory area defvar "base", base, 0, 10 defvar "error", error, 0, 0 ; defvar "handler", handler, 0, brac_handler -- cgit v1.2.3