variable >in
variable source#
variable (source)
$80 buffer: tib
$80 constant tib#
$80 buffer: wp
: source (source) @ source# @ ;
: source@ (source) @ >in @ + c@ ;
: >>source 1 >in +! ;
: in-source? >in @ source# @ < ;
: skip begin source@ over = in-source? and while >>source repeat drop ;
: copy begin source@ over <> in-source? and while
source@ wp cappend >>source
repeat in-source? if >>source then drop ;
: word 0 wp tuck c! swap dup skip copy ;
: char bl word 1+ c@ ;
: .( [char] ) word count type ; immediate
: accept ( c-addr +n -- +n' get line from terminal )
over + 1- over
begin key
dup $0A <> while
dup $7F = if drop 8 then
source-id 0= if dup emit then
dup 8 = if drop 1- >r over r> umax
else over c! 1+ over umin
then
repeat
drop nip swap - ;
: setbase ( addr n -- addr' n' )
over c@ dup 0<> and
dup [char] $ = if drop $10 else
dup [char] # = if drop $0A else
[char] % = if $02 else exit
then then then base ! 1/string ;
: ?sign ( addr n -- addr' n' f )
over c@ $2C - dup abs 1 = and
dup if 1+ >r 1/string r> then ;
: >number ( u addr u -- u' addr' u' )
setbase
begin dup while
over c@ uppercase digit? 0= if drop exit then
>r rot base @ * r> + -rot
1/string
repeat ;
: ?number ( c-addr -- n -1 | c-addr 0 )
base @ >r
dup 0 0 rot count
?sign >r >number if rdrop 2drop drop 0
else 2swap 2drop drop r> if negate then
true then r> base ! ;
: ( [char] ) word drop ; immediate
: source# @ >in ! ; immediate