• Toad User abort with cut: ... -cut

    From sjack@sjack@dontemail.me (sjack) to comp.lang.forth on Thu Oct 17 15:55:17 2024
    From Newsgroup: comp.lang.forth

    Toad doesn't have CATCH/THROW but FigForth provides user abort (ABORT) .
    Have BacForth type words in RTC vocabulary. Using BACK...TREK and
    CUT: ... -CUT made SNAPSHOT error handler to show stacks and return
    to cleanup code marked by CUT: . Not nearly as capable and slick as CATCH/THROW but adequate for my light-weight applications.

    Have CATCH/THROW in Frog but Toad is all about making full use of
    FigForth facilities (use of abundant vocabularies has been very
    entertaining, ain't KISS.)

    User abort with cut: ... -cut



    Some code

    -- SNAPSHOT
    -- User abort action
    -- dump data stack and top of return stack
    -- (return stack top holds the address of the word where the
    -- fault was detected. )
    -- Process each cut: cleanup location
    : SNAPSHOT
    RTC
    BEGIN
    -CUT
    cr ." --- (!) User abort: "
    cr ." Data stack: " s? xx
    cr ." Return : " r .
    cr ." --."
    cr
    LDEPTH 0= UNTIL
    cr ;

    -- YO
    -- Display some items of interest
    : YO
    rtc
    cr ." L-stack depth: " ldepth .
    cr ." LP : " lp@ . tab lp@ @ .
    +voc
    cr ." (ABORT) : " ' (ABORT) @ CELL+ NFA ID.
    cr ." UABORT : " dfa' uabort @ CELL+ NFA ID.
    cr ." FDIID : " fdiid . \ file id, zero after cleanup
    cr
    ;


    Success example

    "pad/txt" svdir sv! \ assign input path prefix
    ' snapshot is uabort \ assign user abort
    -uabort \ enable user abort
    -pause \ allow pausing
    fviews -p rubyatXLIX rubyatLI; \ view two files with pause option

    pad/txt/rubyatLI:

    LI.
    The Moving Finger writes; and, having writ,
    Moves on: nor all thy Piety nor Wit
    Shall lure it back to cancel half a Line,
    Nor all thy Tears wash out a Word of it.

    -more-

    pad/txt/rubyatXLIX:

    XLIX.
    Tis all a Chequer-board of Nights and Days,
    Where Destiny with Men for Pieces plays:
    Hither and thither moves, and mates, and slays,
    And one by one back in the Closet lays.
    +uabort \ disable user abort
    yo \ look at items of interest
    L-stack depth: 0
    LP : 134566380 -1
    (ABORT) : ABORT
    UABORT : SNAPSHOT
    FDIID : 0

    ..CURRENT and CONTEXT are WRK BASE: 10 Latest: YO


    Fail example

    -uabort
    fviews rubyatXLIX foo rubyatLI; \ foo doesn't exit, should fail

    pad/txt/rubyatLI:

    LI.
    The Moving Finger writes; and, having writ,
    Moves on: nor all thy Piety nor Wit
    Shall lure it back to cancel half a Line,
    Nor all thy Tears wash out a Word of it.


    pad/txt/foo:

    --- (!) User abort:
    Data stack: 134583709 10 134582004 -2 666
    Return : 134581372
    --.

    --- (!) User abort:
    Data stack: empty
    Return : 134582140
    --.

    --- (!) FVIEWS abandon
    +uabort
    yo
    L-stack depth: 0
    LP : 134566380 -1
    (ABORT) : ABORT
    UABORT : SNAPSHOT
    FDIID : 0

    ..CURRENT and CONTEXT are WRK BASE: 10 Latest: YO


    -fin-
    OK
    --
    me
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From sjack@sjack@dontemail.me (sjack) to comp.lang.forth on Thu Oct 17 18:25:09 2024
    From Newsgroup: comp.lang.forth

    Ha,ha. Fooled myself looking at file id (FDIID) for zero value to
    indicate cleanup took place. When file i/o failed because file foo
    didn't exist, FDIID never got set so was always zero. (there were
    other means of verifying that cleanup code got accessed, e.g. the
    "FVIEWS abandon' being printed.
    But to see FDIID being reset I needed to at least get the file opened
    and then have it fail. So just open a corrupt file. No! Whatever I
    put into a file, nulls and control characters, does not make the i/o
    fail! To have failure has to be done on my end in processing the
    data. So patched UABORT into a low level part that was acting
    on the data. Mission achomplished.
    --
    me
    --- Synchronet 3.20a-Linux NewsLink 1.114