CoreForth-0

common/tether.ft.md


: >tether-byte  $FF and emit ;
: tether-byte>  key ;

: >tether-word  dup tether-byte>
                dup #8 rshift tether-byte>
                dup #16 rshift tether-byte>
                #24 rshift tether-byte> ;

: tether-word>  tether-byte>
                tether-byte> #8 lshift +
                tether-byte> #16 lshift +
                tether-byte> #24 lshift + ;

: tether-store  tether-word> tether-word> swap ! ;
: tether-fetch  tether-word> @ >tether-word ;
: tether-number tether-word> ;
: tether-exec   tether-word> execute ;

: tether-cmd    dup [char] ! = if drop tether-store false exit then
                dup [char] @ = if drop tether-fetch false exit then
                dup [char] # = if drop tether-number false exit then
                [char] X = if tether-exec false exit then
                true
                ;

: tether-listen begin tether-byte> tether-cmd 4 >tether-byte until ;