Commit Diff


commit - c7d7ae29540cc0db3c92e246d5f34fe9f0fe9eff
commit + 4c79a9268a52568026a51eb4acb9bdb35098362a
blob - 77b5b47b823c52ab40b9107d6aa2ff60165c070f
blob + bcd5d5be5ca3224537d1175e5230c719b65edd53
--- rvforth.S
+++ rvforth.S
@@ -304,15 +304,6 @@ _EMIT:
 _KEY:
 	j getchar
 .size _KEY, . - _KEY
-
-_COMMA:
-	la t0, var_HERE
-	ld t1, 0(t0)
-	sd a0, 0(t1)
-	addi t1, t1, 8
-	sd t1, 0(t0)
-	jr ra
-.size _COMMA, . - _COMMA
 
 defcode "DONE", 4, DONE, 0
 	POP a0
@@ -326,15 +317,16 @@ defcode "DROP", 4, DROP, EXIT
 	addi DSP, DSP, 8
 	NEXT
 
-defcode "2DROP", 5, TDROP, DROP
-	addi DSP, DSP, 16
-	NEXT
+defword "2DROP", 5, TDROP, DROP
+	.quad DROP
+	.quad DROP
+	.quad EXIT
 
 defcode "SWAP", 4, SWAP, TDROP
-	POP t0
-	POP t1
-	PUSH t0
-	PUSH t1
+	ld t0, 0(DSP)
+	ld t1, 8(DSP)
+	sd t0, 8(DSP)
+	sd t1, 0(DSP)
 	NEXT
 
 defcode "OVER", 4, OVER, SWAP
@@ -344,23 +336,23 @@ defcode "OVER", 4, OVER, SWAP
 
 // ( X Y Z -- Z X Y )
 defcode "ROT", 3, ROT, OVER
-	POP t0
-	POP t1
-	POP t2
-	PUSH t1
-	PUSH t0
-	PUSH t2
+	ld t0, 0(DSP)
+	ld t1, 8(DSP)
+	ld t2, 16(DSP)
+	sd t1, 16(DSP)
+	sd t0, 8(DSP)
+	sd t2, 0(DSP)
 	NEXT
 
 // ( X Y Z -- Y Z X )
 // ( Z X Y ) -- ( X Y Z )
 defcode "-ROT", 4, NROT, ROT
-	POP t0
-	POP t1
-	POP t2
-	PUSH t0
-	PUSH t2
-	PUSH t1
+	ld t0, 0(DSP)
+	ld t1, 8(DSP)
+	ld t2, 16(DSP)
+	sd t0, 16(DSP)
+	sd t2, 8(DSP)
+	sd t`, 0(DSP)
 	NEXT
 
 defcode "DUP", 3, DUP, NROT
@@ -382,17 +374,15 @@ defcode "?DUP", 4, QDUP, TDUP
 1:
 	NEXT
 
-defcode "1+", 2, INC, QDUP
-	POP t0
-	addi t0, t0, 1
-	PUSH t0
-	NEXT
+defword "1+", 2, INC, QDUP
+	.quad LIT, 1
+	.quad ADD
+	.quad EXIT
 
-defcode "1-", 2, DEC, INC
-	POP t0
-	addi t0, t0, -1
-	PUSH t0
-	NEXT
+defword "1-", 2, DEC, INC
+	.quad LIT, 1
+	.quad SUB
+	.quad EXIT
 
 defcode "+", 1, ADD, DEC
 	POP t1
@@ -799,10 +789,20 @@ defcode ".", 1, PRINT, FETCHBYTE
 	jal printf
 	NEXT
 
-defcode ",", 1, COMMA, PRINT
-	POP a0
-	jal _COMMA
-	NEXT
+// ( word )
+defword ",", 1, COMMA, PRINT
+	.quad HERE	// ( &HERE word )
+	.quad SWAP	// ( word &HERE )
+	.quad OVER	// ( &HERE word &HERE )
+	.quad FETCH	// ( HERE word &HERE )
+	.quad SWAP	// ( word HERE &HERE )
+	.quad OVER	// ( HERE word HERE &HERE )
+	.quad STORE	// ( HERE &HERE )
+	.quad LIT, 8	// ( 8 HERE &HERE )
+	.quad ADD	// ( HERE+8 &HERE )
+	.quad SWAP	// ( &HERE HERE+8 )
+	.quad STORE	// ( )
+	.quad EXIT	// noreturn
 
 defcode "'", 1, TICK, COMMA
 	ld a0, 0(PC)