--- gforth/see.fs 1997/06/01 20:50:39 1.17 +++ gforth/see.fs 2000/03/11 20:35:05 1.25 @@ -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 @@ -69,8 +72,9 @@ DEFER nlcount ' noop IS nlcount nlflag @ IF (nl) nlflag off THEN XPos @ over + cols u>= IF (nl) THEN ; -: c-to-upper - dup [char] a >= over [char] z <= and if bl - then ; +: c-to-upper ( c1 -- c2 ) \ gforth + \ nac05feb1999 there is a primitive, toupper, with this function + dup [char] a >= over [char] z <= and if bl - then ; : ctype ( adr len -- ) warp? dup XPos +! C-Output @ @@ -132,7 +136,7 @@ VARIABLE SearchPointer \ The branchtable consists of three entrys: \ address of branch , branch destination , branch type -CREATE BranchTable 500 allot +CREATE BranchTable 128 cells allot here 3 cells - ACONSTANT MaxTable @@ -232,42 +236,24 @@ VARIABLE C-Pass : back? ( n -- flag ) 0< ; : ahead? ( n -- flag ) 0> ; -: c-(compile) - Display? - IF - s" POSTPONE " Com# .string - dup @ look 0= ABORT" SEE: No valid XT" - name>string 0 .string bl cemit - THEN - cell+ ; - : c-lit Display? IF dup @ dup abs 0 <# #S rot sign #> 0 .string bl cemit 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 ; @@ -373,10 +359,6 @@ VARIABLE C-Pass : c-for Display? IF nl S" FOR" .struc level+ THEN ; -: .name-without -\ prints a name without () e.g. (+LOOP) - 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+ @@ -403,10 +385,6 @@ VARIABLE C-Pass THEN Debug? IF drop THEN ; -: c-does> \ end of create part - Display? IF S" DOES> " Com# .string THEN - Cell+ cell+ ; - : c-abort" count 2dup + aligned -rot Display? @@ -416,31 +394,49 @@ VARIABLE C-Pass ELSE 2drop THEN ; +[IFDEF] (does>) +: c-does> \ end of create part + Display? IF S" DOES> " Com# .string THEN + maxaligned /does-handler + ; +[THEN] + +[IFDEF] (compile) +: c-(compile) + Display? + IF + s" POSTPONE " Com# .string + dup @ look 0= ABORT" SEE: No valid XT" + name>string 0 .string bl cemit + THEN + cell+ ; +[THEN] CREATE C-Table - ' lit A, ' c-lit A, - ' (s") A, ' c-s" A, - ' (.") A, ' c-." A, - ' "lit A, ' c-c" 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, + ' (abort") A, ' c-abort" A, +\ only defined if compiler is loaded +[IFDEF] (compile) ' (compile) A, ' c-(compile) A, [THEN] +[IFDEF] (does>) ' (does>) A, ' c-does> A, [THEN] + 0 , here 0 , avariable c-extender c-extender ! @@ -527,7 +523,11 @@ IS discode : seecode ( xt -- ) dup s" Code" .defname - >body discode + threading-method + if + >code-address + then + discode ." end-code" cr ; : seevar ( xt -- ) s" Variable" .defname cr ; @@ -572,7 +572,7 @@ IS discode if seedoes EXIT then - dup forthstart u< + dup xtprim? if seecode EXIT then @@ -581,9 +581,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 ; @@ -615,10 +621,15 @@ IS discode then rdrop drop ; -: see ( "name" -- ) \ tools +: see ( "name" -- ) \ tools + \G Locate @var{name} using the current search order. Display the + \G definition of @var{name}. Since this is achieved by decompiling + \G the definition, the formatting is mechanised and some source + \G information (comments, interpreted sequences within definitions + \G etc.) is lost. name find-name dup 0= IF - drop -&13 bounce + drop -&13 throw THEN name-see ;