Hi,

I am trying to implement the 'eval' macro im Parrot m4. The Parrot m4
interpreter is implemented in PIR. The 'eval' is a simple interpreter for
integer artithmetic and forms thus a micro language within a mini language.

For implementing the 'eval' macro I took following approach:

i. Implement a 'm4_eval_compiler' in C, based on 'examples/compilers/japh.c'  
ii. When encountering something likeexamples/compilers

eval(`1 + 1')

I extract the string "1 + 1". and compile it
iii. The compiler returns a .Sub which can be invoked.

In a test script this looks like:
 
.sub _main
    .local pmc m4_eval_compiler_lib
    m4_eval_compiler_lib = loadlib "m4_eval_compiler"
    compreg P1, "m4_eval_compiler"
    .local string code
    code = '1 + 1'
    .local pmc compiled_code
    compiled_code = compile P1, code
    invoke compiled_code
    AFTER_INVOCATION: print "compiled sub has been invoked\n"
    end
.end

This works almost as expected. The problem is that I never get to the label
AFTER_INVOCATION. So here are my questions:

Is there a way to tell 'compiled_code' to continue with 'AFTER_INVOKATION' when
it is invoked? 
This might be analogous to newsub(out PMC, in INT, labelconst INT).
Can I use 'invokecc' for that?
Am I completely on the wrong track?
How can I retrieve return values from 'compiled_code'?

CU, Bernhard
CU, Bernhard



Reply via email to