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

Some PIR "How do I?" questions

22 views
Skip to first unread message

Dan Sugalski

unread,
Nov 21, 2003, 3:18:29 PM11/21/03
to perl6-i...@perl.org
These could use some documenting (and yes, I know the answer to many) for
future use for folks generating PIR. (Hint, hint -- documentation is a
good thing)

*) How do I declare an externally visible subroutine?

*) How do I store a global variable

*) How do I load a global variable

*) How do I call an external function

*) How do I get the sub pmc for a sub declared later (or earlier) in the
file?

*) How do I (or even can I) have a file-scoped variable? (like .local,
only for all code in the file)

Dan

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

Sterling Hughes

unread,
Nov 22, 2003, 7:36:29 AM11/22/03
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski wrote:
> These could use some documenting (and yes, I know the answer to many) for
> future use for folks generating PIR. (Hint, hint -- documentation is a
> good thing)
>
> *) How do I declare an externally visible subroutine?
>
> *) How do I store a global variable
>
> *) How do I load a global variable
>
> *) How do I call an external function
>
> *) How do I get the sub pmc for a sub declared later (or earlier) in the
> file?
>
> *) How do I (or even can I) have a file-scoped variable? (like .local,
> only for all code in the file)
>


*) How do I do the following in PIR:

package Foo::Bar;

my $joe = 42;

sub new {
bless {};
}

sub prnJoe {
my $self = shift;
print $self->jo;
}

package main;

$f = Foo::Bar->new();
$f->prnJoe();


Would also be *really* great (I'm trying to implement the IMC codegen in
PHP for classes and objects right now :)

-Sterling

Melvin Smith

unread,
Nov 22, 2003, 1:02:53 PM11/22/03
to Dan Sugalski, perl6-i...@perl.org
At 03:18 PM 11/21/2003 -0500, Dan Sugalski wrote:
>These could use some documenting (and yes, I know the answer to many) for
>future use for folks generating PIR. (Hint, hint -- documentation is a
>good thing)

I will make an attempt at answering all of these regarding how it is today,
as opposed to how it should/will be very soon; --- later tonight, that is,
when I get back from playing golf =:)

I'm also starting on real IMCC documentation.

-Melvin

Gregor N. Purdy

unread,
Nov 23, 2003, 11:57:36 AM11/23/03
to Sterling Hughes, Dan Sugalski, perl6-i...@perl.org
Umm.. Do you mean:

------------------------------------------------------------
package Foo::Bar;

sub new {
my $class = shift;
return bless { jo => 42 }, $class;
}

sub prnJoe {
my $self = shift;

print $self->{jo}, "\n";
}

package main;

$f = Foo::Bar->new();
$f->prnJoe();

------------------------------------------------------------


Regards,

-- Gregor

--
Gregor Purdy gre...@focusresearch.com
Focus Research, Inc. http://www.focusresearch.com/

Melvin Smith

unread,
Nov 24, 2003, 2:06:31 AM11/24/03
to dan Sugalski, perl6-i...@perl.org
At 03:18 PM 11/21/2003 -0500, Dan Sugalski wrote:
>These could use some documenting (and yes, I know the answer to many) for
>future use for folks generating PIR. (Hint, hint -- documentation is a
>good thing)
>
>*) How do I declare an externally visible subroutine?
>
>*) How do I store a global variable
>
>*) How do I load a global variable
>
>*) How do I call an external function
>
>*) How do I get the sub pmc for a sub declared later (or earlier) in the
>file?
>
>*) How do I (or even can I) have a file-scoped variable? (like .local,
>only for all code in the file)


I just checked in an intial IMCC faq (parrot/imcc/docs/imcfaq.pod)

Hopefully we'll get it linked up in HTML format to the web site asap.

The FAQ is small, but it at least answers all of the above.

I did not go in too much depth about subs because I've got a wave
of changes to commit soon, so I want to hold off on documenting
syntax that is about to be deprecated.

Feel free to send me more questions for the FAQ.

-Melvin


Jerome Quelin

