Author: leo
Date: Mon Apr 18 05:33:22 2005
New Revision: 7860
Modified:
trunk/imcc/parser_util.c
trunk/ops/experimental.ops
trunk/src/mmd.c
trunk/src/sub.c
trunk/t/pmc/integer.t
trunk/t/pmc/mmd.t
Log:
MMD 28 - n_add opcode and friends return new result PMC
* new n_add, n_sub, ... opcodes
* basic tests in integer.t and mmd.t
* fix segfault with parrot -t and returncc in main
Modified: trunk/imcc/parser_util.c
==============================================================================
--- trunk/imcc/parser_util.c (original)
+++ trunk/imcc/parser_util.c Mon Apr 18 05:33:22 2005
@@ -324,8 +324,13 @@
int
is_op(Interp *interpreter, char *name)
{
- return interpreter->op_lib->op_code(name, 0) >= 0
- || interpreter->op_lib->op_code(name, 1) >= 0
+ int (*op_lookup)(const char *, int full) =
+ interpreter->op_lib->op_code;
+ return op_lookup(name, 0) >= 0
+ || op_lookup(name, 1) >= 0
+ || ((name[0] == 'n' && name[1] == '_')
+ && (op_lookup(name + 2, 0) >= 0
+ || op_lookup(name + 2, 1) >= 0))
|| Parrot_is_builtin(interpreter, name, NULL) >= 0;
}
@@ -337,8 +342,6 @@
char buf[10];
assert(*n >= 2);
- if (r[0]->set != 'P')
- return name;
if (*n == 3 && r[0] == r[1]) { /* cvt to inplace */
sprintf(buf, "%d", mmd_op + 1); /* XXX */
mmd = mk_const(interpreter, str_dup(buf), 'I');
@@ -355,12 +358,18 @@
(*n)++;
}
r[0] = mmd;
- return "infix";
+ if (name[0] == 'n' && name[1] == '_')
+ return "n_infix";
+ else
+ return "infix";
}
static int
-is_infix(char *name)
+is_infix(char *name, int n, SymReg **r)
{
+ if (n < 2 || r[0]->set != 'P')
+ return -1;
+
if (strcmp(name, "add") == 0)
return MMD_ADD;
if (strcmp(name, "sub") == 0)
@@ -377,6 +386,10 @@
return MMD_CMOD;
if (strcmp(name, "pow") == 0)
return MMD_POW;
+
+ /* now try n_<op> */
+ if (name[0] == 'n' && name[1] == '_')
+ return is_infix(name + 2, n, r);
return -1;
}
@@ -404,7 +417,7 @@
char format[128];
int len;
- if ( (op = is_infix(name)) >= 0) {
+ if ( (op = is_infix(name, n, r)) >= 0) {
/* sub x, y, z => infix .MMD_SUBTRACT, x, y, z */
name = to_infix(interpreter, name, r, &n, op);
}
Modified: trunk/ops/experimental.ops
==============================================================================
--- trunk/ops/experimental.ops (original)
+++ trunk/ops/experimental.ops Mon Apr 18 05:33:22 2005
@@ -266,6 +266,17 @@
General infix dispatch opcode. $1 is the MMD function number.
+=item C<n_infix(inconst INT, out PMC, in PMC, in INT)>
+
+=item C<n_infix(inconst INT, out PMC, in PMC, in NUM)>
+
+=item C<n_infix(inconst INT, out PMC, in PMC, in STR)>
+
+=item C<n_infix(inconst INT, out PMC, in PMC, in PMC)>
+
+General infix dispatch opcode. $1 is the MMD function number.
+These opcodes return a new result PMC $2.
+
=cut
inline op infix(inconst INT, in PMC, in INT) :base_core {
@@ -308,6 +319,26 @@
goto NEXT();
}
+inline op n_infix(inconst INT, out PMC, in PMC, in INT) :base_core {
+ $2 = mmd_dispatch_p_pip(interpreter, $3, $4, NULL, $1);
+ goto NEXT();
+}
+
+inline op n_infix(inconst INT, out PMC, in PMC, in NUM) :base_core {
+ $2 = mmd_dispatch_p_pnp(interpreter, $3, $4, NULL, $1);
+ goto NEXT();
+}
+
+inline op n_infix(inconst INT, out PMC, in PMC, in STR) :base_core {
+ $2 = mmd_dispatch_p_psp(interpreter, $3, $4, NULL, $1);
+ goto NEXT();
+}
+
+inline op n_infix(inconst INT, out PMC, in PMC, in PMC) :base_core {
+ $2 = mmd_dispatch_p_ppp(interpreter, $3, $4, NULL, $1);
+ goto NEXT();
+}
+
=back
###############################################################################
Modified: trunk/src/mmd.c
==============================================================================
--- trunk/src/mmd.c (original)
+++ trunk/src/mmd.c Mon Apr 18 05:33:22 2005
@@ -336,8 +336,12 @@
if (is_pmc) {
sub = (PMC*)real_function;
- return Parrot_runops_fromc_args(interpreter, sub, "PPPP",
- left, right, dest);
+ if (dest)
+ return Parrot_runops_fromc_args(interpreter, sub, "PPPP",
+ left, right, dest);
+ else
+ return Parrot_runops_fromc_args(interpreter, sub, "PPP",
+ left, right);
}
else {
return (*real_function)(interpreter, left, right, dest);
@@ -358,8 +362,12 @@
function, left_type, enum_type_INTVAL, &is_pmc);
if (is_pmc) {
sub = (PMC*)real_function;
- return Parrot_runops_fromc_args(interpreter, sub, "PPIP",
- left, right, dest);
+ if (dest)
+ return Parrot_runops_fromc_args(interpreter, sub, "PPIP",
+ left, right, dest);
+ else
+ return Parrot_runops_fromc_args(interpreter, sub, "PPI",
+ left, right);
}
else {
return (*real_function)(interpreter, left, right, dest);
@@ -380,8 +388,12 @@
function, left_type, enum_type_FLOATVAL, &is_pmc);
if (is_pmc) {
sub = (PMC*)real_function;
- return Parrot_runops_fromc_args(interpreter, sub, "PPNP",
- left, right, dest);
+ if (dest)
+ return Parrot_runops_fromc_args(interpreter, sub, "PPNP",
+ left, right, dest);
+ else
+ return Parrot_runops_fromc_args(interpreter, sub, "PPN",
+ left, right);
}
else {
return (*real_function)(interpreter, left, right, dest);
@@ -402,8 +414,12 @@
function, left_type, enum_type_STRING, &is_pmc);
if (is_pmc) {
sub = (PMC*)real_function;
- return Parrot_runops_fromc_args(interpreter, sub, "PPSP",
- left, right, dest);
+ if (dest)
+ return Parrot_runops_fromc_args(interpreter, sub, "PPSP",
+ left, right, dest);
+ else
+ return Parrot_runops_fromc_args(interpreter, sub, "PPS",
+ left, right);
}
else {
return (*real_function)(interpreter, left, right, dest);
Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c (original)
+++ trunk/src/sub.c Mon Apr 18 05:33:22 2005
@@ -531,8 +531,11 @@
STRING*
Parrot_full_sub_name(Interp* interpreter, PMC* sub)
{
- struct Parrot_sub * s = PMC_sub(sub);
+ struct Parrot_sub * s;
+ if (!sub || !VTABLE_defined(interpreter, sub))
+ return NULL;
+ s = PMC_sub(sub);
if (PMC_IS_NULL(s->name_space)) {
return s->name;
} else {
Modified: trunk/t/pmc/integer.t
==============================================================================
--- trunk/t/pmc/integer.t (original)
+++ trunk/t/pmc/integer.t Mon Apr 18 05:33:22 2005
@@ -17,7 +17,7 @@
=cut
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 11;
pir_output_is(<< 'CODE', << 'OUTPUT', "basic math");
@@ -67,7 +67,7 @@
print "A newly created Integer is "
if int_1 goto LABEL_1
print "not "
-LABEL_1:
+LABEL_1:
print "true.\n"
.local int is_defined
@@ -76,7 +76,7 @@
print "A newly created Integer is "
if is_defined goto LABEL_2
print " not "
-LABEL_2:
+LABEL_2:
print "defined.\n"
int_1 = -999999999
@@ -85,7 +85,7 @@
print " is "
if is_defined goto LABEL_3
print "not "
-LABEL_3:
+LABEL_3:
print "true.\n"
is_defined = defined int_1
@@ -94,7 +94,7 @@
print " is "
if is_defined goto LABEL_4
print "not "
-LABEL_4:
+LABEL_4:
print "defined.\n"
end
.end
@@ -306,3 +306,41 @@
ok 4
OUTPUT
+pir_output_is(<< 'CODE', << 'OUTPUT', "n_<oper>");
+.sub main @MAIN
+ $P0 = new Integer
+ $P1 = new Integer
+ set $P0, 6
+ set $P1, 2
+
+ n_add $P2, $P0, $P1
+ print $P2
+ print "\n"
+ $P2 = n_add $P0, $P1
+ print $P2
+ print "\n"
+ n_sub $P2, $P0, $P1
+ print $P2
+ print "\n"
+ n_mul $P2, $P0, $P1
+ print $P2
+ print "\n"
+ n_div $P2, $P0, $P1
+ print $P2
+ print "\n"
+ n_mod $P2, $P0, $P1
+ print $P2
+ print "\n"
+ n_pow $P2, $P0, $P1
+ print $P2
+ print "\n"
+.end
+CODE
+8
+8
+4
+12
+3
+0
+36
+OUTPUT
Modified: trunk/t/pmc/mmd.t
==============================================================================
--- trunk/t/pmc/mmd.t (original)
+++ trunk/t/pmc/mmd.t Mon Apr 18 05:33:22 2005
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 23;
+use Parrot::Test tests => 24;
pir_output_is(<<'CODE', <<'OUTPUT', "PASM divide");
@@ -781,3 +781,31 @@
42
42
OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "Integer subclasses, n_add");
+.sub main @MAIN
+ $P0 = subclass "Integer", "AInt"
+ $P0 = new "AInt"
+ $P1 = new Integer
+ set $P0, 6
+ set $P1, 2
+
+ $P2 = n_add $P0, $P1
+ print $P2
+ print "\n"
+.end
+.namespace ["AInt"]
+.sub __add @MULTI(AInt, Integer)
+ .param pmc l
+ .param pmc r
+ print l
+ print r
+ print "\n"
+ $P0 = new Integer
+ $P0 = 2
+ .return($P0)
+.end
+CODE
+62
+2
+OUTPUT