.sub foo @ANON
creates an anonymous subroutine. It's available with the normal call syntax:
x = foo(y)
in the same module[1], as this syntax translates roughly to:
set_p_pc P0, foo
invoke
where "foo" is a visible clue for the index in the constant table, where
the Sub PMC is located.
But:
$I0 = global "foo"
fails and throws an exception.
Feedback welcome, especially WRT some defaults for code created via
compreg/compile,
leo
[1] in the sense: everything that got compiled in one piece.
> I've checked in intial support for anonymous subroutines.
>
> .sub foo @ANON
>
> creates an anonymous subroutine.
Cool.
I can't seem to combine it with "non_prototyped".
- Sam Ruby
> I can't seem to combine it with "non_prototyped".
.sub "foo" @ANON, non_prototyped
> - Sam Ruby
leo
> On a semi-related note, can I get a classoffset without doing a hash
> lookup? That is, can I store the class number I get assigned somewhere
> for quick fetching?
It *could* be something like the example below. But that doesn't work
yet. Currently subroutines denoted with @IMMEDIATE are run, after the
whole source files was parsed and that one sub got compiled.
The question is, if the sub should already be run, when the subroutine
is parsed. If yes, the example code would run, if the whole parser/lexer
thingy were reentrant.
The code just compiles the enum type constant, classoffsets could just
follow that scheme.
leo
# doesn't work yet
.sub first @IMMEDIATE, @ANON
.local pmc T
T = newclass "Test"
addattribute T, "a"
addattribute T, "b"
$I0 = find_type "Test"
.local pmc comp
comp = compreg "PIR"
$S0 = ".const int T_TYPE = "
$S1 = $I0
$S0 .= $S1
$S0 .= "\n"
## print $S0
$P0 = compile comp, $S0
.end
.sub _main @MAIN
.local pmc t
t = new T_TYPE
print t
.end
.namespace ["Test"]
.sub __get_string
.return ("ok\n")
.end
On a semi-related note, can I get a classoffset without doing a hash
lookup? That is, can I store the class number I get assigned somewhere
for quick fetching?
Thanks,
Luke
> The question is, if the sub should already be run, when the subroutine
> is parsed. If yes, the example code would run, if the whole parser/lexer
> thingy were reentrant.
I've that example running now. Compiling is basically reentrant already.
But while at it I'll cleanup all the globals, which will take some time.
> The code just compiles the enum type constant, classoffsets could just
> follow that scheme.
[ example again ]
> .sub first @IMMEDIATE, @ANON
> .local pmc T
> T = newclass "Test"
> addattribute T, "a"
> addattribute T, "b"
> $I0 = find_type "Test"
> .local pmc comp
> comp = compreg "PIR"
> $S0 = ".const int T_TYPE = "
> $S1 = $I0
> $S0 .= $S1
> $S0 .= "\n"
> ## print $S0
> $P0 = compile comp, $S0
> .end
> .sub _main @MAIN
> .local pmc t
> t = new T_TYPE
> print t
> .end
> .namespace ["Test"]
> .sub __get_string
> .return ("ok\n")
> .end
leo