[svn:parrot] r41660 - branches/pcc_reapply/src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sun Oct 4 01:08:57 UTC 2009
Author: bacek
Date: Sun Oct 4 01:08:56 2009
New Revision: 41660
URL: https://trac.parrot.org/parrot/changeset/41660
Log:
Revamp CPointer casting to DTRT.
Modified:
branches/pcc_reapply/src/pmc/cpointer.pmc
Modified: branches/pcc_reapply/src/pmc/cpointer.pmc
==============================================================================
--- branches/pcc_reapply/src/pmc/cpointer.pmc Sun Oct 4 01:08:32 2009 (r41659)
+++ branches/pcc_reapply/src/pmc/cpointer.pmc Sun Oct 4 01:08:56 2009 (r41660)
@@ -190,18 +190,27 @@
VTABLE INTVAL get_integer() {
Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
-
+
if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
- const INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
return *int_pointer;
}
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ return (INTVAL)*num_pointer;
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ STRING ** const str_pointer = (STRING **) data->pointer;
+ return Parrot_str_to_int(INTERP, *str_pointer);
+ }
else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
- return VTABLE_get_integer(interp, *pmc_pointer);
+ return VTABLE_get_integer(INTERP, *pmc_pointer);
+ }
+ else {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Unable to fetch value, broken signature!");
}
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to fetch integer value, the pointer is not an integer");
-
}
/*
@@ -222,13 +231,21 @@
INTVAL * const int_pointer = (INTVAL *) data->pointer;
*int_pointer = value;
}
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ *num_pointer = value;
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ STRING ** const str_pointer = (STRING **) data->pointer;
+ *str_pointer = Parrot_str_from_int(INTERP, value);
+ }
else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
- VTABLE_set_integer_native(interp, *pmc_pointer, value);
+ *pmc_pointer = get_integer_pmc(INTERP, value);
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to set integer value, the pointer is not an integer");
+ "Unable to set value, broken signature!");
}
}
@@ -246,16 +263,26 @@
VTABLE FLOATVAL get_number() {
Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
- if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
- const FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ return (FLOATVAL)*int_pointer;
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
return *num_pointer;
}
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ STRING ** const str_pointer = (STRING **) data->pointer;
+ return Parrot_str_to_num(INTERP, *str_pointer);
+ }
else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
- return VTABLE_get_number(interp, *pmc_pointer);
+ return VTABLE_get_number(INTERP, *pmc_pointer);
+ }
+ else {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Unable to fetch value, broken signature!");
}
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to fetch number value, the pointer is not a number");
}
/*
@@ -272,17 +299,25 @@
VTABLE void set_number_native(FLOATVAL value) {
Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
- if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ *int_pointer = (INTVAL)value;
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
*num_pointer = value;
}
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ STRING ** const str_pointer = (STRING **) data->pointer;
+ *str_pointer = Parrot_str_from_num(INTERP, value);
+ }
else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
- VTABLE_set_number_native(interp, *pmc_pointer, value);
+ *pmc_pointer = get_number_pmc(INTERP, value);
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to set number value, the pointer is not a number");
+ "Unable to set value, broken signature!");
}
}
@@ -300,16 +335,26 @@
VTABLE STRING *get_string() {
Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
- if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ return Parrot_str_from_int(INTERP, *int_pointer);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ return Parrot_str_from_num(INTERP, *num_pointer);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
STRING ** const str_pointer = (STRING **) data->pointer;
return *str_pointer;
}
else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
- return VTABLE_get_string(interp, *pmc_pointer);
+ return VTABLE_get_string(INTERP, *pmc_pointer);
+ }
+ else {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Unable to fetch value, broken signature!");
}
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to fetch string value, the pointer is not a string");
}
/*
@@ -326,17 +371,25 @@
VTABLE void set_string_native(STRING *value) {
Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
- if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ *int_pointer = Parrot_str_to_int(INTERP, value);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ *num_pointer = Parrot_str_to_num(INTERP, value);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
STRING ** const str_pointer = (STRING **) data->pointer;
*str_pointer = value;
}
else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
- VTABLE_set_string_native(interp, *pmc_pointer, value);
+ *pmc_pointer = get_string_pmc(INTERP, value);
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to set string value, the pointer is not a string");
+ "Unable to set value, broken signature!");
}
}
@@ -352,13 +405,27 @@
VTABLE PMC *get_pmc() {
const Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
-
- if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
+
+ if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ return get_integer_pmc(INTERP, *int_pointer);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ return get_number_pmc(INTERP, *num_pointer);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ STRING ** const str_pointer = (STRING **) data->pointer;
+ return get_string_pmc(INTERP, *str_pointer);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
return *pmc_pointer;
}
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to fetch PMC value, the pointer is not a PMC");
+ else {
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Unable to fetch value, broken signature!");
+ }
}
/*
@@ -374,13 +441,25 @@
VTABLE void set_pmc(PMC *value) {
const Parrot_CPointer_attributes * const data = PARROT_CPOINTER(SELF);
- if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
+ if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "I"))) {
+ INTVAL * const int_pointer = (INTVAL *) data->pointer;
+ *int_pointer = VTABLE_get_integer(INTERP, value);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "N"))) {
+ FLOATVAL * const num_pointer = (FLOATVAL *) data->pointer;
+ *num_pointer = VTABLE_get_number(INTERP, value);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "S"))) {
+ STRING ** const str_pointer = (STRING **) data->pointer;
+ *str_pointer = VTABLE_get_string(INTERP, value);
+ }
+ else if (Parrot_str_equal(interp, data->sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) data->pointer;
*pmc_pointer = value;
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "Unable to set PMC value, the pointer is not a PMC");
+ "Unable to set value, broken signature!");
}
}
More information about the parrot-commits
mailing list