New lib module - 'libjtable.fs'

David McNab <[email protected]> Thu, 28 Oct 2004 18:39:55 +1300
Newsgroups gmane.comp.lang.forth.picforth
Message-ID <[email protected]>
Hi,

I've just written a picforth module (attached) for implementing
'jump tables'.

Example usage:

   needs libjtable.fs

   : func1  ... ;
   : func2  ... ;
   : func3  ... ;

   jtable myjump
       func1 t,
       func2 t,
       func3 t,
   end-table

   main : main
     c" About to invoke jumptable" tty-putsl
     1 myjump
     c" Back from jumptable" tty-putsl
   ;

Alternatively, you can declare constants while defining the table, to 
simulate the sorely-missed ' and execute keywords:

   jtable execute
       func1 t,   0 constant 'func1
       func2 t,   1 constant 'func2
       func3 t,   2 constant 'func3
   end-table

   main : main
       tty-init
       c" About to invoke jumptable" tty-putsl
       'func1 execute
       'func2 execute
       c" Back from jumptable" tty-putsl
   ;

Enjoy!

-- 
Cheers
David

_______________________________________________
PicForth mailing list
[email protected]
http://lists.rfc1149.net/mailman/listinfo/picforth
libjtable.fs (text/plain, 249 B)
\ Provides jump table primitives

host

: element-jtable ( xt -- ) goto ;

meta

: jtable ( "name" -- start endxt elemxt )
    reachable tcshere ['] end-ftable ['] element-jtable
    meta> :: >w
    return-in-w pcl ,f addwf
    -tcompile
;

target