Steve Fink <[EMAIL PROTECTED]> wrote:
> I am experimenting with registering my own compiler for the "regex"
> language, but the usage is confusing. It seems that the intention is
> that compilers will return a code object that gets invoked, at which
> time it runs until it hits an C<end> opcode. But what if I want to
> return some values from the compiled code? I see the following
> options:
An Eval object isa Closure. The only difference to a subroutine is IIRC,
that if supports direct jumps out of the evaled code segment via the
inter-segment branch_cs opcode:
# LAB:
# eval("goto LAB if ($i==6)");
The branch_cs thingy is kind of a hack. It would be better to get rid
of that and just return per continuation.
And: the runloop is executed until it hits either an C<end> opcode or
it invokes a (return) continuation with A NULL destination.
Thus it should be totally valid to return a Sub or Closure object from
your compiler. The C<invoke> of these two handles the packfile segment
switching.
> $P0 = compreg "pig-latin"
> $P1 = compile $P0, "eturnray oneay oremay anthay asway assedpay inay"
> $I0 = $P1(41)
> print $I0 # Should print out 42
That's fine.
leo