Hmmm...

Wouldn't a C compiler want to return a sub that invoked the main()
(if there was one)? And, if there wasn't one, wouldn't the C compiler
want to return a sub that raised an exception?


Regards,

-- Gregor

Dan Sugalski wrote:
At 11:03 PM -0700 8/21/04, Steve Fink 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?


Here's what's supposed to happen.

The compile op only compiles the code passed in, it doesn't execute it. The returned sub object represents the entire code chunk that was compiled, and likely ought to be immediately executed itself.

As a perl example, the eval function should give code like:

    compiler = compreg "Perl5"
    eval_pmc = compile compiler, my_source
    eval_pmc()

though the eval_pmc() call ought to check and see if it got anything in return.

This does mean that if you skip the invocation of the returned PMC that things may not happen. This is fine. And for many languages the returned PMC won't actually do anything at all when invoked.

It's important to note that the returned PMC does *not* represent any particular sub in the source -- rather it represents the entire source module. So if the language was C, for example, the returned PMC wouldn't do anything since C doesn't allow you to have code outside functions.

Reply via email to