uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

brainfuck.tal (1217B)


      1 ( usage: cat program.bf | uxncli brainfuck.rom )
      2 
      3 |10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
      4 
      5 |0100
      6 
      7 @on-reset ( -> )
      8 	;on-console .Console/vector DEO2
      9 	BRK
     10 
     11 @on-console ( -> )
     12 	.Console/read DEI DUP #20 GTH ?{
     13 		POP <eval>
     14 		#0000 .Console/vector DEO2
     15 		#010f DEO
     16 		BRK }
     17 	[ LIT2 &ptr =program ] INC2k ,&ptr STR2
     18 	STA
     19 	BRK
     20 
     21 @<eval> ( -- )
     22 	[ LIT2r =on-console/ptr ] LDA2r ;program
     23 	&while ( -- )
     24 		LDAk [ LIT "+ ] NEQ ?{ LDAkr STHr INC STH2kr STA }
     25 		LDAk [ LIT "- ] NEQ ?{ LDAkr STHr #01 SUB STH2kr STA }
     26 		LDAk [ LIT "> ] NEQ ?{ INC2r }
     27 		LDAk [ LIT "< ] NEQ ?{ [ LIT2r 0001 ] SUB2r }
     28 		LDAk [ LIT ". ] NEQ ?{ LDAkr [ LITr 18 ] DEOr }
     29 		LDAk [ LIT "[ ] NEQ ?{ goto-next }
     30 		LDAk [ LIT "] ] NEQ ?{ goto-back }
     31 		INC2 LDAk ?&while
     32 	POP2 POP2r JMP2r
     33 
     34 @goto-next ( `mem* prg* -- )
     35 	OVR2r LDAr STHr ?{ JMP2r }
     36 	[ LITr 00 ] INC2
     37 	&loop ( -- )
     38 		LDAk [ LIT "[ ] NEQ ?{ INCr }
     39 		LDAk [ LIT "] ] NEQ ?{
     40 			STHkr ?{ POPr JMP2r }
     41 			[ LITr 01 ] SUBr }
     42 		INC2 !&loop
     43 
     44 @goto-back ( `mem* prg* -- )
     45 	OVR2r LDAr STHr ?{ JMP2r }
     46 	[ LITr 00 ] #0001 SUB2
     47 	&loop ( -- )
     48 		LDAk [ LIT "] ] NEQ ?{ INCr }
     49 		LDAk [ LIT "[ ] NEQ ?{
     50 			STHkr ?{ POPr JMP2r }
     51 			[ LITr 01 ] SUBr }
     52 		#0001 SUB2 !&loop
     53 
     54 @program
     55 
     56