Steve Fink wrote:
On Aug-26, Leopold Toetsch wrote:

.sub @regex_at_foo_imc_line_4711 # e.g.

Yes, this illustrates what I was really getting at. My compiler can
certainly take a subroutine name (or file and line number, or whatever)
to use to generate the code with, but what is the proper way to pass
that infomation in through the compile op?

I don't know how your compiler generates the code. But you are probably concatenating a string of PIR instructions and pass that over to the C<compile> opcode.
Anyway, the identifier you are using for the C<.sub> directive gets stored in globals and is the name of the subroutine.


... I can just stick it in some
register, but it seems like there ought to be some standard-ish way of
passing parameters to compilers. Which then makes me wonder why compile
is done as an opcode rather than a method invocation on the return value
of compreg.

C<compile> as a method call for the compiler would really be a worthwhile extension. But you can provide your own compiler wrapper and pass the subroutine name to that function. [1]


... I see that for Compiler and NCI PMCs, that's exactly what it
does, but for anything else it does the Parrot_runops_fromc_args_save
thing; couldn't that be somehow exposed separately so that the compile
op goes away? My only complaint about C<compile> is that it isn't
transparent how to use it, whereas I am comfortable with invoking things
and following the calling conventions.

Well, there isn't much difference. The compile function is called as a plain function. A method call would additionally pass C<self>, which you can pass as an argument too, if you need it.


leo

[1]

sub test @MAIN
    .local NCI compiler
    find_global compiler, "xcompile"
    compreg "XPASM", compiler
    .local pmc my_compiler
    my_compiler = compreg "XPASM"
    .local pmc the_sub
    .local string code
    code = "print \"ok\\n\"\n"
    code .= "end\n"
    the_sub = my_compiler("_foo", code)
    the_sub()
    the_sub = global "_foo"
    the_sub()
.end

.sub xcompile
    .param string sub_name
    .param string code
    $S0 = ".pcc_sub "
    $S0 .= sub_name
    $S0 .= ":\n"
    $S0 .= code
    .local NCI pasm_compiler
    pasm_compiler = compreg "PASM"
    # print $S0
    $P0 = compile pasm_compiler, $S0
    .pcc_begin_return
        .return $P0
    .pcc_end_return
.end



Reply via email to