Leo pointed out that while Tcl is using the '.HLL' directive, ...
nothing was actually being autoboxed to the various Tcl types, as tcl
has not been registering each type we care about.
I saw that Roger had implemented this for Amber, so I borrowed his
implementation, and added it as new syntax to the PMC declarations.
'pmclass' now takes two additional flags:
"hll HLL"
The High level language this PMC corresponds to.
"maps Type"
The basic parrot PMC type that this PMC correspond to
for
".HLL" usage. For example:
pmcclass TclInt hll Tcl maps Integer
allows this PMC to automatically be used when
autoboxing "I"
registers to PMCs.
Requires the "hll" flag.
This makes the generated .c file contain the appropriate code
for .HLL registration.
So, for TclString, we now define our pmc as:
pmclass TclString extends TclObject extends String dynpmc group
tcl_group hll Tcl maps String { ... }
and now this code:
.HLL 'Tcl', 'tcl_group'
.sub ''
$P1 = test()
$S1 = typeof $P1
print $S1
print_newline
.end
.sub test
.return ("coke")
.end
prints "TclString" instead of "String". (presuming you've built Tcl,
of course)
(Roger: you should steal this syntax for your Amber PMCs. =-)
Nice improvisation on an existing theme. One of these months I'll get
around to making op and pmc definitions less clunky. Meantime, I'm
glad the fix was so straightforward.
--
Chip Salzenberg <ch...@pobox.com>
> 'pmclass' now takes two additional flags ...
> (Roger: you should steal this syntax for your Amber PMCs. =-)
Thanks Will. Consider it stolen!
I see that you only handle one 'maps' directive per PMC. I think some
PMCs will use more. Consider a HLL that doesn't have any special Boolean
type. It's likely that its integer type will map both Integer and
Boolean.
My current PMCs map only one type each, so it's not an issue for me.
Regards,
Roger Browne