--- gforth/see.fs 1997/01/29 21:32:38 1.15 +++ gforth/see.fs 1997/07/06 14:29:34 1.18 @@ -25,7 +25,10 @@ \ Ideas: Level should be a stack +require look.fs require termsize.fs +require wordinfo.fs +[IFUNDEF] .name : .name name>string type space ; [THEN] decimal @@ -56,7 +59,7 @@ DEFER nlcount ' noop IS nlcount : nl nlflag on ; : (nl) nlcount - XPos @ Level @ = ?Exit + XPos @ Level @ = IF EXIT THEN \ ?Exit C-Formated @ IF C-Output @ IF C-Clearline @ IF cols XPos @ - spaces @@ -108,7 +111,7 @@ VARIABLE Colors Colors on : .struc uppercase on Str# .string ; -\ CODES 15may93jaw +\ CODES (Branchtypes) 15may93jaw 21 CONSTANT RepeatCode 22 CONSTANT AgainCode @@ -118,21 +121,30 @@ VARIABLE Colors Colors on 11 CONSTANT AheadCode 13 CONSTANT WhileCode2 14 CONSTANT Disable +15 CONSTANT LeaveCode + \ FORMAT WORDS 13jun93jaw VARIABLE C-Stop VARIABLE Branches -VARIABLE BranchPointer +VARIABLE BranchPointer \ point to the end of branch table VARIABLE SearchPointer + +\ The branchtable consists of three entrys: +\ address of branch , branch destination , branch type + CREATE BranchTable 500 allot here 3 cells - ACONSTANT MaxTable : FirstBranch BranchTable cell+ SearchPointer ! ; -: (BranchAddr?) ( a-addr -- a-addr true | false ) +: (BranchAddr?) ( a-addr1 -- a-addr2 true | false ) +\ searches a branch with destination a-addr1 +\ a-addr1: branch destination +\ a-addr2: pointer in branch table SearchPointer @ BEGIN dup BranchPointer @ u< WHILE @@ -161,6 +173,20 @@ ACONSTANT MaxTable 2drop true THEN ; +: MyBranch ( a-addr -- a-addr a-addr2 ) +\ finds branch table entry for branch at a-addr + dup @ over + + BranchAddr? + BEGIN + WHILE 1 cells - @ + over <> + WHILE dup @ over + + MoreBranchAddr? + REPEAT + SearchPointer @ 3 cells - + ELSE true ABORT" SEE: Table failure" + THEN ; + \ \ addrw addrt \ BEGIN ... WHILE ... AGAIN ... THEN @@ -224,39 +250,32 @@ VARIABLE C-Pass THEN cell+ ; -: c-s" - count 2dup + aligned -rot - Display? - IF [char] S cemit [char] " cemit bl cemit 0 .string - [char] " cemit bl cemit - ELSE 2drop - THEN ; - -: c-." - count 2dup + aligned -rot - Display? - IF [char] . cemit - [char] " cemit bl cemit 0 .string - [char] " cemit bl cemit - ELSE 2drop - THEN ; +: .name-without ( addr -- addr ) +\ prints a name without () e.g. (+LOOP) or (s") + dup 1 cells - @ look + IF name>string over c@ '( = IF 1 /string THEN + 2dup + 1- c@ ') = IF 1- THEN .struc ELSE drop + THEN ; : c-c" + Display? IF nl .name-without THEN count 2dup + aligned -rot Display? - IF [char] C cemit [char] " cemit bl cemit 0 .string + IF bl cemit 0 .string [char] " cemit bl cemit ELSE 2drop THEN ; -: Forward? ( a-addr true | false -- ) +: Forward? ( a-addr true | false -- a-addr true | false ) +\ a-addr1 is pointer into branch table +\ returns true when jump is a forward jump IF dup dup @ swap 1 cells - @ - Ahead? IF true ELSE drop false THEN \ only if forward jump ELSE false THEN ; -: RepeatCheck +: RepeatCheck ( a-addr1 a-addr2 true | false -- false ) IF BEGIN 2dup 1 cells - @ swap dup @ + u<= @@ -295,13 +314,17 @@ VARIABLE C-Pass IF drop S" REPEAT " .struc nl ELSE S" AGAIN " .struc nl THEN - ELSE dup cell+ BranchAddr? Forward? - IF dup cell+ @ WhileCode2 = - IF nl S" ELSE" .struc level+ - ELSE level- nl S" ELSE" .struc level+ THEN - cell+ Disable swap ! - ELSE S" AHEAD" .struc level+ - THEN + ELSE MyBranch cell+ @ LeaveCode = + IF S" LEAVE " .struc + ELSE + dup cell+ BranchAddr? Forward? + IF dup cell+ @ WhileCode2 = + IF nl S" ELSE" .struc level+ + ELSE level- nl S" ELSE" .struc level+ THEN + cell+ Disable swap ! + ELSE S" AHEAD" .struc level+ + THEN + THEN THEN THEN Debug? @@ -309,19 +332,6 @@ VARIABLE C-Pass ELSE cell+ THEN ; -: MyBranch ( a-addr -- a-addr a-addr2 ) - dup @ over + - BranchAddr? - BEGIN - WHILE 1 cells - @ - over <> - WHILE dup @ over + - MoreBranchAddr? - REPEAT - SearchPointer @ 3 cells - - ELSE true ABORT" SEE: Table failure" - THEN ; - : DebugBranch Debug? IF dup @ over + swap THEN ; \ return 2 different addresses @@ -344,7 +354,10 @@ VARIABLE C-Pass level- nl S" WHILE " .struc level+ - ELSE nl S" IF " .struc level+ + ELSE MyBranch cell+ @ LeaveCode = + IF s" 0= ?LEAVE " .struc + ELSE nl S" IF " .struc level+ + THEN THEN THEN THEN @@ -354,12 +367,16 @@ VARIABLE C-Pass : c-for Display? IF nl S" FOR" .struc level+ THEN ; -: .name-without - dup 1 cells - @ look IF name>string 1 /string 1- .struc ELSE drop THEN ; - : c-loop Display? IF level- nl .name-without bl cemit nl THEN - DebugBranch cell+ cell+ ; + DebugBranch cell+ + Scan? + IF dup BranchAddr? + BEGIN WHILE cell+ LeaveCode swap ! + dup MoreBranchAddr? + REPEAT + THEN + cell+ ; : c-do Display? IF nl .name-without level+ THEN ; @@ -368,14 +385,6 @@ VARIABLE C-Pass Display? IF nl S" ?DO" .struc level+ THEN DebugBranch cell+ ; -: c-leave - Display? IF S" LEAVE " .struc THEN - Debug? IF dup @ + THEN cell+ ; - -: c-?leave - Display? IF S" ?LEAVE " .struc THEN - cell+ DebugBranch swap cell+ swap cell+ ; - : c-exit dup 1 cells - CheckEnd IF Display? IF nlflag off S" ;" Com# .string THEN @@ -399,31 +408,30 @@ VARIABLE C-Pass CREATE C-Table - ' lit A, ' c-lit A, - ' (s") A, ' c-s" A, - ' (.") A, ' c-." A, - ' "lit A, ' c-c" A, - comp' leave drop A, ' c-leave A, - comp' ?leave drop A, ' c-?leave A, - ' (do) A, ' c-do A, - ' (+do) A, ' c-do A, - ' (u+do) A, ' c-do A, - ' (-do) A, ' c-do A, - ' (u-do) A, ' c-do A, - ' (?do) A, ' c-?do A, - ' (for) A, ' c-for A, - ' ?branch A, ' c-?branch A, - ' branch A, ' c-branch A, - ' (loop) A, ' c-loop A, - ' (+loop) A, ' c-loop A, - ' (s+loop) A, ' c-loop A, - ' (-loop) A, ' c-loop A, - ' (next) A, ' c-loop A, - ' ;s A, ' c-exit A, - ' (does>) A, ' c-does> A, - ' (abort") A, ' c-abort" A, - ' (compile) A, ' c-(compile) A, - 0 , here 0 , + ' lit A, ' c-lit A, + ' (s") A, ' c-c" A, + ' (.") A, ' c-c" A, + ' "lit A, ' c-c" A, +[IFDEF] (c") ' (c") A, ' c-c" A, [THEN] + ' (do) A, ' c-do A, +[IFDEF] (+do) ' (+do) A, ' c-do A, [THEN] +[IFDEF] (u+do) ' (u+do) A, ' c-do A, [THEN] +[IFDEF] (-do) ' (-do) A, ' c-do A, [THEN] +[IFDEF] (u-do) ' (u-do) A, ' c-do A, [THEN] + ' (?do) A, ' c-?do A, + ' (for) A, ' c-for A, + ' ?branch A, ' c-?branch A, + ' branch A, ' c-branch A, + ' (loop) A, ' c-loop A, + ' (+loop) A, ' c-loop A, +[IFDEF] (s+loop) ' (s+loop) A, ' c-loop A, [THEN] +[IFDEF] (-loop) ' (-loop) A, ' c-loop A, [THEN] + ' (next) A, ' c-loop A, + ' ;s A, ' c-exit A, + ' (does>) A, ' c-does> A, + ' (abort") A, ' c-abort" A, + ' (compile) A, ' c-(compile) A, + 0 , here 0 , avariable c-extender c-extender ! @@ -446,12 +454,12 @@ c-extender ! ; : BranchTo? ( a-addr -- a-addr ) - Display? IF dup BranchAddr? + Display? IF dup BranchAddr? IF BEGIN cell+ @ dup 20 u> IF drop nl S" BEGIN " .struc level+ ELSE - dup Disable <> + dup Disable <> over LeaveCode <> and IF WhileCode2 = IF nl S" THEN " .struc nl ELSE level- nl S" THEN " .struc nl THEN @@ -468,7 +476,10 @@ c-extender ! dup >r DoTable r> swap IF drop EXIT THEN Display? IF look 0= IF drop dup 1 cells - @ . \ ABORT" SEE: Bua!" - ELSE dup cell+ count 31 and rot wordinfo .string THEN bl cemit + ELSE + dup cell+ count dup immediate-mask and + IF bl cemit ." POSTPONE " THEN + 31 and rot wordinfo .string THEN bl cemit ELSE drop THEN ; @@ -552,7 +563,7 @@ IS discode if seedoes EXIT then - dup forthstart u< + dup xtprim? if seecode EXIT then @@ -561,9 +572,15 @@ IS discode docon: of seecon endof docol: of seecol endof dovar: of seevar endof +[ [IFDEF] douser: ] douser: of seeuser endof +[ [THEN] ] +[ [IFDEF] dodefer: ] dodefer: of seedefer endof +[ [THEN] ] +[ [IFDEF] dofield: ] dofield: of seefield endof +[ [THEN] ] over >body of seecode endof 2drop abort" unknown word type" ENDCASE ;