|0 @System &pad $e &debug $1 &state $1
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
%dbg { LIT2 01 -System/debug DEO }
|100
@on-reset ( -> )
;on-console .Console/vector DEO2
;Code/intro Code/emit-line
;Code/intro2 Code/emit-line
BRK
@on-console ( -> )
.Console/type DEI #04 NEQ ?{ ( EOF handling )
Loops/not-empty? ?{ ;errs/mismatch errs/die }
}
.Console/read DEI
DUP [ LIT "[ ] NEQ ?{ Loops/open }
DUP [ LIT "] ] NEQ ?{ Loops/close }
DUP [ LIT ", ] NEQ ?{ Labels/get POP2 }
Code/emit
BRK
@putn2 ( n* -- )
SWP putn
( >> )
@putn ( n -- )
#10 DIVk DUP putbcd
MUL SUB putbcd
JMP2r
@putbcd ( n -- )
DUP #0a LTH ?{ #27 ADD }
#30 ADD .Console/write DEO
JMP2r
@Code/tab
"+ =/add
"- =/sub
"> =/next
"< =/prev
". =/out
", =/in
"[ =/open
"] =/close
$1
&add "INC 0a
&sub "STHrk 20 "SUB 0a
&next "OVR 20 "STZ 20 "INC 20 "LDZk 0a
&prev "OVR 20 "STZ 20 "STHrk 20 "SUB 20 "LDZk 0a
&out "DUP 20 "#18 20 "DEO 0a
&in 20 "POP 20 ";{ 20 "#10 20 "DEO2 20 "BRK 20 "} 20 "#12 20 "DEI 0a
&open 20 "DUP 20 "#00 20 "EQU 20 "?{ 0a
&close 20 "} 0a
&intro "|100 20 "( 20 "generated 20 "by 20 "bfc.rom 20 ") 0a
&intro2 "LITr 20 "01 0a
&trailer "#800f 20 "DEO 20 "BRK 0a
&emit ( c -- )
LIT2r =/tab
( >> )
&search ( c `addr* -- )
DUP LDArk STHr DUP
#00 NEQ ?{ POP2r POP2 POP JMP2r }
EQU ?{ INC2r INC2r INC2r !/search }
POP STH2r INC2 LDA2
( >> )
&emit-line ( addr* -- )
LDAk .Console/write DEO
LDAk #0a EQU ?{ INC2 !/emit-line }
POP2 JMP2r
@Labels/get ( -- label* )
[ LIT2 &ctr $2 ] INC2k ,/ctr STR2 ( get next loop idx )
DUP2
( >> )
&print-label ( n* -- )
[ LIT2 "@ -Console/write ] DEO
!/print-name
&print-jmi ( n* -- )
[ LIT2 "! -Console/write ] DEO
( >> )
&print-name ( n* -- )
[ LIT2 "l -Console/write ] DEO
putn2
JMP2r
@Loops/open ( -- )
Labels/get
[ LIT2 &ptr =/stack ] INC2k INC2 ,/ptr STR2 ( increment stack pointer )
STA2 ( store idx )
JMP2r
&close ( -- )
,/ptr LDR2 #0002 SUB2 ( decrement stack pointer )
LDA2k INC2k ORA ?{ ;errs/underflow errs/die }
Labels/print-jmi
,/ptr STR2
JMP2r
¬-empty? ( -- empty )
,/ptr LDR2 ;/stack EQU2
JMP2r
@errs/die ( addr* -- )
LDAk DUP ?{ #ff .System/state DEO BRK }
.Console/error DEO
INC2 !/die
&underflow "fatal: 20 "too 20 "many 20 "closing 20 "braces. 0a $1
&mismatch "fatal: 20 "not 20 "enough 20 "closing 20 "braces. 0a $1
@Loops/guard [ ffff ]
&stack ( goes to end of ram )