cvsuser 05/04/05 09:02:27
Modified: classes integer.pmc
t/pmc mmd.t
Log:
MMD 19 - subclassed Integer
Revision Changes Path
1.26 +18 -3 parrot/classes/integer.pmc
Index: integer.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/integer.pmc,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- integer.pmc 27 Mar 2005 13:14:18 -0000 1.25
+++ integer.pmc 5 Apr 2005 16:02:26 -0000 1.26
@@ -420,8 +420,23 @@
void add (PMC* value, PMC* dest) {
MMD_Integer: {
- INTVAL a = PMC_int_val(SELF);
- INTVAL b = PMC_int_val(value);
+ /*
+ * SELF and value can both be PMCs that inherit
+ * from Integer:
+ * cl = subclass "Integer", "MyInt"
+ * so we can't used PMC_int_val(SELF) in any of these
+ * Integer methods
+ *
+ * TODO one of
+ * a) remember MMD distance of this call
+ * (works only for dynamic dispatch)
+ * b) check for exact Integer type
+ * c) create MMD_Any_Integer MMD
+ * d) or dispatch to MMD_DEFAULT
+ */
+
+ INTVAL a = VTABLE_get_integer(INTERP, SELF);
+ INTVAL b = VTABLE_get_integer(INTERP, value);
INTVAL c = a + b;
if ((c^a) >= 0 || (c^b) >= 0)
VTABLE_set_integer_native(INTERP, dest, c);
1.24 +34 -2 parrot/t/pmc/mmd.t
Index: mmd.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/mmd.t,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- mmd.t 4 Apr 2005 16:03:28 -0000 1.23
+++ mmd.t 5 Apr 2005 16:02:27 -0000 1.24
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 22;
+use Parrot::Test tests => 23;
pir_output_is(<<'CODE', <<'OUTPUT', "PASM divide");
@@ -744,3 +744,35 @@
42.42
42
OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "Integer subclasses");
+.sub main @MAIN
+ .local pmc d, l, r, cl
+ cl = subclass "Integer", "AInt"
+ d = new "AInt"
+ l = new "AInt"
+ r = new "AInt"
+ l = 3
+ r = 39
+ print l
+ print "\n"
+ print r
+ print "\n"
+ # this works only by calling the mmd_fallback
+ add d, l, r
+ print d
+ print "\n"
+ # dispatches to Parrot_Integer_add_Integer
+ l."__add"(r, d)
+ print d
+ print "\n"
+.end
+
+
+
+CODE
+3
+39
+42
+42
+OUTPUT