--- gforth/Attic/kernal.fs 1995/11/09 18:06:20 1.47 +++ gforth/Attic/kernal.fs 1995/11/30 18:01:48 1.49 @@ -1338,7 +1338,7 @@ Defer key ( -- c ) \ core tib /line loadfile @ ?dup IF read-line throw - ELSE loadline @ 0< IF 2drop false EXIT THEN + ELSE sourceline# 0< IF 2drop false EXIT THEN accept true THEN 1 loadline +! @@ -1380,14 +1380,14 @@ create nl$ 1 c, A c, 0 c, \ gnu includes \ include-file 07apr93py : push-file ( -- ) r> - loadline @ >r loadfile @ >r + sourceline# >r loadfile @ >r blk @ >r tibstack @ >r >tib @ >r #tib @ >r >tib @ tibstack @ = IF r@ tibstack +! THEN tibstack @ >tib ! >in @ >r >r ; : pop-file ( throw-code -- throw-code ) dup IF - source >in @ loadline @ loadfilename 2@ + source >in @ sourceline# sourcefilename error-stack dup @ dup 1+ max-errors 1- min error-stack ! 6 * cells + cell+ @@ -1455,7 +1455,8 @@ create pathfilenamebuf 256 chars allot \ pathfilenamebuf swap ; create included-files 0 , 0 , ( pointer to and count of included files ) -create image-included-files 0 , 0 , ( pointer to and count of included files ) +here ," the terminal" dup c@ swap 1 + swap , A, here 2 cells - +create image-included-files 1 , A, ( pointer to and count of included files ) \ included-files points to ALLOCATEd space, while image-included-files \ points to ALLOTed objects, so it survives a save-system @@ -1463,6 +1464,20 @@ create image-included-files 0 , 0 , ( po \ a-addr 2@ produces the current file name ( c-addr u ) included-files 2@ drop loadfilename# @ 2* cells + ; +: sourcefilename ( -- c-addr u ) \ gforth + \ the name of the source file which is currently the input + \ source. The result is valid only while the file is being + \ loaded. If the current input source is no (stream) file, the + \ result is undefined. + loadfilename 2@ ; + +: sourceline# ( -- u ) \ gforth sourceline-number + \ the line number of the line that is currently being interpreted + \ from a (stream) file. The first line has the number 1. If the + \ current input source is no (stream) file, the result is + \ undefined. + loadline @ ; + : init-included-files ( -- ) image-included-files 2@ 2* cells save-string drop ( addr ) image-included-files 2@ nip included-files 2! ; @@ -1629,8 +1644,8 @@ DEFER DOERROR ; : (DoError) ( throw-code -- ) - loadline @ IF - source >in @ loadline @ 0 0 .error-frame + sourceline# IF + source >in @ sourceline# 0 0 .error-frame THEN error-stack @ 0 ?DO -1 error-stack +! @@ -1770,7 +1785,7 @@ Defer 'cold ' noop IS 'cold : boot ( path **argv argc -- ) argc ! argv ! cstring>sstring pathstring 2! main-task up! sp@ dup s0 ! $10 + dup >tib ! tibstack ! #tib off >in off - rp@ r0 ! fp@ f0 ! cold ; + rp@ r0 ! fp@ f0 ! ['] cold catch DoError bye ; : bye ( -- ) \ tools-ext script? 0= IF cr THEN 0 (bye) ;