~jleightcap/forth-bf

e902deef62d753eed664c701d9b9ce47f910093f — jleightcap 1 year, 5 months ago master
brainfuck
2 files changed, 29 insertions(+), 0 deletions(-)

A README.md
A bf.fs
A  => README.md +3 -0
@@ 1,3 @@
# forth-bf

brainfuck as forth EDSL

A  => bf.fs +26 -0
@@ 1,26 @@
VARIABLE ARRAY 1000 CELLS ALLOT
ARRAY 1000 0 FILL

VARIABLE APTR
ARRAY APTR !

: RESET
    ARRAY 1000 0 FILL
    ARRAY APTR !
    ;

: PEEK APTR @ @ ;
: POKE APTR @ ! ;

: < APTR @ 1 CELLS - APTR ! ;
: > APTR @ 1 CELLS + APTR ! ;
: + PEEK 1+ POKE ;
: - PEEK 1- POKE ;
: . PEEK . ;
: , KEY POKE ;
: [ POSTPONE BEGIN POSTPONE PEEK POSTPONE WHILE ; IMMEDIATE
: ] POSTPONE REPEAT ; IMMEDIATE

\ example programs:
: echo , [ . , ] ;
: add , > , [ < + > - ] < . ;