tonyrog / ffe

Forth Flavoured Erlang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Forth Flavoured Erlang

This is forth on steorids in an Erlang environment send and receiving message running in parallell.

And it is nearly functional ...

module based forth.

words are organized into modules/vocabularies, words are called by using :, built in words are access directly without the : module separator.

The words in interactive mode are added into a special module.

: sqr dup * ;

Run like this

$ ./priv/ffe.sh
 ok 
: sqr dup * ; ok
12 sqr . 144 ok

Or

echo ": sqr dup * ; 12 sqr ." | ./priv/ffe.sh

In a module:

\ module foo

\ ( x -- (x*x) )
: sqr dup * ;

\ ( <a1> .. <an> <n> -- <sum> )
: sum 0 do + loop ;

If compiled then this is translated into the module foo.

-module(foo).
-export(['_ffe_sqr'/0,'_ffe_sum'/0]).

'_ffe_sqr'() ->
    { 0, <<"sqr">>, fun ffe:docol/4, fun ffe:star/0, fun ffe:semis/0 }).

'_ffe_sum'() ->
    { 0, <<"sum">>, fun ffe:docol/4, fun ffe:lit/4, 0, 
      fun ffe:pdo/0, fun fee:plus/0, fun ffe:ploop/0, -2,
     ffe:semis/0 }.

CREATE DOES>

How do you compile CREATE DOES> in ffe? let's show an example.

: my-constant CREATE , DOES> @ ;

Compiles into

my-constant = 
  fun() -> {0,<<"my-constant">>, fun ffe:docol/4,
            fun ffe:'_ffe_create/0,
            fun ffe:comma/0,
            fun ffe:'ffe_does'/0,
            fun ffe:'ffe_fetch'/0,
            fun ffe:semis/0 }
  end.

This is a defining word that creat a constant used like this

10 my-constant ten

This compiles into

ten = 
  fun() -> {0, <<"ten">>, fun ffe:does1/4, 

About

Forth Flavoured Erlang


Languages

Language:Erlang 69.0%Language:C 28.1%Language:Makefile 1.2%Language:Assembly 1.1%Language:Forth 0.5%Language:Shell 0.1%