Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[CVS ci] @ANON sub pragma

5 views
Skip to first unread message

Leopold Toetsch

unread,
Nov 25, 2004, 3:18:55 AM11/25/04
to Perl 6 Internals
I've checked in intial support for anonymous subroutines.

.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.

Sam Ruby

unread,
Nov 27, 2004, 10:59:53 PM11/27/04
to Leopold Toetsch, Perl 6 Internals
Leopold Toetsch wrote:

> 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

Leopold Toetsch

unread,
Nov 28, 2004, 2:32:00 AM11/28/04
to Sam Ruby, perl6-i...@perl.org
Sam Ruby <ru...@intertwingly.net> wrote:

> I can't seem to combine it with "non_prototyped".

.sub "foo" @ANON, non_prototyped

> - Sam Ruby

leo

Leopold Toetsch

unread,
Nov 28, 2004, 4:31:08 AM11/28/04
to Luke Palmer, Perl 6 Internals
Luke Palmer wrote:

> 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

Luke Palmer

unread,
Nov 28, 2004, 1:08:15 AM11/28/04
to Sam Ruby, Leopold Toetsch, Perl 6 Internals
Leopold Toetsch wrote:
>I've checked in intial support for anonymous subroutines.
>
> .sub foo @ANON
>
>creates an anonymous subroutine.

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

Leopold Toetsch

unread,
Nov 28, 2004, 10:28:13 AM11/28/04
to perl6-i...@perl.org
Leopold Toetsch <l...@toetsch.at> wrote:
> Luke Palmer wrote:

> 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

0 new messages