Fixed the uninitialized string error Nick pointed out, but as he noted, it
has no effect on the error.
Leopold Toetsch writes:
Will Coleda (via RT) wrote:
While I expect it to print "ok 1", it instead prints:
Null PMC access in invoke()
current instr.: 'main' pc 50 (compile.pir:8)
W/o testing it I'd say that ...
code .= "print \""
code .= printme
code .= "\\n\"\n"
... a single print statement isn't a subroutine, so it has to fail.
But this is the PASM compiler, not the PIR compiler - Attached find the
slightly more complicated example using a PIR sub instead of a PASM snippet
which dies in exactly the same fashion. (Which is to say, as the invokable
is invoked with <invokecc>). I even insure that the anonymous sub is not
reused by dynamically creating a .sub name, though for this particular
example it's irrelevant.
(Note: the subject "PIR compilers" was referring to "compilers written in
PIR", as opposed to the compilers written in C. (as opposed to being opposed
to the PASM compiler.))
.sub main @MAIN
register_compiler()
.local pmc compiler, invokable
compiler = compreg "PUTS"
invokable = compile compiler, "ok 1"
invokable()
.end
.sub register_compiler
.local pmc counter
counter = new Integer
counter = 0
store_global "counter", counter
$P0 = find_global "puts"
compreg "PUTS", $P0
.end
.sub puts
.param string printme
.local pmc pir_compiler, retval
pir_compiler = compreg "PIR"
.local pmc counter
counter = find_global "counter"
inc counter
.local string code
code = ".sub anonymous"
$S0 = counter
code .= $S0
code .= " @ANON\n"
code .= "print \""
code .= printme
code .= "\\n\"\n"
code .=".end\n"
retval = compile pir_compiler, code
.return (retval)
.end