commit a41f1ce3e8fe166b7e8b8b06c20f6071d0398289
parent 57396faa94e5c85f7d28aa06ea4261609f77d097
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 15 Feb 2024 20:31:27 -0800
(brainfuck.tal) Modernizing
Diffstat:
2 files changed, 56 insertions(+), 61 deletions(-)
diff --git a/projects/examples/exercises/brainfuck.tal b/projects/examples/exercises/brainfuck.tal
@@ -1,71 +1,64 @@
-( Brainfuck:
- > Move the pointer to the right
- < Move the pointer to the left
- + Increment the memory cell at the pointer
- - Decrement the memory cell at the pointer
- . Output the character signified by the cell at the pointer
- , Input a character and store it in the cell at the pointer
- [ Jump past the matching ] if the cell at the pointer is 0
- ] Jump back to the matching [ if the cell at the pointer is nonzero )
+( usage: cat program.bf | uxncli brainfuck.rom )
-|0100 ( -> )
+|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
- ;memory
- ;program
- &while
- LDAk LIT "> NEQ ,&movr JCN [ SWP2 INC2 SWP2 ] &movr
- LDAk LIT "< NEQ ,&movl JCN [ SWP2 #0001 SUB2 SWP2 ] &movl
- LDAk LIT "+ NEQ ,&incr JCN [ OVR2 STH2k LDA INC STH2r STA ] &incr
- LDAk LIT "- NEQ ,&decr JCN [ OVR2 STH2k LDA #01 SUB STH2r STA ] &decr
- LDAk LIT ". NEQ ,&emit JCN [ OVR2 LDA #18 DEO ] &emit
- LDAk LIT "[ NEQ ,&next JCN [ ,goto-next JSR ] &next
- LDAk LIT "] NEQ ,&prev JCN [ ,goto-back JSR ] &prev
- INC2 LDAk ,&while JCN
- POP2
- ( halt )
- #010f DEO
+|0100
-BRK
+@on-reset ( -> )
+ ;on-console .Console/vector DEO2
+ BRK
-@goto-next ( -- )
+@on-console ( -> )
+ .Console/read DEI DUP #20 GTH ?{
+ POP <eval>
+ #0000 .Console/vector DEO2
+ #010f DEO
+ BRK }
+ [ LIT2 &ptr =program ] INC2k ,&ptr STR2
+ STA
+ BRK
- OVR2 LDA #00 EQU JMP JMP2r
- ( depth ) LITr 00
- INC2
- &loop
- LDAk LIT "[ NEQ JMP INCr
- LDAk LIT "] NEQ ,&no-end JCN
- STHkr #00 EQU ,&end JCN
- LITr 01 SUBr
- &no-end
- INC2 LDAk ,&loop JCN
- &end
- ( depth ) POPr
+@<eval> ( -- )
+ ;on-console/ptr LDA2 ;program
+ &while ( -- )
+ LDAk [ LIT "+ ] NEQ ?{
+ OVR2 STH2k LDA INC STH2r STA }
+ LDAk [ LIT "- ] NEQ ?{
+ OVR2 STH2k LDA #01 SUB STH2r STA }
+ LDAk [ LIT "> ] NEQ ?{ SWP2 INC2 SWP2 }
+ LDAk [ LIT "< ] NEQ ?{
+ SWP2 #0001 SUB2 SWP2 }
+ LDAk [ LIT ". ] NEQ ?{
+ OVR2 LDA #18 DEO }
+ LDAk [ LIT "[ ] NEQ ?{ goto-next }
+ LDAk [ LIT "] ] NEQ ?{ goto-back }
+ INC2 LDAk ?&while
+ POP2 JMP2r
-JMP2r
+@goto-next ( mem* prg* -- )
+ OVR2 LDA ?{ JMP2r }
+ ( depth ) [ LITr 00 ] INC2
+ &loop ( -- )
+ LDAk [ LIT "[ ] NEQ JMP
+ INCr LDAk [ LIT "] ] NEQ ?&>no-end
+ STHkr #00 EQU ?&end
+ LITr 01 SUBr &>no-end
+ INC2 LDAk ?&loop
+ &end ( depth )
+ POPr JMP2r
-@goto-back ( -- )
+@goto-back ( mem* prg* -- )
+ OVR2 LDA ?{ JMP2r }
+ ( depth ) [ LITr 00 ] #0001 SUB2
+ &loop ( -- )
+ LDAk [ LIT "] ] NEQ JMP
+ INCr LDAk [ LIT "[ ] NEQ ?&>no-end
+ STHkr #00 EQU ?&end
+ LITr 01 SUBr &>no-end
+ #0001 SUB2 LDAk ?&loop
+ &end ( depth )
+ POPr JMP2r
- OVR2 LDA #00 NEQ JMP JMP2r
- ( depth ) LITr 00
- #0001 SUB2
- &loop
- LDAk LIT "] NEQ JMP INCr
- LDAk LIT "[ NEQ ,&no-end JCN
- STHkr #00 EQU ,&end JCN
- LITr 01 SUBr
- &no-end
- #0001 SUB2 LDAk ,&loop JCN
- &end
- ( depth ) POPr
+@program
-JMP2r
-@program ( Hello World! )
-
- "++++++++[>++++[>++>+++>+++>+<<<<
- "-]>+>+>->>+[<]<-]>>.>---.+++++++
- "..+++.>>.<-.<.+++.------.-------
- "-.>>+.>++. $1
-
-@memory
diff --git a/projects/examples/exercises/hello.bf b/projects/examples/exercises/hello.bf
@@ -0,0 +1,2 @@
+>++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+.
+