On Mon, 25 Jul 2011 at 14:42:12 +0200, Anton Ertl wrote:
>On Sun, Jul 24, 2011 at 09:10:33PM -0400, Josh Grams wrote:
>> Are there other gotchas that I need to watch out for?
>
>None come to my mind.

Cool, thanks.

Actually memory allocation is a bit of a problem with that version; you
have to pass it a non-transient string, and I'd rather not repeatedly
allocate the filename string.  So here's one which handles allocation.
I haven't tested extensively, but it seems to work for me.

--Josh

: ?included ( c-addr u -- c-addr' u flag )
        \G If the file @var{c-addr u} is in the list of earlier included
        \G files, return @code{true} and the matching filename string
        \G @var{c-addr' u} from the list, otherwise return @code{false} and
        \G the original string.
    included-files 2@  2 cells * bounds ?do
                2dup i 2@ str= if 2drop i 2@ true unloop exit then
        2 cells +loop false ;

: >sourcefile ( u.line# c-addr u -- )
        ?included 0= if save-mem 2dup add-included-file then
        loadfilename 2!  1- loadline ! ;

: #line ( "N "filename"" -- )
        parse-word evaluate  [char] "
                dup parse -trailing abort" expected filename string" drop
        parse cr >sourcefile ;

Reply via email to