CoreForth-0

avr/compiler-itc.ft.md


variable state

: [             false state ! ; immediate
: ]             true state ! ;
: compiling?    state @ ;
: interpreting? state @ 0= ;

: >body         2 cells + ;
: ,link         , ;
: ,call         , ;
: s"            postpone (s")
                [char] " word dup dup c@ 1+ here swap move
                c@ 1+ allot align ; immediate

: literal       postpone lit , ; immediate
: >rom          $7fff and ;
: ,enter        ['] docol >rom , ;
: ,docon        ['] docon >rom , ;
: ,dovar        ['] dovar >rom , ;
: ,exit         ['] exit , ;

: immediate     %01000000 latest @ link>flags bis! ;
: reveal        %10000000 latest @ link>flags bic! ;
: hide          %10000000 latest @ link>flags bis! ;
: postpone      bl word find 0< if literal postpone ,call
                else ,call then ; immediate
: [']           ' postpone literal ; immediate

: <builds       align   here latest dup @ ,link   !
                bl word
                dup dup c@ 1+
                    over %10000000 swap bis!
                    here swap move
                c@ %00111111 and 1+ allot align ;
: :             <builds ,enter hide ] ;
: ;             ,exit reveal [ ; immediate
: :noname       align latest @ here dup latest ! ,enter ] ; immediate

: create        <builds ,dovar reveal ;
: constant      <builds ,docon , reveal ;
: variable      <builds ,dovar cell alloc reveal ;
: buffer:       <builds ,dovar alloc reveal ;

: recurse       latest @ link> ,call ; immediate
: [char]        char postpone literal ; immediate
: ."            postpone s" postpone type ; immediate