unread,
Nov 24, 2003, 12:48:16 PM11/24/03
to Melvin Smith, dan Sugalski, perl6-i...@perl.org
Melvin Smith wrote:
> I just checked in an intial IMCC faq (parrot/imcc/docs/imcfaq.pod)

Great job. Attached you'll find some corrections for typos.


> The FAQ is small, but it at least answers all of the above.

As I see it, the faq will grow fast... Maybe we'll have to split it in
different parts (generalities, subs / calling conventions, variable
declaration / access, etc.). But maybe later.


> Feel free to send me more questions for the FAQ.

Ok, here are some more (some questions are easy - but a faq should also
have some easy items -, others are not yet possible, but anyway):

* How does one retrieve arguments given on the command-line?
* How does one call a function? With arguments? With a variable number
of arguments? Get the return value(s) of a sub?
* How does one read from a file? stdin? unbuffered stdin?
* How does one create socket and network stuff?
* How does one launch an exception? trap an exception?
* How does one create a class? instanciate an object?


Jerome
--
jqu...@mongueurs.net

Jerome Quelin

unread,
Nov 24, 2003, 12:49:18 PM11/24/03
to perl6-i...@perl.org
Jerome Quelin wrote:
> Melvin Smith wrote:
> > I just checked in an intial IMCC faq (parrot/imcc/docs/imcfaq.pod)
> Great job. Attached you'll find some corrections for typos.

And of course I forgot the patch file. Here it is.

Jerome
--
jqu...@mongueurs.net

imcfaq_typos.patch

Melvin Smith

unread,
Nov 24, 2003, 12:58:54 PM11/24/03
to Jerome Quelin, dan Sugalski, perl6-i...@perl.org
At 06:48 PM 11/24/2003 +0100, Jerome Quelin wrote:
>Melvin Smith wrote:
> > I just checked in an intial IMCC faq (parrot/imcc/docs/imcfaq.pod)
>
>Great job. Attached you'll find some corrections for typos.

Thanks. BTW Robert has linked the HTML FAQ to the site.
You can get to it from the Resources tab, or just go straight
to http://www.parrotcode.org/faq/imcc

I much prefer reading it in a browser.


> > Feel free to send me more questions for the FAQ.
>
>Ok, here are some more (some questions are easy - but a faq should also
>have some easy items -, others are not yet possible, but anyway):
>
>* How does one retrieve arguments given on the command-line?
>* How does one call a function? With arguments? With a variable number
>of arguments? Get the return value(s) of a sub?
>* How does one read from a file? stdin? unbuffered stdin?
>* How does one create socket and network stuff?
>* How does one launch an exception? trap an exception?
>* How does one create a class? instanciate an object?

I'll get to work on these. Look for something tonight or tomorrow.
Some of this refreshes my memory on things I need to implement.

-Melvin


Dan Sugalski

unread,
Nov 24, 2003, 1:11:03 PM11/24/03
to Jerome Quelin, Melvin Smith, perl6-i...@perl.org
On Mon, 24 Nov 2003, Jerome Quelin wrote:

> Ok, here are some more (some questions are easy - but a faq should also
> have some easy items -, others are not yet possible, but anyway):
>
> * How does one retrieve arguments given on the command-line?
> * How does one call a function? With arguments? With a variable number
> of arguments? Get the return value(s) of a sub?
> * How does one read from a file? stdin? unbuffered stdin?
> * How does one create socket and network stuff?
> * How does one launch an exception? trap an exception?
> * How does one create a class? instanciate an object?

With the exception of the second bullet item, these are generic parrot
FAQs rather than IMCC/PIR specific ones, so ought to be put in a different
FAQ or doc section...

Jerome Quelin

unread,
Nov 24, 2003, 1:18:33 PM11/24/03
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski wrote:
> On Mon, 24 Nov 2003, Jerome Quelin wrote:
> > * How does one retrieve arguments given on the command-line?
> > * How does one call a function? With arguments? With a variable
> > number of arguments? Get the return value(s) of a sub?
> > * How does one read from a file? stdin? unbuffered stdin?
> > * How does one create socket and network stuff?
> > * How does one launch an exception? trap an exception?
> > * How does one create a class? instanciate an object?
>
> With the exception of the second bullet item, these are generic
> parrot FAQs rather than IMCC/PIR specific ones, so ought to be put in
> a different FAQ or doc section...

