CoreForth-0

common/interpret.ft.md


: ex.           $45 emit $23 emit h.4 ;
: prompt        source-id if exit then space [char] o emit [char] k emit cr ;
: interpret     begin  bl word dup c@ while      textadr
                  find ?dup if                    xt 1/-1
                    1+ interpreting? or              immed or interp?
                    if execute else ,call then
                  else                            textadr
                    ?number if                    converted ok
                      compiling? if postpone literal then
                    else count type [char] ? emit cr $fff3 throw then
                  then
                repeat drop ;

: evaluate      source >in @ >r >r >r
                source# ! (source) ! 0 >in ! interpret
                r> r> r> >in ! source# ! (source) ! ;

: refill        tib dup tib# xon accept xoff
                source# ! (source) ! 0 >in ! true ;

: quit          r0 rp! 0 state !
                begin
                  refill
                while
                  source-id 0= if space then
                  ['] interpret catch
                  ?dup if
                    dup $fff3 <> if ex. postpone [ else drop then
                    s0 sp!
                  then
                  interpreting? if prompt then
                repeat
                bye ;

: abort         s0 sp! quit ;

: abort"        postpone if
                postpone s" postpone type postpone cr
                postpone abort
                postpone then ; immediate