cvsuser 03/11/06 07:57:31
Modified: imcc imcc.y parser_util.c
Log:
Add support for Px = newsub _foo, _retcontinuation
Revision Changes Path
1.106 +9 -2 parrot/imcc/imcc.y
Index: imcc.y
===================================================================
RCS file: /cvs/public/parrot/imcc/imcc.y,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -w -r1.105 -r1.106
--- imcc.y 4 Nov 2003 07:48:01 -0000 1.105
+++ imcc.y 6 Nov 2003 15:57:31 -0000 1.106
@@ -375,7 +375,7 @@
t1 = mk_const(str_dup(buf), 'S');
p1 = mk_pasm_reg(str_dup("P1"));
iNEWSUB(interp, cur_unit, p1, NEWSUB,
- mk_address(((Method*)s->p)->label->name, U_add_once), 1);
+ mk_address(((Method*)s->p)->label->name, U_add_once), NULL,
1);
iINDEXSET(interp, cur_unit, p0, t1, p1);
}
}
@@ -705,7 +705,14 @@
| target '=' NEW classname COMMA var { $$ = iNEW(interp, cur_unit, $1, $4, $6,
1); }
| target '=' NEW classname { $$ = iNEW(interp, cur_unit, $1, $4,
NULL, 1); }
| target '=' newsub IDENTIFIER { $$ = iNEWSUB(interp, cur_unit, $1, $3,
- mk_address($4, U_add_once), 1); }
+ mk_address($4, U_add_once), NULL,
1); }
+ | target '=' newsub IDENTIFIER COMMA
+ IDENTIFIER { /* XXX: Fix 4arg version of newsub PASM op
+ * to use $1 instead of implicit P0
+ */
+ $$ = iNEWSUB(interp, cur_unit, NULL, $3,
+ mk_address($4, U_add_once),
+ mk_address($5, U_add_once), 1); }
| target '=' DEFINED var { $$ = MK_I(interp, cur_unit,
"defined",2, $1,$4); }
| target '=' DEFINED var '[' keylist ']' { keyvec=KEY_BIT(2);
$$ = MK_I(interp, cur_unit, "defined", 3, $1,
$4, $6); }
1.46 +46 -17 parrot/imcc/parser_util.c
Index: parser_util.c
===================================================================
RCS file: /cvs/public/parrot/imcc/parser_util.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -w -r1.45 -r1.46
--- parser_util.c 4 Nov 2003 07:47:01 -0000 1.45
+++ parser_util.c 6 Nov 2003 15:57:31 -0000 1.46
@@ -72,20 +72,22 @@
* between new and newsub.
*
* Example:
- * P0 = newsub _f ::= newsub, P0, .Sub, _f
- * P0 = newclosure _c ::= newsub, P0, .Closure, _c
+ * P0 = newsub _func ::= newsub, P0, .Sub, _func
+ * P0 = newclosure _clos ::= newsub, P0, .Closure, _clos
+ * P0 = newsub _func, _ret ::= newsub, .Sub, .RetContinuation, _func, _ret
+ * P0 = newclosure _clos, _ret ::= newsub, .Closure, .RetContinuation, _clos,
_ret
*
- * XXX: Support the return continuation form of newsub
- * XXX: IMCC is really due for a refactor. :(
+ * XXX: Currently the 3 arg version of newsub ignores the Px target on the assign.
+ * Fix the PASM opcode.
*/
Instruction *
iNEWSUB(struct Parrot_Interp *interpreter, IMC_Unit * unit, SymReg * r0, int type,
- SymReg *init, int emit)
+ SymReg *subinit, SymReg *retinit, int emit)
{
char fmt[256];
SymReg *regs[IMCC_MAX_REGS];
- SymReg *pmc;
+ SymReg *subpmc, *retpmc;
int i, nargs;
int pmc_num;
const char * classnm = NULL;
@@ -103,27 +105,54 @@
string_from_cstring(interpreter, classnm, 0));
sprintf(fmt, "%d", pmc_num);
- pmc = mk_const(str_dup(fmt), 'I');
+ subpmc = mk_const(str_dup(fmt), 'I');
if (pmc_num <= 0)
fataly(1, sourcefile, line, "Unknown PMC type '%s'\n", classnm);
sprintf(fmt, "%%s, %d\t # .%s", pmc_num, classnm);
- r0->usage = U_NEW;
+ /* 1st form: px = newsub _foo */
+ if(!retinit) {
+ r0->usage = U_NEW;
regs[0] = r0;
- regs[1] = pmc;
- if (init) {
- regs[2] = init;
+ regs[1] = subpmc;
+ if (subinit) {
+ regs[2] = subinit;
nargs = 3;
}
else
nargs = 2;
+ }
+ /* 2nd form: px = newsub _foo, _retcont
+ *
+ * XXX: Currently px is ignored, this op sets P0/P1 implicitly
+ */
+ else {
+ if(!subinit) { /* sanity check */
+ fataly(1, sourcefile, line, "iNEWSUB: NULL $0 for newsub\n");
+ }
+
+ /* The return continuation */
+ pmc_num = pmc_type(interpreter,
+ string_from_cstring(interpreter, "RetContinuation", 0));
+
+ sprintf(fmt, "%d", pmc_num);
+ retpmc = mk_const(str_dup(fmt), 'I');
+
+ regs[0] = subpmc;
+ regs[1] = retpmc;
+ regs[2] = subinit;
+ regs[3] = retinit;
+ nargs = 4;
+ }
+
i = nargs;
while (i < IMCC_MAX_REGS)
regs[i++] = NULL;
return INS(interpreter, unit, "newsub", NULL, regs, nargs,0, emit);
}
+
void
op_fullname(char * dest, const char * name, SymReg * args[],
int narg, int keyvec) {