[svn:parrot] r44753 - in trunk: src/pmc t/pmc
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Mon Mar 8 01:49:13 UTC 2010
Author: plobsing
Date: Mon Mar 8 01:49:12 2010
New Revision: 44753
URL: https://trac.parrot.org/parrot/changeset/44753
Log:
freeze/thaw for Complex
Modified:
trunk/src/pmc/complex.pmc
trunk/t/pmc/complex.t
Modified: trunk/src/pmc/complex.pmc
==============================================================================
--- trunk/src/pmc/complex.pmc Mon Mar 8 01:38:08 2010 (r44752)
+++ trunk/src/pmc/complex.pmc Mon Mar 8 01:49:12 2010 (r44753)
@@ -329,6 +329,42 @@
/*
+=item C<void freeze(PMC *visit)>
+
+=item C<void thaw(PMC *visit)>
+
+Serialize/deserialize this object for bytecode.
+
+=cut
+
+*/
+
+ VTABLE void freeze(PMC *visit) {
+ FLOATVAL re, im;
+
+ SUPER(visit);
+
+ GET_ATTR_re(INTERP, SELF, re);
+ VTABLE_push_float(INTERP, visit, re);
+
+ GET_ATTR_im(INTERP, SELF, im);
+ VTABLE_push_float(INTERP, visit, im);
+ }
+
+ VTABLE void thaw(PMC *visit) {
+ FLOATVAL re, im;
+
+ SUPER(visit);
+
+ re = VTABLE_shift_float(INTERP, visit);
+ SET_ATTR_re(INTERP, SELF, re);
+
+ im = VTABLE_shift_float(INTERP, visit);
+ SET_ATTR_im(INTERP, SELF, im);
+ }
+
+/*
+
=item C<INTVAL get_integer()>
Returns the modulus of the complex number as an integer.
Modified: trunk/t/pmc/complex.t
==============================================================================
--- trunk/t/pmc/complex.t Mon Mar 8 01:38:08 2010 (r44752)
+++ trunk/t/pmc/complex.t Mon Mar 8 01:49:12 2010 (r44753)
@@ -21,7 +21,7 @@
.include 'fp_equality.pasm'
.include "iglobals.pasm"
- plan(458)
+ plan(459)
string_parsing()
exception_malformed_string__real_part()
@@ -50,6 +50,7 @@
instantiate__pir__s()
test_complex_neg()
test_clone()
+ test_freeze_thaw()
test_sub()
test_i_sub()
sprintf_with_a_complex()
@@ -591,6 +592,14 @@
.fp_eq_ok($N1, -3.0, '... nor to imag portion')
.end
+.sub test_freeze_thaw
+ $P0 = new ['Complex']
+ set $P0, "1 - 3i"
+ $S0 = freeze $P0
+ $P1 = thaw $S0
+ is($P0, $P1, 'roundtrip serialize Complex PMC')
+.end
+
.sub test_sub
.local pmc d, f, c
d = new ['Undef']
More information about the parrot-commits
mailing list