[PicForth] New lib module - 'libjtable.fs'

David McNab david at rebirthing.co.nz
Thu Oct 28 07:39:55 CEST 2004


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
-------------- next part --------------
\ 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



More information about the PicForth mailing list