Correct, but then someone new to parrot who wants to write a compiler
targetting parrot will need to look for and read faqs in a lot of
different places...

I think the real question is: do we want to promote imcc as _the_ target
language for compilers targetting parrot?
If the answer is yes (as I thought it was), then I don't think we need a
pasm faq...

Jerome
--
jqu...@mongueurs.net

Melvin Smith

unread,
Nov 24, 2003, 11:22:02 PM11/24/03
to Jerome Quelin, Dan Sugalski, perl6-i...@perl.org
At 07:18 PM 11/24/2003 +0100, Jerome Quelin wrote:
>Dan Sugalski wrote:
> > On Mon, 24 Nov 2003, Jerome Quelin wrote:
> > > * How does one launch an exception? trap an exception?
> > > * How does one create a class? instanciate an object?
>
> > With the exception of the second bullet item, these are generic
> > parrot FAQs rather than IMCC/PIR specific ones, so ought to be put in
> > a different FAQ or doc section...

The last 2 bullet items will also be specific to IMCC. The syntax for defining
a class will trigger IMCC to construct and freeze the class with the bytecode
at compile time which means it wont generate any Parrot instructions.
That is how it currently does constant subs. Also, exceptions in IMCC
will certainly be a briefer syntax, maybe even try/catch.

>I think the real question is: do we want to promote imcc as _the_ target
>language for compilers targetting parrot?

The answer is yes.

>If the answer is yes (as I thought it was), then I don't think we need a
>pasm faq...

We still need one but I do not want to maintain it, myself.
Simon Cozens already wrote some stuff that could be used as a
start. Of course there is also Perl6 Essentials. :)

We DO need a Parrot Programming FAQ. I propose the IMCC faq functions
as just that. We can still have the current Parrot FAQ, which is
great at answering generic questions for people who haven't swallowed
the blue pill yet. (Or was it the red pill, I vaguely remember Dan in a black
trenchcoat and glasses, and guns.....)

-Melvin


Melvin Smith

unread,
Nov 24, 2003, 11:03:17 PM11/24/03
to Jerome Quelin, perl6-i...@perl.org
At 06:49 PM 11/24/2003 +0100, Jerome Quelin wrote:
>Jerome Quelin wrote:
> > Melvin Smith wrote:
> > > I just checked in an intial IMCC faq (parrot/imcc/docs/imcfaq.pod)
> > Great job. Attached you'll find some corrections for typos.
>
>And of course I forgot the patch file. Here it is.

Thanks, applied!

Also I added another sample that might interest compiler writers
that may be new to Parrot/IMCC syntax. It just shows one approach
to compiling a class with fields, methods and instantiating them.

The syntax is a workaround for the lack of explicit class/object support
in Parrot.

-Melvin


Dan Sugalski

unread,
Nov 25, 2003, 9:01:11 AM11/25/03
to Melvin Smith, Jerome Quelin, perl6-i...@perl.org
On Mon, 24 Nov 2003, Melvin Smith wrote:

> We DO need a Parrot Programming FAQ. I propose the IMCC faq functions
> as just that. We can still have the current Parrot FAQ, which is
> great at answering generic questions for people who haven't swallowed
> the blue pill yet. (Or was it the red pill, I vaguely remember Dan in a black
> trenchcoat and glasses, and guns.....)

I think separating the IMCC and parrot programming FAQs, or making the
IMCC faq a section of a larger Parrot FAQ, would be better. The IMCC FAQ
really ought to be about syntax rather than semantics.

Robert Spier

unread,
Nov 26, 2003, 12:50:20 AM11/26/03
to perl6-i...@perl.org
> I think separating the IMCC and parrot programming FAQs, or making the
> IMCC faq a section of a larger Parrot FAQ, would be better. The IMCC FAQ
> really ought to be about syntax rather than semantics.

Patches welcome.

:-J

-R

Pete Lomax

