At 12:07 13/01/2006 +0100, Leopold Toetsch wrote:
On Jan 13, 2006, at 10:20, François PERRAD wrote:
=head1 DESCRIPTION
This test file describes an improvement for the directive .const
when an HLL is using.
Not really - see below.
.const .Integer i = "12"
The Integer PMC implements the constructor "new_from_string", which is
called at compile time to create a possibly constant PMC item with the
given value. PMC constants are frozen/thawed as usual, and above just
works. The .const pmc directive is just sugar for
set_p_pc Px, <pmc_constant>
.const .Sub _test = "_test"
A .Sub is a bit special, as the Sub PMC is already created, when a .sub
directive is encountered during codegen. So this is again just a
C<set_p_pc> opcode.
.const .LuaNumber n = "12.34"
I presume LuaNumber doesn't have new_from_string (Float hasn't either).
.const .LuaFunction _test = "_test"
Creation of Sub PMCs currently doesn't honor HLL mappings. There are a
few hardcoded references of "Sub", "Closure", and "Coroutine" in the
compiler and in packfile.c. These should be easily to spot. Explicit tests
against enum_class_Sub need to be replaced by VTABLE_isa or _does.
I start with the following patch, but I am not happy with it.
does_isa() isn't a public function (I haven't found a handle for a pmc).
It allows the expected syntax but the behavior isn't good :
the created pmc is a Sub not a LuaFunction.
François.
Index: imcparser.c
===================================================================
--- imcparser.c (revision 11318)
+++ imcparser.c (working copy)
@@ -392,6 +392,9 @@
return INS(interpreter, unit, opname, fmt, r, n, keyvec, 1);
}
+extern INTVAL
+does_isa (Interp* interpreter, STRING *method, STRING *what);
+
static Instruction*
mk_pmc_const(Parrot_Interp interp, IMC_Unit *unit,
char *type, SymReg *left, char *constant)
@@ -426,6 +429,17 @@
rhs->pmc_type = type_enum;
rhs->usage = U_FIXUP;
return INS(interp, unit, "set_p_pc", "", r, 2, 0, 1);
+ default:
+ {
+ VTABLE *vtable = Parrot_base_vtables[type_enum];
+ if (does_isa(interp, const_string(interp, "sub"),
vtable->does_str)) {
+ rhs = mk_const(interp, name, 'p');
+ r[1] = rhs;
+ rhs->pmc_type = type_enum;
+ rhs->usage = U_FIXUP;
+ return INS(interp, unit, "set_p_pc", "", r, 2, 0, 1);
+ }
+ }
}
rhs = mk_const(interp, name, 'P');
r[1] = rhs;
leo