home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
dmp.seq
< prev
next >
Wrap
Text File
|
1990-05-18
|
7KB
|
206 lines
\ DMP.SEQ
0 value dmp_seg 0 value dmp_end
6000 array sym_buf 0 value sym_len
handle afile
: @T ( a1 -- n1 )
dmp_seg swap @L ;
: C@T ( a1 -- n1 )
dmp_seg swap C@L ;
: read_fl ( a1 n1 a2 n2 seg -- n3 )
>r >r >r ">$ afile $>handle
afile hopen abort" Couldn't open"
r> r> afile r> exhread ( -- n3 ) \ length returned
afile hclose drop ;
: read_dmp ( -- )
dmp_seg 0=
if 12500 paragraph alloc 8 = abort" Failed to allocate!"
=: dmp_seg drop
then
dmp_seg 0 12500 0 LFILL
" test.cpm" $100 12000 dmp_seg read_fl $100 + =: dmp_end
" test.sym" sym_buf 6000 ?ds: read_fl =: sym_len ;
32 array nbuf
: >>name ( a1 -- name )
save> base hex
>r
sym_buf sym_len
begin over 4 here place here count + off
here number? 2drop dup r@ <>
2 pick 0> and
while drop $0A scan 1 /string
repeat r> =
if 5 /string 2dup $0D scan nip - nbuf place
else 2drop nbuf off
then nbuf
restore> base ;
: >>find ( a1 -- a2 )
save> base hex
>r
sym_buf sym_len
begin 2dup 5 /string
2dup $0D scan nip - r@ count rot max caps-comp dup
2 pick 0> and
while drop $0A scan 1 /string
repeat r>drop 0=
if drop 4 here place here count + off
here number? 2drop
else 2drop false
then
restore> base ;
0 value sym_point
0 value rem_len
: next_sym ( -- a1 n1 ) \ a1 = start n1 = len
rem_len 0=
if sym_point 0 exit
then
save> base hex
sym_point rem_len
over 4 here place here count + off
here number? 2drop >r
$0A scan 1 /string =: rem_len dup =: sym_point
4 here place here count + off
r> here number? 2drop over -
over dmp_end swap - umin
restore> base ;
\ CR 2DUP SWAP 3 .R 3 .R DEPTH 3 .R SPACE ;
: sym_reset ( -- )
sym_buf 2+ =: sym_point
sym_len 2- 0max =: rem_len ;
$100 CONSTANT ORIGIN
$108 CONSTANT DPUSH
$109 CONSTANT HPUSH
$10A CONSTANT >NEXT
$110 CONSTANT >NEXT1
$115 CONSTANT NEST
$126 CONSTANT DODOES
$137 CONSTANT DOCREATE
$13C CONSTANT DOCONSTANT
$145 CONSTANT DODEFER
$14E CONSTANT RP0
$150 CONSTANT RP
$152 CONSTANT SP0
$154 CONSTANT VOC-INIT
0 value |"
0 value |lit
0 value |do
0 value |?do
0 value |loop
0 value |+loop
0 value |?branch
0 value |branch
: inline_init ( -- )
" (x)" over '"' swap 1+ c! \ fix "
">$ >>find =: |"
" (lit)" ">$ >>find =: |lit
" (do)" ">$ >>find =: |do
" (?do)" ">$ >>find =: |do
" (loop)" ">$ >>find =: |loop
" (+loop)" ">$ >>find =: |+loop
" ?branch" ">$ >>find =: |?branch
" branch" ">$ >>find =: |branch ;
: h.2 ( n1 -- )
save> base hex
0 <# # # #> type space
restore> base ;
: $dump ( a1 -- n1 )
dup c@T dup h.2 ." {" dup>r swap 1+ swap 0
?do dup i + c@T emit
loop drop ." } " r> 3 + ;
: dumpT ( a1 n1 -- )
dup ." length = " u. rmargin @ ?line
bounds
?do ?cr i c@T h.2 ?keypause
loop ;
: ?inline ( a1 n1 -- a1 n1 n2 )
over @T
case
|" of over 2+ $dump endof
|lit of over 2+ @T h. 4 endof
|do of over 2+ @T h. 4 endof
|?do of over 2+ @T h. 4 endof
|loop of over 2+ @T h. 4 endof
|+loop of over 2+ @T h. 4 endof
|?branch of over 2+ @T h. 4 endof
|branch of over 2+ @T h. 4 endof
drop 2
endcase ;
: ||: ( a1 n1 -- )
2 /string
begin ?cr over @T >>name dup c@ 0=
if drop over @T h. 2
else count dup 1+ ?line type space
?inline
then /string ?dup 0= ?keypause
until drop ;
: ||create ( a1 n1 -- )
drop ." VARIABLE " 2+ @T h. ;
: ||defer ( a1 n1 -- )
drop ." DEFER " 2+ @T dup h. ?dup
if >>name count type
then ;
: ||constant ( a1 n1 -- )
drop ." CONSTANT " 2+ @T h. ;
: ||unknown ( a1 n1 -- )
." UNKNOWN " dumpT ;
: ?.word ( a1 n1 -- )
over @T
case
nest of ||: endof
docreate of ||create endof
dodefer of ||defer endof
doconstant of ||constant endof
drop
||unknown
endcase ;
: dmp ( -- )
decimal
dosio_init
caps on
?ds: sseg !
$fff0 set_memory
16 tabsize !
16 lmargin !
74 rmargin !
read_dmp
inline_init
sym_reset
begin next_sym ?dup
?keypause
while cr
over h.
over >>name count type tab
over dup @T 2- =
if ." CODE " dumpT
else ?.word
then
repeat drop cr ;