unread,
Nov 27, 2003, 7:02:42 AM11/27/03
to perl6-i...@perl.org
Perl6 already does interpolation without special support from IMCC.

That's nice for it. Where do I go crib from?

Pete

Melvin Smith

unread,
Nov 27, 2003, 9:52:10 AM11/27/03
to Pete Lomax, perl6-i...@perl.org
At 12:02 PM 11/27/2003 +0000, Pete Lomax wrote:
>Perl6 already does interpolation without special support from IMCC.
>
>That's nice for it. Where do I go crib from?

?

-Melvin


Pete Lomax

unread,
Nov 27, 2003, 12:38:47 PM11/27/03
to perl6-i...@perl.org

I'll rephrase. Is there anything knocking about which would help with
eg:
printf (pFile, "Amount %12.3f [%-10.10s]\n",balance,name);

Or do I have to rip the string apart character-by-character, then
throw all my variables about in registers, cutting, chopping and
padding them into shape, and then dumping them in iddy little bits?

Pete

Dan Sugalski

unread,
Nov 27, 2003, 1:14:24 PM11/27/03
to Pete Lomax, perl6-i...@perl.org

Depends entirely on two things:

1) Whether we want printf-style functionality as part of the core
2) Whether you want to use it

I think the answer to #1 is a big yes. You can answer #2 as you need. :)
--

Melvin Smith

unread,
Dec 1, 2003, 10:28:00 PM12/1/03
to Dan Sugalski, Pete Lomax, perl6-i...@perl.org
At 01:14 PM 11/27/2003 -0500, Dan Sugalski wrote:
>At 5:38 PM +0000 11/27/03, Pete Lomax wrote:
>>On Thu, 27 Nov 2003 09:52:10 -0500, Melvin Smith
>><mrjol...@mindspring.com> wrote:
>>
>>>At 12:02 PM 11/27/2003 +0000, Pete Lomax wrote:
>>>>Perl6 already does interpolation without special support from IMCC.
>>I'll rephrase. Is there anything knocking about which would help with
>>eg:
>>printf (pFile, "Amount %12.3f [%-10.10s]\n",balance,name);
>>
>>Or do I have to rip the string apart character-by-character, then
>>throw all my variables about in registers, cutting, chopping and
>>padding them into shape, and then dumping them in iddy little bits?
>
>Depends entirely on two things:
>
>1) Whether we want printf-style functionality as part of the core
>2) Whether you want to use it
>
>I think the answer to #1 is a big yes. You can answer #2 as you need. :)

To me, variable interpolation means high-level language interpolation
using the high-level symbol name. printf isn't the same. I'd call it
"format interpolation", if that makes sense.

1) interpolation by the symbol name we don't need at the Parrot/IMC
level, and this was what the FAQ addressed. I could be wrong, though.

2) printf/sprintf - we do need it (and implemented in C) since it is a
staple and is the
reasonable hook for HLL implementors to do interpolation without having
to write a special native method or PMC for each language.

-Melvin


Dan Sugalski

unread,
Dec 2, 2003, 9:32:36 AM12/2/03
to Melvin Smith, Pete Lomax, perl6-i...@perl.org
At 10:28 PM -0500 12/1/03, Melvin Smith wrote:
>
>2) printf/sprintf - we do need it (and implemented in C) since it is
>a staple and is the
>reasonable hook for HLL implementors to do interpolation without having
>to write a special native method or PMC for each language.

Okay, once I get the object stuff finished I think this is the next
thing to tackle. The one question is whether we should make the
lead-in character for sequences settable at runtime, as not all
languages will want to use % for interpolation. (I am, however,
perfectly fine with choosing something otherwise unused and forcing
languages to translate from their exposed form to our internal form)
--

Pete Lomax

unread,
Dec 10, 2003, 10:45:13 AM12/10/03
to perl6-i...@perl.org

Rummaging around /ops/ops.num, I spotted:

sprintf_s_s_p 1140
sprintf_s_sc_p 1141
sprintf_p_p_p 1142

(don't recall seeing sprintf mentioned elsewhere) So I tried them
(well the first two anyway), and they work.

Pete

0 new messages