Author: cotto
Date: Thu Aug 21 10:01:26 2008
New Revision: 30426
Modified:
trunk/languages/pipp/src/pmc/phpboolean.pmc
trunk/languages/pipp/src/pmc/phpfloat.pmc
trunk/languages/pipp/src/pmc/phpinteger.pmc
trunk/languages/pipp/src/pmc/phpstring.pmc
trunk/languages/pipp/src/pmc/phpundef.pmc
Log:
[pipp] add serialize METHODs to most of the scalar PMCs
Modified: trunk/languages/pipp/src/pmc/phpboolean.pmc
==============================================================================
--- trunk/languages/pipp/src/pmc/phpboolean.pmc (original)
+++ trunk/languages/pipp/src/pmc/phpboolean.pmc Thu Aug 21 10:01:26 2008
@@ -66,10 +66,21 @@
=over 4
+=item C<STRING* serialize()>
+
+Return a representation of this boolean in the same format as PHP's serialize
function.
+
=cut
*/
+ METHOD STRING* serialize() {
+ STRING *serialized;
+ serialized = string_printf(INTERP, "b:%d;", VTABLE_get_integer(INTERP,
SELF));
+ RETURN(STRING *serialized);
+ }
+
+
/*
=back
Modified: trunk/languages/pipp/src/pmc/phpfloat.pmc
==============================================================================
--- trunk/languages/pipp/src/pmc/phpfloat.pmc (original)
+++ trunk/languages/pipp/src/pmc/phpfloat.pmc Thu Aug 21 10:01:26 2008
@@ -48,10 +48,30 @@
=over 4
+=item C<STRING* serialize()>
+
+Return a representation of this float in the same format as PHP's serialize
function.
+
=cut
*/
+ METHOD STRING* serialize() {
+ STRING *serialized;
+ INTVAL zero_index = -1;
+
+ /* PHP's serialized floats stringify the exact value stored rather than
+ * just the significant digits. */
+ serialized = string_printf(INTERP, "%.*f", 100,
VTABLE_get_number(INTERP, SELF));
+ while (string_ord(INTERP, serialized, zero_index - 1) == '0')
+ zero_index--;
+
+ serialized = string_chopn(INTERP, serialized, 0 - zero_index);
+ serialized = string_printf(INTERP, "f:%Ss;", serialized);
+ RETURN(STRING *serialized);
+ }
+
+
/*
=back
Modified: trunk/languages/pipp/src/pmc/phpinteger.pmc
==============================================================================
--- trunk/languages/pipp/src/pmc/phpinteger.pmc (original)
+++ trunk/languages/pipp/src/pmc/phpinteger.pmc Thu Aug 21 10:01:26 2008
@@ -67,6 +67,22 @@
RETURN(PMC *SELF);
}
+/*
+
+=item C<STRING* serialize()>
+
+Return a representation of this integer in the same format as PHP's serialize
function.
+
+=cut
+
+*/
+ METHOD STRING* serialize() {
+ STRING *serialized;
+ serialized = string_printf(INTERP, "i:%d;", VTABLE_get_integer(INTERP,
SELF));
+ RETURN(STRING *serialized);
+ }
+
+
}
/*
Modified: trunk/languages/pipp/src/pmc/phpstring.pmc
==============================================================================
--- trunk/languages/pipp/src/pmc/phpstring.pmc (original)
+++ trunk/languages/pipp/src/pmc/phpstring.pmc Thu Aug 21 10:01:26 2008
@@ -162,8 +162,26 @@
RETURN(PMC *retval);
}
+/*
+
+=item C<STRING* serialize()>
+
+Return a representation of this string in the same format as PHP's serialize
function.
+
+=cut
+
+*/
+ METHOD STRING* serialize() {
+ STRING *serialized;
+ serialized = string_printf(INTERP, "s:%d:\"%Ss\";",
VTABLE_elements(INTERP, SELF),
+ VTABLE_get_string(INTERP, SELF));
+ RETURN(STRING *serialized);
+ }
+
+
}
+
/*
=back
Modified: trunk/languages/pipp/src/pmc/phpundef.pmc
==============================================================================
--- trunk/languages/pipp/src/pmc/phpundef.pmc (original)
+++ trunk/languages/pipp/src/pmc/phpundef.pmc Thu Aug 21 10:01:26 2008
@@ -50,8 +50,21 @@
=cut
+=item C<STRING* serialize()>
+
+Return a representation of this PMC in the same format as PHP's serialize
function.
+
+=cut
+
*/
+ METHOD STRING* serialize() {
+ STRING *serialized;
+ serialized = CONST_STRING(INTERP, "N;");
+ RETURN(STRING *serialized);
+ }
+
+
/*
=back