On Mon, 15 Apr 2002, Jerome Quelin wrote:

> * Befunge does not support named subroutines. So I have to provide a way in
> order to simulate this. I thought about the following:
>
>       use Inline Befunge;
>       print "9 + 16 = ", add(9, 16), "\n";
>       print "9 - 16 = ", subtract(9, 16), "\n";
>       __END__
>       __Befunge__
>       BF add
>       +q
>       BF substract
>       -q
>
> This means I'm parsing (via the Inline::Befugne::build() sub) the Befunge
> space and split on the pattern /BF (.+)/,

Sounds good.

> creating a hash ref:
>     { add => '+q',
>       substract => '-q' }
> that I'm storing in the Inline object in the ILSM section.

Now you've lost me.  Don't create hash-refs, create subroutines in the
package that wants to Inline Befunge.  If that didn't make any sense feel
free to take a look at my Inline::Guile module.  In load(), I loop over
functions and bind them into the calling package like this:

   # got a live one, register it
   no strict 'refs';
   *{"${pkg}::$name"} = sub { Guile::apply($proc, [@_]); }

Replace that Guile::apply() with the appropriate Language::Befunge call
and you should be in business.

> * Another question. Let's assume the calling part work. Since Befunge is
> stack based, I have to push the params onto the stack. Furthermore, since it
> only understands integers, I have to translate strings into "0gnirts" (that
> is, a zero terminated serie of integers mapping the ordinal values of the
> chars). So, how can I fetch the args provided to the sub?

Er, using @_?  In the example above I pass args to my Guile functions as a
ref to to contents of @_.  You could replace that with a call to a routine
that turns the contents of @_ into integers and pushes them onto the
stack.

-sam


Reply via email to