I am writing an XSLT 2.0 processor, and I want to give users the option to write their own message and error handling routines and the like in their favourite scripting language. So I thought of using parrot.
But when I look at http://www.parrotcode.org/docs/embed.html, I can see no way of getting information back from the script - not even an exit code. Is there anyway of doing this that I have missed? -- Colin Adams Preston Lancashire
On Tue, May 17, 2005 at 03:00:14PM +0100, Colin Paul Adams wrote: > But when I look at http://www.parrotcode.org/docs/embed.html, I can > see no way of getting information back from the script - not even an > exit code. Is there anyway of doing this that I have missed?
You may wish to use Parrot_call_sub's "SS" form, where you pass in a string and get back a string. Something like this:
my $interp = Parrot_new(undef);
# ... load a .pir file or some other code into $interp ...
my $code_pmc = Parrot_find_global( $interp, const_string("Namespace"), const_string("sub_name"), );
my $return_str = Parrot_call_sub( $interp, $code_pmc, const_string("SS"), const_string("Your_input_string_here"), );
>>>>> "Jeff" == Jeff Horwitz <j...@smashing.org> writes:
Jeff> you'll probably want to use the Parrot_call_sub_* API to Jeff> call individual subroutines and get return values. "perldoc Jeff> extend.c" in the parrot source for more info. you might
Thanks - I'll take a look at that.
Jeff> also have a look at the mod_parrot source Jeff> (http://www.smashing.org/mod_parrot), which is one of the Jeff> few apps embedding parrot at the moment. the other is pugs Jeff> (http://www.pugscode.org), but it's written in haskell.
Why's that a but? Haskell's a good language. -- Colin Adams Preston Lancashire
> Jeff> also have a look at the mod_parrot source > Jeff> (http://www.smashing.org/mod_parrot), which is one of the > Jeff> few apps embedding parrot at the moment. the other is pugs > Jeff> (http://www.pugscode.org), but it's written in haskell.
> Why's that a but? Haskell's a good language.
no argument there -- just assumed you were looking for examples in C! :)
you'll probably want to use the Parrot_call_sub_* API to call individual subroutines and get return values. "perldoc extend.c" in the parrot source for more info. you might also have a look at the mod_parrot source (http://www.smashing.org/mod_parrot), which is one of the few apps embedding parrot at the moment. the other is pugs (http://www.pugscode.org), but it's written in haskell.
> I am writing an XSLT 2.0 processor, and I want to give users the > option to write their own message and error handling routines and the > like in their favourite scripting language. So I thought of using > parrot.
> But when I look at http://www.parrotcode.org/docs/embed.html, I can > see no way of getting information back from the script - not even an > exit code. Is there anyway of doing this that I have missed? > -- > Colin Adams > Preston Lancashire
>>>>> "Jeff" == Jeff Horwitz <j...@smashing.org> writes:
>> Why's that a but? Haskell's a good language.
Jeff> no argument there -- just assumed you were looking for Jeff> examples in C! :)
Actually, examples in any language are fine. I'm actually writing in Eiffel, but I shall use an interface generator to automatically build low-level bridging classes from the C header files. I intend to make it available as a general extension mechanism for Eiffel via parrot, as that will be almost zero effort after implementing what I need for my program. -- Colin Adams Preston Lancashire
> Actually, examples in any language are fine. > I'm actually writing in Eiffel, but I shall use an interface generator > to automatically build low-level bridging classes from the C header > files. > I intend to make it available as a general extension mechanism for > Eiffel via parrot, as that will be almost zero effort after > implementing what I need for my program.
this is similar to what we did with pugs, except we used haskell's FFI (foreign function interface) to call out to Parrot's API. see src/Pugs/Embed/Parrot.hsc in the pugs source.
On 5/17/05, Autrijus Tang <autri...@autrijus.org> wrote:
> On Tue, May 17, 2005 at 05:31:32PM +0100, Colin Paul Adams wrote: > > I take it SS stands for String-to-String?
> Yes. "PPC" would stand for PMC -> PMC -> String, i.e. take two PMCs > and returns a String.
of course, you meant PPS here, but i can't take credit for the catch :)
from #parrot: [13:35] Coke: autrijus - did you mean PPS, not PPC ? [13:35] Coke: (email) [13:36] autrijus: I meant PPS. ;) [13:36] autrijus: please reply me to correct my mistake :) [13:36] autrijus: <- brain autocompletion [13:37] Coke: I can't easily reply ATM [13:44] particle: i'll do it
Autrijus> On Tue, May 17, 2005 at 03:00:14PM +0100, Colin Paul Autrijus> Adams wrote: >> But when I look at http://www.parrotcode.org/docs/embed.html, I >> can see no way of getting information back from the script - >> not even an exit code. Is there anyway of doing this that I >> have missed?
Autrijus> You may wish to use Parrot_call_sub's "SS" form, where Autrijus> you pass in a string and get back a string. Something Autrijus> like this:
Autrijus> my $interp = Parrot_new(undef);
Autrijus> # ... load a .pir file or some other code into Autrijus> $interp ...
Autrijus> my $code_pmc = Parrot_find_global( $interp, Autrijus> const_string("Namespace"), const_string("sub_name"), );
Autrijus> You may wish to use Parrot_call_sub's "SS" form, where Autrijus> you pass in a string and get back a string. Something Autrijus> like this:
Autrijus> my $interp = Parrot_new(undef);
Autrijus> # ... load a .pir file or some other code into Autrijus> $interp ...
Autrijus> my $code_pmc = Parrot_find_global( $interp, Autrijus> const_string("Namespace"), const_string("sub_name"), );
I'm having a problem with this. For Parrot_find_global, I'm specifying global.h as one of the header files which must be read to generate definitions from. But this is failing, apparently because PMC isn't defined.
So I tried to find where PMC was defined - it looked like pobj.h to me, but if I include that, I run into trouble with size_t (?!) and DPOINTER (at least).
What headers do I need to read for the parrot_find_global call? -- Colin Adams Preston Lancashire
>>>>> "Jeff" == Jeff Horwitz <j...@smashing.org> writes:
>> What headers do I need to read for the parrot_find_global call?
Jeff> Parrot_PMC is the public type, and behind the scenes it's Jeff> defined as PMC *.
Jeff> all you should need to include is embed.h, extend.h and for Jeff> now, resources.h. i'm actually working on fleshing these Jeff> files out to be more consistent wrt the public API.
Jeff> see trunk/src/parrot_util.c in the mod_parrot source for a Jeff> working example of all this.
Thanks. That reference was useful, as they have to be in that order (resources.h first). it compiles now. -- Colin Adams Preston Lancashire
> I'm having a problem with this. > For Parrot_find_global, I'm specifying global.h as one of the header > files which must be read to generate definitions from. > But this is failing, apparently because PMC isn't defined.
> So I tried to find where PMC was defined - it looked like pobj.h to > me, but if I include that, I run into trouble with size_t (?!) and > DPOINTER (at least).
> What headers do I need to read for the parrot_find_global call?
Parrot_PMC is the public type, and behind the scenes it's defined as PMC *.
all you should need to include is embed.h, extend.h and for now, resources.h. i'm actually working on fleshing these files out to be more consistent wrt the public API.
see trunk/src/parrot_util.c in the mod_parrot source for a working example of all this.
>>>>> "Jeff" == Jeff Horwitz <j...@smashing.org> writes:
Jeff> all you should need to include is embed.h, extend.h and for Jeff> now, resources.h. i'm actually working on fleshing these Jeff> files out to be more consistent wrt the public API.
I'm getting real close now.
But I'm having problems creating the parrot strings. I'm using
Parrot_new_string
and I'm passing "UTF-8" as the encoding name.
I get back:
Can't make 'UTF-8' charset strings
Despite what the documentation says:
encoding
This specifies the encoding used to encode the characters in the data. There are currently four character encodings used in Parrot: singlebyte, UTF-8, UTF-16 and UTF-32. UTF-16 and UTF-32 should use the native endianness of the machine.
So does that mean I'm limited to singlebyte strings? If so, how do I specify this encoding, and what is the character set that is used? (US-ASCII ?) -- Colin Adams Preston Lancashire
>>>>> "Colin" == Colin Paul Adams <co...@colina.demon.co.uk> writes: >>>>> "Jeff" == Jeff Horwitz <j...@smashing.org> writes:
Colin> Can't make 'UTF-8' charset strings
Colin> Despite what the documentation says:
Colin> encoding
Colin> This specifies the encoding used to encode the characters Colin> in the data. There are currently four character encodings Colin> used in Parrot: singlebyte, UTF-8, UTF-16 and Colin> UTF-32. UTF-16 and UTF-32 should use the native endianness Colin> of the machine.
Well, I found in the code what is actually accepted (iso-8859-1, for instance, but that is hardly acceptable).
Yeah. I'm sorry to say that: you are just hitting a part of Parrot labeled "under (re)construction" and the docs aren't all up to date.
If you are using vim, "make tags" [1] in the parrot directory, follow "string_make", which is called from Parrot_new_string() and you'll see a more but still not complete listing of *charset*s that are supplied currently. The ultimate list of charsets can be found in charset/*.c or src/charset.c.
Additionally the interface doc is talking about an encoding, which is pretty misleading:
fixed_8 - iso_8859_xxx
encoding - charset which one
You currently can just pass a charset, but the default encoding for the charset "unicode" is "utf8" (now).
> This specifies the encoding used to encode the characters in the > data. There are currently four character encodings used in Parrot: > singlebyte, UTF-8, UTF-16 and UTF-32. UTF-16 and UTF-32 should use the > native endianness of the machine.
That is outdated and future as well. Currently only utf8 encoding is working (for some degree of working)
> So does that mean I'm limited to singlebyte strings?
No, pass charset "unicode", which defaults to encoding "utf8"
>>>>> "Leopold" == Leopold Toetsch <l...@toetsch.at> writes:
Leopold> Yeah. I'm sorry to say that: you are just hitting a part Leopold> of Parrot labeled "under (re)construction" and the docs Leopold> aren't all up to date.
<snip>
>> So does that mean I'm limited to singlebyte strings?
Leopold> No, pass charset "unicode", which defaults to encoding Leopold> "utf8"
OK. Thanks for that. -- Colin Adams Preston Lancashire
On Fri, May 20, 2005 at 10:34:39AM +0100, Colin Paul Adams wrote: > I have a problem with this - namely that the function is variadic, and > the interface generator can't cope with this.
Hmm, in Haskell FFI, we hard-coded two cases of invocation, treating the function as two distinct, non-variadic forms:
Autrijus> On Tue, May 17, 2005 at 03:00:14PM +0100, Colin Paul Autrijus> Adams wrote: >> But when I look at http://www.parrotcode.org/docs/embed.html, I >> can see no way of getting information back from the script - >> not even an exit code. Is there anyway of doing this that I >> have missed?
Autrijus> You may wish to use Parrot_call_sub's "SS" form, where Autrijus> you pass in a string and get back a string. Something Autrijus> like this:
I have a problem with this - namely that the function is variadic, and the interface generator can't cope with this.
So I'm going to have to do a lot of hand-coding to get round this problem.
This is a general problem for interface generators, I believe. Would it be possible to have more friendly functions in embed.h/c for use by interface generators? (By more friendly, I mean instead of ..., a single argument of some list or array type.) -- Colin Adams Preston Lancashire
>>>>> "Leopold" == Leopold Toetsch <l...@toetsch.at> writes:
Leopold> Colin Paul Adams <co...@colina.demon.co.uk> wrote: >> I have a problem with this - namely that the function is >> variadic, and the interface generator can't cope with this.
Autrijus> On Fri, May 20, 2005 at 10:34:39AM +0100, Colin Paul Autrijus> Adams wrote: >> I have a problem with this - namely that the function is >> variadic, and the interface generator can't cope with this.
Autrijus> Hmm, in Haskell FFI, we hard-coded two cases of Autrijus> invocation, treating the function as two distinct, Autrijus> non-variadic forms:
Autrijus> -- This is the (() returns Void) form foreign import Autrijus> ccall "Parrot_call_sub" parrot_call_sub_vv :: Autrijus> ParrotInterp -> ParrotPMC -> CString -> IO ()
Autrijus> -- This is the ((String, String) returns String) Autrijus> form foreign import ccall "Parrot_call_sub" Autrijus> parrot_call_sub_SSS :: ParrotInterp -> ParrotPMC -> Autrijus> CString -> ParrotString -> ParrotString -> IO Autrijus> ParrotString
Autrijus> Surely you can do the same with Eiffel?
Yes, I can, but that only copes with a single string parameter - there are very many possibilities (strictly, infinite, though obviously not in practice). Also, I shall want to use the object/method calls, which adds further to the burden.
And I'm not just coding this for my XSLT processor - I am going to make the Eiffel library freely available to all Eiffel programmers. That way, any Eiffel program can use any Parrot-targetted scripting language as an extension language (and the language can be chosen by the user of the application who wants to do the scripting, not imposed by the developer of the application). So this requires a lot of flexibility.
I can easily code by hand (and will, for now) just those subroutines and methods I shall require for use within my XSLT processor, but to do them all in general will be too much (so I shall have to request each application deleoper to add the code necessary that they want).
And this applies to anyone else who wants to use Parrot as a multi-lingual extension mechanism for another language. -- Colin Adams Preston Lancashire
The problem I'm finding with this, is getting back the returned string characters. I assume the void * returned is pointing to a Parrot String. Certainly it's not a const char *.
There is a function declaration
Parrot_string_cstring
in string_funcs.h, but it appears to have no definitoon anywhere, so that's not much use to me. -- Colin Adams Preston Lancashire