
Ficl: An Embeddable Extension Language Interpreter
by John Sadler


Example 1:

hex
10000 constant leds
10002 constant switches
20000 constant adc
20002 constant dac

Example 2:

: !oreg  ( value -- )   leds c! ; 
: @adc   ( -- value )   adc c@ ;
: !dac   ( value -- )   dac c! ;
: @ireg  ( -- value )   switches c@ ;

Example 3:

variable led-shadow   0 led-shadow !
: !leds  ( value -- )   dup !oreg led-shadow ! ;
0 !leds

Example 4:

: toggle-led  ( led -- ) 
    1 swap lshift    \ make a bit-mask for the LED
    led-shadow @ xor \ toggle the bit in the shadow reg
    !oreg            \ now update the LED and shadow
;

Example 5:

: adc-loop
    begin 
        @adc dup !dac 100 msec 
    255 = until 
;


Listing One

FICL_VM *pVM;
ficlInitSystem(10000); /* create a 10,000 cell dictionary */
pVM = ficlNewVM();

for (;;)
{
    int ret;
    gets(in);
    ret = ficlExec(pVM, in);
    if (ret == VM_USEREXIT)
    {
        ficlTermSystem();
        break;
    }
}


Listing Two
/* Ficl interface to _chdir (Win32)
** Gets a newline (or NULL) delimited string from the input
** and feeds it to the Win32 chdir function...
** Usage example:
**    cd c:\tmp
*/
static void ficlChDir(FICL_VM *pVM)
{
    FICL_STRING *pFS = (FICL_STRING *)pVM->pad;
    vmGetString(pVM, pFS, '\n');
    if (pFS->count > 0)
    {
        int err = _chdir(pFS->text);
        if (err)
        {
            vmTextOut(pVM, "Error: path not found", 1);
            vmThrow(pVM, VM_QUIT);
        }
    }
    return;
}
/* Here's the corresponding ficlBuild call... 
** ficlBuild("cd",       ficlChDir,    FW_DEFAULT);
*/



2


