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:
1) Manually set up the return values in the appropriate registers. 2) Use .pcc_begin_return/.pcc_end_return to set up the return values, but override the P1 return continuation to go to some subroutine that immediately calls C<end>. 3) Use .pcc_begin_return/.pcc_end_return to set up the return values, and have the user of the compiler grab out some magic-named subroutine using C<find_global> and invoke it rather than directly invoking the return value of the C<compile> op. 4) Make my compiler behave differently from the built-in compilers, by arranging for it to return a Sub object from the C<compile> op rather than an Eval object. Then the caller can directly invoke the return value of C<compile> and get back return values as if it were calling a normal subroutine, because it is. #1 is painful and extremely error-prone. #2 is a total hack. #3 forces the user of the compiler to not only call things differently depending on which language it's using, but also it has to know the magic subroutine name #4 seems to make compilers inconsistent with each other, and I worry that the Eval PMC does more than just running code until it hits an C<end> op. If my explanation was confusing, then here are some examples. I expect the user of the compiler to look like this: $P0 = compreg "pig-latin" $P1 = compile $P0, "eturnray oneay oremay anthay asway assedpay inay" $I0 = $P1(41) print $I0 # Should print out 42 Option #3 would change this to $P0 = compreg "pig-latin" compile $P0, "eturnray oneay oremay anthay asway assedpay inay" $P1 = find_global "_pig_latin_eval_block" $I0 = $P1(41) print $I0 # Should print out 42 Rather than writing out example code for the compiler and generated code to illustrate each of the cases, I think I'll wait to see if this needs clarification first. :-)