Proposed steps towards the next release 0.2 and beyond.

0 views
Skip to first unread message

Leopold Toetsch

unread,
Mar 7, 2005, 5:01:13 AM3/7/05
to Perl 6 Internals
Below inline/attached is a proposal for Parrot core changes. I'll post a
more detailed proposal for 1) objects in a minute.

leo

REL-0.2.txt

Roger Browne

unread,
Mar 7, 2005, 7:09:02 AM3/7/05
to Perl 6 Internals
On Mon, 2005-03-07 at 11:01 +0100, Leopold Toetsch wrote:

> 4.1.1) implement a language pragma in assembler, e.g.:
>
> .HL_language Python

A pragma like that seems to split high-level languages into two groups:
those that are specially known to parrot, and those that are not. I'd
like it to be possible for ANY scripting language to be compiled to IMC
or PASM, and for that compiled code to be runnable directly (if it uses
only built-in PMC classes), or with the addition of dynamically-loaded
classes (if the built-in PMC classes are not suitable).

> 4.1.2) create table of canonical types per language mapping
>
> Integer - PyInt - TclInt - Perl6Int - ...

Why not use a pragma to list the canonical types, instead of a
".HL_language" pragma.

In the language I'm implementing, there are distinct PMCs for Integer,
Character, Boolean, Bits and Enumeration - but I don't want lose
interoperability with other languages that use one integer type for all
of these.

Within my language, each of the above types is implemented with its own
PMC, but each of these PMCs uses the same internal layout as .Integer.
Therefore, it would be fine for them all to be treated at an integer
within inter-language calls. But there needs to be a way for my IMC to
tell parrot about this.

Here's an example of how it could be done for a language that uses one
PMC for all integer-like types:

.Language_name "ruby" # just a String; used for messages etc
.Language_mapping Integer <-> RubyInt
.Language_mapping Character <-> RubyInt
.Language_mapping Boolean <-> RubyInt
.Language_mapping Bits <-> RubyInt
.Language_mapping Enumeration <-> RubyInt
.Language_mapping String <-> RubyString
...etc

and here's how it might look for a language that has a greater degree of
abstraction:

.Language_name "Bird"
.Language_mapping Integer <-> BirdInteger
.Language_mapping Character <-> BirdCharacter
.Language_mapping Boolean <-> BirdBoolean
.Language_mapping Bits <-> BirdBits
.Language_mapping Enumeration <-> BirdEnum
.Language_mapping String <-> BirdString
...etc

This would enable parrot to know that when a BirdBoolean is passed to a
ruby method, BirdBoolean has a Boolean interface which ruby can treat as
a RubyInt.

If the ruby method wants to return a character, perhaps parrot could
provide an "abstract" version of the "new" opcode, so that ruby can
create a "new abstract Character". Parrot would then consult the
canonical types, and would create a BirdCharacter if the calling
language was "Bird", but would create a PyInt if the calling language
was "Python".

I hope this makes some sense, and that you can see some merit in it.

> Proposed steps towards the next release 0.2 and beyond.

I'd be very pleased to see working support in 0.2 for
setfile/setline/setcolumn so that when my IMC code fails due to (e.g.) a
divide by zero error, the parrot runtime can report the source location
in my high-level code rather than the source location in my IMC.

Regards,
Roger
--
Roger Browne <ro...@eiffel.demon.co.uk>

Leopold Toetsch

unread,
Mar 7, 2005, 7:50:59 AM3/7/05
to Roger Browne, perl6-i...@perl.org
Roger Browne <ro...@eiffel.demon.co.uk> wrote:
> On Mon, 2005-03-07 at 11:01 +0100, Leopold Toetsch wrote:

>> 4.1.1) implement a language pragma in assembler, e.g.:
>>
>> .HL_language Python

> A pragma like that seems to split high-level languages into two groups:
> those that are specially known to parrot, and those that are not.

Not really. The rational for the .HL_language is twofold:
- all modules and therefore all subroutines in it should have the HLL
name attached to it.
- the vtable and MMD methods that return new PMCs should return a PMC
that is consistent with the types of that language. If no specific
type is registered, Parrot's default or standard types like
Integer, Float, or String are used.

> Why not use a pragma to list the canonical types, instead of a
> ".HL_language" pragma.

This is of course part of the plan :) The ".HL_language" or
".Language_name" pragma specifies the mapping to use for the rest of the
source file. And the mappings should be dynamically extendable as ...

> .Language_mapping Integer <-> RubyInt

.. it's shown here, yes.

> I'd be very pleased to see working support in 0.2 for
> setfile/setline/setcolumn so that when my IMC code fails due to (e.g.) a
> divide by zero error, the parrot runtime can report the source location
> in my high-level code rather than the source location in my IMC.

