Permalink
Browse files

[Lua]

- refactoring PMC
  • Loading branch information...
1 parent 0d12c02 commit f87ff507348132205163f401c49237fa62d05a26 fperrad committed Apr 6, 2007
Showing with 50 additions and 45 deletions.
  1. +2 −2 pmc/luaany.pmc
  2. +35 −30 pmc/luanumber.pmc
  3. +13 −13 pmc/luastring.pmc
View
@@ -559,7 +559,7 @@ Throws an exception.
}
real_exception(INTERP, NULL, ILL_INHERIT,
"attempt to get length of a %s value",
- string_to_cstring(INTERP, VTABLE_name(INTERP, SELF)));
+ string_to_cstring(INTERP, DYNSELF.name()));
return NULL;
}
@@ -599,7 +599,7 @@ Common implementation (use C<__tostring> or C<get_string>).
}
else {
retval = pmc_new(INTERP, dynpmc_LuaString);
- PMC_str_val(retval) = VTABLE_get_string(INTERP, SELF);
+ PMC_str_val(retval) = DYNSELF.get_string();
}
return retval;
}
View
@@ -204,8 +204,8 @@ Returns a Parrot string representation of the number.
*/
void set_string_native (STRING *value) {
- VTABLE_morph(INTERP, SELF, dynpmc_LuaString);
- VTABLE_set_string_native(INTERP, SELF, value);
+ SELF.morph(dynpmc_LuaString);
+ DYNSELF.set_string_native(value);
}
/*
@@ -242,7 +242,7 @@ Decrements the number.
*/
PMC* neg (PMC * dest) {
- FLOATVAL a = - DYNSELF.get_number();
+ FLOATVAL a = - SELF.get_number();
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
VTABLE_set_number_native(INTERP, dest, a);
@@ -257,8 +257,8 @@ Decrements the number.
*/
void i_neg () {
- FLOATVAL a = - DYNSELF.get_number();
- VTABLE_set_number_native(INTERP, SELF, a);
+ FLOATVAL a = - SELF.get_number();
+ SELF.set_number_native(a);
}
/*
@@ -279,7 +279,7 @@ MMD_LuaNumber: {
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
VTABLE_set_number_native(INTERP, dest,
- DYNSELF.get_number() + VTABLE_get_number(INTERP, value));
+ SELF.get_number() + VTABLE_get_number(INTERP, value));
return dest;
}
MMD_LuaString: {
@@ -320,8 +320,9 @@ MMD_DEFAULT: {
*/
void i_add (PMC* value) {
MMD_LuaNumber: {
- VTABLE_set_number_native(INTERP, SELF,
- DYNSELF.get_number() + VTABLE_get_number(INTERP, value));
+ FLOATVAL n = SELF.get_number()
+ + VTABLE_get_number(INTERP, value);
+ SELF.set_number_native(n);
}
MMD_LuaString: {
PMC* n = LuaString.value.tonumber();
@@ -362,7 +363,7 @@ MMD_LuaNumber: {
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
VTABLE_set_number_native(INTERP, dest,
- DYNSELF.get_number() - VTABLE_get_number(INTERP, value));
+ SELF.get_number() - VTABLE_get_number(INTERP, value));
return dest;
}
MMD_LuaString: {
@@ -404,8 +405,9 @@ MMD_DEFAULT: {
*/
void i_subtract (PMC* value) {
MMD_LuaNumber: {
- VTABLE_set_number_native(INTERP, SELF,
- DYNSELF.get_number() - VTABLE_get_number(INTERP, value));
+ FLOATVAL n = SELF.get_number()
+ - VTABLE_get_number(INTERP, value);
+ SELF.set_number_native(n);
}
MMD_LuaString: {
PMC* n = LuaString.value.tonumber();
@@ -446,7 +448,7 @@ MMD_LuaNumber: {
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
VTABLE_set_number_native(INTERP, dest,
- DYNSELF.get_number() * VTABLE_get_number(INTERP, value));
+ SELF.get_number() * VTABLE_get_number(INTERP, value));
return dest;
}
MMD_LuaString: {
@@ -488,8 +490,9 @@ MMD_DEFAULT: {
*/
void i_multiply (PMC* value) {
MMD_LuaNumber: {
- VTABLE_set_number_native(INTERP, SELF,
- DYNSELF.get_number() * VTABLE_get_number(INTERP, value));
+ FLOATVAL n = SELF.get_number()
+ * VTABLE_get_number(INTERP, value);
+ SELF.set_number_native(n);
}
MMD_LuaString: {
PMC* n = LuaString.value.tonumber();
@@ -530,7 +533,7 @@ MMD_LuaNumber: {
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
VTABLE_set_number_native(INTERP, dest,
- DYNSELF.get_number() / VTABLE_get_number(INTERP, value));
+ SELF.get_number() / VTABLE_get_number(INTERP, value));
return dest;
}
MMD_LuaString: {
@@ -572,8 +575,9 @@ MMD_DEFAULT: {
*/
void i_divide (PMC* value) {
MMD_LuaNumber: {
- VTABLE_set_number_native(INTERP, SELF,
- DYNSELF.get_number() / VTABLE_get_number(INTERP, value));
+ FLOATVAL n = SELF.get_number()
+ / VTABLE_get_number(INTERP, value);
+ SELF.set_number_native(n);
}
MMD_LuaString: {
PMC* n = LuaString.value.tonumber();
@@ -611,7 +615,7 @@ MMD_DEFAULT: {
*/
PMC* modulus (PMC* value, PMC* dest) {
MMD_LuaNumber: {
- FLOATVAL a = DYNSELF.get_number();
+ FLOATVAL a = SELF.get_number();
FLOATVAL b = VTABLE_get_number(INTERP, value);
if (!dest)
@@ -658,10 +662,10 @@ MMD_DEFAULT: {
*/
void i_modulus (PMC* value) {
MMD_LuaNumber: {
- FLOATVAL a = DYNSELF.get_number();
+ FLOATVAL a = SELF.get_number();
FLOATVAL b = VTABLE_get_number(INTERP, value);
- VTABLE_set_number_native(INTERP, SELF, a - floor(a/b)*b);
+ SELF.set_number_native(a - floor(a/b)*b);
}
MMD_LuaString: {
PMC* n = LuaString.value.tonumber();
@@ -702,7 +706,7 @@ MMD_LuaNumber: {
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
VTABLE_set_number_native(INTERP, dest,
- pow(DYNSELF.get_number(), VTABLE_get_number(INTERP, value)));
+ pow(SELF.get_number(), VTABLE_get_number(INTERP, value)));
return dest;
}
MMD_LuaString: {
@@ -743,8 +747,9 @@ MMD_DEFAULT: {
*/
void i_pow (PMC* value) {
MMD_LuaNumber: {
- VTABLE_set_number_native(INTERP, SELF,
- pow(DYNSELF.get_number(), VTABLE_get_number(INTERP, value)));
+ FLOATVAL n = pow(SELF.get_number(),
+ VTABLE_get_number(INTERP, value));
+ SELF.set_number_native(n);
}
MMD_LuaString: {
PMC* n = LuaString.value.tonumber();
@@ -820,7 +825,7 @@ MMD_DEFAULT: {
PMC* concatenate (PMC* value, PMC* dest) {
MMD_LuaNumber: {
STRING* s = string_concat(INTERP,
- DYNSELF.get_string(),
+ SELF.get_string(),
VTABLE_get_string(INTERP, value), 0);
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
@@ -829,7 +834,7 @@ MMD_LuaNumber: {
}
MMD_LuaString: {
STRING* s = string_concat(INTERP,
- DYNSELF.get_string(),
+ SELF.get_string(),
VTABLE_get_string(INTERP, value), 0);
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
@@ -862,14 +867,14 @@ MMD_DEFAULT: {
*/
void i_concatenate (PMC* value) {
MMD_LuaNumber: {
- STRING* s = DYNSELF.get_string();
+ STRING* s = SELF.get_string();
STRING* v = VTABLE_get_string(INTERP, value);
- DYNSELF.set_string_native(string_append(INTERP, s, v));
+ SELF.set_string_native(string_append(INTERP, s, v));
}
MMD_LuaString: {
- STRING* s = DYNSELF.get_string();
+ STRING* s = SELF.get_string();
STRING* v = VTABLE_get_string(INTERP, value);
- DYNSELF.set_string_native(string_append(INTERP, s, v));
+ SELF.set_string_native(string_append(INTERP, s, v));
}
MMD_DEFAULT: {
PMC *meth = find_meth(INTERP, value, "__concat");
@@ -922,7 +927,7 @@ MMD_DEFAULT: {
METHOD PMC* tonumber() {
PMC *retval;
- retval = VTABLE_clone(INTERP, SELF);
+ retval = SELF.clone();
return retval;
}
View
@@ -167,8 +167,8 @@ Return the string "string".
*/
void set_number_native(FLOATVAL value) {
- VTABLE_morph(INTERP, SELF, dynpmc_LuaNumber);
- VTABLE_set_number_native(INTERP, SELF, value);
+ SELF.morph(dynpmc_LuaNumber);
+ DYNSELF.set_number_native(value);
}
/*
@@ -179,8 +179,8 @@ Return the string "string".
*/
void set_number_native (FLOATVAL value) {
- VTABLE_morph(INTERP, SELF, dynpmc_LuaNumber);
- VTABLE_set_number_native(INTERP, SELF, value);
+ SELF.morph(dynpmc_LuaNumber);
+ DYNSELF.set_number_native(value);
}
/*
@@ -921,7 +921,7 @@ MMD_DEFAULT: {
PMC* concatenate (PMC* value, PMC* dest) {
MMD_LuaNumber: {
STRING* s = string_concat(INTERP,
- DYNSELF.get_string(),
+ SELF.get_string(),
VTABLE_get_string(INTERP, value), 0);
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
@@ -930,7 +930,7 @@ MMD_LuaNumber: {
}
MMD_LuaString: {
STRING* s = string_concat(INTERP,
- DYNSELF.get_string(),
+ SELF.get_string(),
VTABLE_get_string(INTERP, value), 0);
if (!dest)
dest = pmc_new(INTERP, SELF->vtable->base_type);
@@ -963,14 +963,14 @@ MMD_DEFAULT: {
*/
void i_concatenate (PMC* value) {
MMD_LuaNumber: {
- STRING* s = DYNSELF.get_string();
+ STRING* s = SELF.get_string();
STRING* v = VTABLE_get_string(INTERP, value);
- DYNSELF.set_string_native(string_append(INTERP, s, v));
+ SELF.set_string_native(string_append(INTERP, s, v));
}
MMD_LuaString: {
- STRING* s = DYNSELF.get_string();
+ STRING* s = SELF.get_string();
STRING* v = VTABLE_get_string(INTERP, value);
- DYNSELF.set_string_native(string_append(INTERP, s, v));
+ SELF.set_string_native(string_append(INTERP, s, v));
}
MMD_DEFAULT: {
PMC *meth = find_meth(INTERP, value, "__concat");
@@ -1021,7 +1021,7 @@ MMD_DEFAULT: {
PMC *retval;
retval = pmc_new(INTERP, dynpmc_LuaNumber);
- PMC_num_val(retval) = VTABLE_elements(INTERP, SELF);
+ PMC_num_val(retval) = SELF.elements();
return retval;
}
@@ -1058,7 +1058,7 @@ MMD_DEFAULT: {
char *s1;
char *s2;
- rep = VTABLE_get_string(INTERP, SELF);
+ rep = SELF.get_string();
s1 = string_to_cstring(INTERP, rep);
d = strtod(s1, &s2);
if (s1 != s2) { /* at least one valid digit? */
@@ -1088,7 +1088,7 @@ MMD_DEFAULT: {
char *s1;
char *s2;
- rep = VTABLE_get_string(INTERP, SELF);
+ rep = SELF.get_string();
s1 = string_to_cstring(INTERP, rep);
n = strtoul(s1, &s2, base);
if (s1 != s2) { /* at least one valid digit? */

0 comments on commit f87ff50

Please sign in to comment.