*) 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
*) 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
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
------------------------------------------------------------
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/
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
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
And of course I forgot the patch file. Here it is.
Jerome
--
jqu...@mongueurs.net
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
> 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...
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
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
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
> 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.
Patches welcome.
:-J
-R
That's nice for it. Where do I go crib from?
Pete
?
-Melvin
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
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
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)
--
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