commit 5e84c64a4cc060164e6823d96e7ba193abc55756
parent df1e0180ae8dce560bd9cf9c1f2498ba7e8dcc29
Author: Christian Ermann <christianermann@gmail.com>
Date: Sun, 30 Mar 2025 13:39:06 -0700
Add 'lit,' and update 'compile,'
Diffstat:
| M | src/forth.s | | | 54 | +++++++++++++++++++++++++++--------------------------- |
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/forth.s b/src/forth.s
@@ -501,11 +501,10 @@ defword "\"", double_quote, 0x270C92A5, flags=flag_immediate
# lit-string
push w
la w, lit_string
- jal jal_to
jal compile_comma
# len [chars]
push w
- jal compile_comma
+ jal lit_comma
la x, _code_pointer
lw x, 0(x)
push x
@@ -667,21 +666,15 @@ _postpone_macro:
# stores `jal-to <xt>` into the current definition
jal to_cfa
jal fetch
- jal jal_to
jal compile_comma
j _postpone_done
_postpone_normal:
- # stores `literal<xt> jal-to compile,` into the current definition
+ # stores `literal<xt> compile,` into the current definition
jal to_cfa
jal fetch
jal literal
push w
- la w, jal_to
- jal jal_to
- jal compile_comma
- push w
la w, compile_comma
- jal jal_to
jal compile_comma
j _postpone_done
_postpone_fail:
@@ -694,8 +687,8 @@ defword "literal", literal, 0xECB9D8E4, flags=flag_immediate
li w, 0xFFC10113 # addi psp, psp, -4
push w
li w, 0xFEA12E23 # sw w, -4(psp)
- jal compile_comma
- jal compile_comma
+ jal lit_comma
+ jal lit_comma
mv x, w
_literal_small_1:
# emit `addi w, zero, immed`
@@ -721,9 +714,9 @@ _literal_large_1:
_literal_large_2:
# emit `lui w, immed`
addi w, w, 0x537
- jal compile_comma
+ jal lit_comma
_literal_small_2:
- jal compile_comma
+ jal lit_comma
exit
defcode "word>hash", word_to_hash, 0x50E0A245
@@ -794,7 +787,6 @@ _interpret_word_found:
bnez x, _interpret_macro
_interpret_word:
load_cell w, 0(w)
- jal jal_to
jal compile_comma
j _interpret_start
_interpret_macro:
@@ -1087,7 +1079,6 @@ defcode ",", comma, 0x290C95CB
pop w
next
-
defcode "c,", char_comma, 0xA32A0A5A
la y, _data_pointer
load_cell x, 0(y)
@@ -1097,15 +1088,24 @@ defcode "c,", char_comma, 0xA32A0A5A
pop w
next
-defcode "compile," compile_comma, 0x8D0A6736
+defcode "lit," lit_comma, 0xD2F4416E
+ # Store a cell-sized value into code space
+ # ( cell -- )
la y, _code_pointer
- load_cell x, 0(y)
- store_cell w, 0(x)
- addi x, x, cell
- store_cell x, 0(y)
+ lw x, 0(y)
+ sw w, 0(x)
+ addi x, x, 1*cell
+ sw x, 0(y)
pop w
next
+defword "compile,", compile_comma, 0x8D0A6736
+ # Compile a word into code space
+ # ( xt -- )
+ jal jal_to
+ jal lit_comma
+ exit
+
defcode "align-data", align_data, 0x78D58E59
la x, _data_pointer
lw y, 0(x)
@@ -1402,7 +1402,7 @@ defword "dovar,", dovar_comma, 0x1F514E5B
# ret
push w
li w, 0x00008067
- jal compile_comma
+ jal lit_comma
exit
defword "docon,", docon_comma, 0x76DCA1A4
@@ -1412,28 +1412,28 @@ defword "docon,", docon_comma, 0x76DCA1A4
# ret
push w
li w, 0x00008067
- jal compile_comma
+ jal lit_comma
exit
defword "docol,", docol_comma, 0xFAE1EE9E
push w
li w, 0xFE14AE23 # sw ra, -4(s1)
- jal compile_comma
+ jal lit_comma
push w
li w, 0xFFC48493 # addi s1, s1, -4
- jal compile_comma
+ jal lit_comma
exit
defword "exit,", exit_comma, 0xD540F80B
push w
li w, 0x0004A083 # lw ra, 0(s1)
- jal compile_comma
+ jal lit_comma
push w
li w, 0x00448493 # addi s1, s1, 4
- jal compile_comma
+ jal lit_comma
push w
li w, 0x00008067 # ret
- jal compile_comma
+ jal lit_comma
exit
defword "create-meta", create_meta, 0x001AE175