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

Loading bytecode at runtime

5 views
Skip to first unread message

Dan Sugalski

unread,
Jan 15, 2004, 12:29:45 PM1/15/04
to perl6-i...@perl.org
Okay, since folks are diving into IMCC (assuming we can keep a fight
from breaking out) it's time to address bytecode loading.

We've got the need to have subs that get executed when a code segment
is loaded, a need to have a 'main' sub that gets executed as mainline
code, and subs that get executed after compilation but before run.
So, since I *hate* magic name subs, what I want to do is add tags to
subs to indicate what they should do. So, these tags are what I want,
to be added to the .pcc_sub line:

MAIN
IMMEDIATE
LOAD
POSTCOMP

and I also would like a way to tag a label out of band for the assembler:

.MAIN foo
.IMMEDIATE bar
.LOAD baz
.POSTCOMP xyzzy

MAIN subs, of which there should be only one, is the sub that parrot
executes when it's handed a bytecode file to run. If I do:

./parrot foo.pbc

then the sub tagged MAIN in foo.pbc should be the one considered the
main subroutine. MAIN subs get argv passed in.

IMMEDIATE subs are executed, with no parameters, as soon as they're
done compiling. They're definitely compile-time things, and odds are
we won't have too many of them when writing assembly code, but
they'll be reasonably common for HLLs we deal with.

POSTCOMP subs are executed as soon as compilation is done, once again
with no parameters. Whether they do a whole lot is up in the air, but
that's not my problem, and it'll be useful for compile-and-go systems.

LOAD subs are executed on bytecode load time. Once again, no
parameters. Bytecode gets loaded, they get called.

All these subs have real names in addition to their particular
properties (and they can have multiple properties) so should be in
the bytecode file for normal execution. (So a sub could be marked as
LOAD and POSTCOMP, and be callable by name)

I'm presuming throwing names and/or addresses into a metadata segment
is the right way to go here, so that works for me.
--
Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

Leopold Toetsch

unread,
Feb 20, 2004, 3:42:04 AM2/20/04
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski <d...@sidhe.org> wrote:
> Okay, since folks are diving into IMCC (assuming we can keep a fight
> from breaking out) it's time to address bytecode loading.

> We've got the need to have subs that get executed when a code segment
> is loaded, a need to have a 'main' sub that gets executed as mainline
> code, and subs that get executed after compilation but before run.
> So, since I *hate* magic name subs, what I want to do is add tags to
> subs to indicate what they should do. So, these tags are what I want,
> to be added to the .pcc_sub line:

> MAIN
> IMMEDIATE
> LOAD
> POSTCOMP

Started that now:

The syntax (proposed and current) is for PASM:

.pcc_sub @MAIN _main:

and for PIR:

.sub _main prototyped, @MAIN, @IMMEDIATE, @LOAD, @POSTCOMP

albeit it doesn't make much sense, to through all possible pragmas at
one sub ;)

All these specifiers are optional.

I did choose the '@' prefix because of possible name collisions with
existing labels (like t/op/string_102.pasm). It clearly denotes that
something special is going on here.

Next will be @LOAD and possibly @MAIN functionality.

leo

Leopold Toetsch

unread,
Feb 20, 2004, 7:52:13 AM2/20/04
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski <d...@sidhe.org> wrote:

> We've got the need to have subs that get executed when a code segment
> is loaded,

That part is working now for loaded assembly and byte code.

.pcc_sub @LOAD _the_init_code: # PASM

.sub _the_init_code @LOAD, prototyped # PIR

s. t/pmc/sub.t for examples.

leo

Leopold Toetsch

unread,
Feb 20, 2004, 9:20:23 AM2/20/04
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski <d...@sidhe.org> wrote:

> MAIN subs, of which there should be only one, is the sub that parrot
> executes when it's handed a bytecode file to run. If I do:

Done.

> IMMEDIATE subs are executed, with no parameters, as soon as they're
> done compiling. They're definitely compile-time things, and odds are
> we won't have too many of them when writing assembly code, but
> they'll be reasonably common for HLLs we deal with.

This is more tricky. Further it depends on, what code is allowed in such
subs (e.g. calling other subs, eval ;). Postponed.

> POSTCOMP subs are executed as soon as compilation is done, once again
> with no parameters. Whether they do a whole lot is up in the air, but
> that's not my problem, and it'll be useful for compile-and-go systems.

Can that not be achieved by either MAIN or LOAD?

> LOAD subs are executed on bytecode load time. Once again, no
> parameters. Bytecode gets loaded, they get called.

Done.

leo

Dan Sugalski

unread,
Feb 20, 2004, 10:19:45 AM2/20/04
to l...@toetsch.at, perl6-i...@perl.org
At 9:42 AM +0100 2/20/04, Leopold Toetsch wrote:
>Started that now:
>
>The syntax (proposed and current) is for PASM:
>
> .pcc_sub @MAIN _main:
>
>and for PIR:
>
> .sub _main prototyped, @MAIN, @IMMEDIATE, @LOAD, @POSTCOMP

Let's skip the commas, mandate the properties come later, lower-case
'em, and toss the @. So that'd read, for PIR:

.sub _main prototyped main immediate load postcomp

Leopold Toetsch

unread,
Feb 20, 2004, 12:48:39 PM2/20/04
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski wrote:

> At 9:42 AM +0100 2/20/04, Leopold Toetsch wrote:
>
>> Started that now:
>>
>> The syntax (proposed and current) is for PASM:
>>
>> .pcc_sub @MAIN _main:
>>
>> and for PIR:
>>
>> .sub _main prototyped, @MAIN, @IMMEDIATE, @LOAD, @POSTCOMP
>
>
> Let's skip the commas, mandate the properties come later, lower-case
> 'em, and toss the @. So that'd read, for PIR:
>
> .sub _main prototyped main immediate load postcomp


As already said, "main" or "MAIN" are reserved words then and collide
with exisiting labels. Its doable by introducing some flags, that these
identifiers are only special after a .sub/.pcc_sub. But I don't like to
mess around with the lexer too much. If someone speaks lex fluently,
please jump in ;)
Getting rid of the commas is easy.

leo

Dan Sugalski

unread,
Feb 20, 2004, 1:41:43 PM2/20/04
to Leopold Toetsch, perl6-i...@perl.org

Hrm. I may take a shot at it, as I've been dealing with grammars far
more than I'd like to be lately. If it's a problem then for now we
can put preceding periods on them, to make it .main/.immediate/.load
or whatever.

0 new messages