Yep. Good point. It was discussed some time ago and went off into the
multi-dimensionality of the code location ;)

But yes. Code is ever becoming more complex and debugging is already a
pain. The lexer already knows about setfile and setline as well as
C-like #line directives. The information is discarded but should go into
similar metadata like PIR-line information is already using.

> Regards,
> Roger

leo

MrJoltCola

unread,
Mar 7, 2005, 10:30:02 AM3/7/05
to l...@toetsch.at, Roger Browne, perl6-i...@perl.org
At 07:50 AM 3/7/2005, Leopold Toetsch wrote:
>Roger Browne <ro...@eiffel.demon.co.uk> wrote:
> > On Mon, 2005-03-07 at 11:01 +0100, Leopold Toetsch wrote:
>
> >> 4.1.1) implement a language pragma in assembler, e.g.:
> >>
> >> .HL_language Python

Sounds good to me except that I would prefer you remove the HL_
and just call it .language to be consistent with other directives.
Incidentally this is what .NET uses as well except its implementation
uses GUID instead of a string, and it also allows the compiler
vendor and source document type to be included in the directive.

Dan and I talked about this a couple of years ago on IRC.
Originally I wanted to stay away from GUIDs as I think they are overkill,
and had considered allowing ASCII:

.language Perl6
.language Perl6:ThePerlFoundation

But..., this requires this section in the bytecode to be variable sized,
so there might be some merit to using GUIDs, especially for vendors.

I think to keep PIR "convenient" for hackers I want to accept both
strings and 32 bit integers for each. If a string, it must be already
registered in IMCC and we can probably reserve the first 1024 for
"pre-registering" but IMCC still would be able to accept integers.

In any case, it needs to be fixed width in the bytecode header.

We need to revisit the bytecode format. Last time through, I put
an "Opcode type" at some offset, per Dan's request.
We store a magic number for that. I'm pretty sure we can use
this field to identify the language using whatever is provided in the
.language pragma, but I can't speak for Dan. I think he might
have had different plans for opcode type.

-Melvin


Leopold Toetsch

unread,
Mar 7, 2005, 11:05:52 AM3/7/05
to MrJoltCola, perl6-i...@perl.org
MrJoltCola <mrjol...@mindspring.com> wrote:
> At 07:50 AM 3/7/2005, Leopold Toetsch wrote:
>> >>
>> >> .HL_language Python

> Sounds good to me except that I would prefer you remove the HL_
> and just call it .language to be consistent with other directives.

I don't care much about the actual keyword - as long as we find a
reasonable compromise ;) Anyway, the HL_ prefix should make sure that
it's not mixed up with any kind of string's language declaration. But as
strings don't have a language setting anymore ".language" would be fine
too.

> Incidentally this is what .NET uses as well except its implementation
> uses GUID instead of a string, and it also allows the compiler
> vendor and source document type to be included in the directive.

I don't like GUIDs. I prefer text.

> Dan and I talked about this a couple of years ago on IRC.
> Originally I wanted to stay away from GUIDs as I think they are overkill,
> and had considered allowing ASCII:

Yep.

> .language Perl6
> .language Perl6:ThePerlFoundation

> But..., this requires this section in the bytecode to be variable sized,

No. All that kind of information should either go into PBCs metadata or
stored as PMC constants:

.const .Version $P0 = "vendor=>tpf,author=>mel,version=0.815"

or whatever. It's up to the Version PMC to parse the passed in string
and freeze it appropriately.

The constant PMC syntax is used already for subroutines. We'd need just
to switch to freeze/thaw for PMC constants.

WRT .language: that should be just a plain string.

> In any case, it needs to be fixed width in the bytecode header.

Not really. Metadata are in separate sections or .language becomes a
string constant.

> We need to revisit the bytecode format. Last time through, I put
> an "Opcode type" at some offset, per Dan's request.

You mean C<opcodetype> in the PBC header? That's still unused. But there
is:

#define OPCODE_TYPE_PERL 0x5045524c
#define OPCODE_TYPE_PYTHON 0x5045524b
#define OPCODE_TYPE_JAVA 4871757
#define OPCODE_TYPE_MSNET 2e4e4554

which defines 4-byte char constants denoting the language, somehow.

> We store a magic number for that. I'm pretty sure we can use
> this field to identify the language using whatever is provided in the
> .language pragma, but I can't speak for Dan. I think he might
> have had different plans for opcode type.

Well, it seems to be that. But we want and additional type mapping for
Parrot standard types. So that doesn't fit there anyway.

> -Melvin

leo

Reply all
Reply to author
Forward
0 new messages