Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
vtable pow & i_pow are gone, since the merge of branch vtable_massacre
Browse files Browse the repository at this point in the history
(see http://trac.parrot.org/parrot/changeset/43921).
currently, we lost the support of metamethod __pow.
  • Loading branch information
fperrad committed Feb 13, 2010
1 parent 2e0135a commit cdc873f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 222 deletions.
47 changes: 15 additions & 32 deletions dynext/pmc/luaany.pmc
Expand Up @@ -104,6 +104,21 @@ Returns C<true>.

/*

=item C<FLOATVAL get_number()>

Throws an exception.

=cut

*/
VTABLE FLOATVAL get_number() {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value", SELF.name());
return 0.0;
}

/*

=item C<void *get_pointer()>

Returns the address of the PMC.
Expand Down Expand Up @@ -299,10 +314,6 @@ Throws an exception.

=item C<void i_modulus(PMC *value)>

=item C<PMC* pow(PMC *value, PMC *dest)>

=item C<void i_pow(PMC *value)>

=item C<PMC* concatenate(PMC *value, PMC *dest)>

=item C<void i_concatenate(PMC *value)>
Expand Down Expand Up @@ -448,34 +459,6 @@ Throws an exception.
SELF = pmc_new(INTERP, dynpmc_LuaNil);
}

MULTI PMC* pow(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__pow");

if (PMC_IS_NULL(meth))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value", SELF.name());

Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);

if (PMC_IS_NULL(dest))
return pmc_new(INTERP, dynpmc_LuaNil);

return dest;
}

MULTI void i_pow(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__pow");

if (PMC_IS_NULL(meth))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value", SELF.name());

Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);

if (PMC_IS_NULL(SELF))
SELF = pmc_new(INTERP, dynpmc_LuaNil);
}

MULTI PMC* concatenate(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__concat");

Expand Down
84 changes: 0 additions & 84 deletions dynext/pmc/luanumber.pmc
Expand Up @@ -690,90 +690,6 @@ Used to unarchive the number.

/*

=item C<PMC *pow(PMC *value, PMC *dest)>

=cut

*/
MULTI PMC *pow(LuaNumber value, PMC *dest) {
const FLOATVAL n = pow(SELF.get_number(),
VTABLE_get_number(INTERP, value));
dest = pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}

MULTI PMC *pow(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber)
return Parrot_LuaNumber_multi_pow_LuaNumber_PMC(INTERP, SELF, n, dest);

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}

MULTI PMC *pow(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__pow");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = pmc_new(INTERP, dynpmc_LuaNil);

return dest;
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}

/*

=item C<void i_pow(PMC *value)>

=cut

*/
MULTI void i_pow(LuaNumber value) {
const FLOATVAL n = pow(SELF.get_number(),
VTABLE_get_number(INTERP, value));
SELF.set_number_native(n);
}

MULTI void i_pow(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_LuaNumber_multi_i_pow_LuaNumber(INTERP, SELF, n);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}

MULTI void i_pow(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__pow");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = pmc_new(INTERP, dynpmc_LuaNil);

return;
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}

/*

=item C<INTVAL is_equal(PMC *value)>

=cut
Expand Down
128 changes: 22 additions & 106 deletions dynext/pmc/luastring.pmc
Expand Up @@ -86,6 +86,28 @@ Creates a copy of the string.

/*

=item C<FLOATVAL get_number()>

Returns a number or throws an exception.

=cut

*/
VTABLE FLOATVAL get_number() {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, SELF,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber)
return VTABLE_get_number(INTERP, n);

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value", SELF.name());
return 0.0;
}

/*

=item C<STRING* get_string()>

Returns the string itself.
Expand Down Expand Up @@ -785,112 +807,6 @@ Used to unarchive the string.

/*

=item C<PMC* pow(PMC *value, PMC *dest)>

=cut

*/
MULTI PMC* pow(LuaNumber value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, SELF,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber) {
PMC *result = PMCNULL;
Parrot_mmd_multi_dispatch_from_c_args(INTERP,
"pow", "PPP->P", n, value, dest, &result);
return result;
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value", SELF.name());
}

MULTI PMC* pow(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, SELF,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber) {
PMC *result = PMCNULL;
Parrot_mmd_multi_dispatch_from_c_args(INTERP,
"pow", "PPP->P", n, value, dest, &result);
return result;
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value", SELF.name());
}

MULTI PMC* pow(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__pow");

if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = pmc_new(INTERP, dynpmc_LuaNil);

return dest;
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}

/*

=item C<void i_pow(PMC *value)>

=cut

*/
MULTI void i_pow(LuaNumber value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, SELF,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_mmd_multi_dispatch_from_c_args(INTERP,
"i_pow", "PP", n, value);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
SELF.name());
}

MULTI void i_pow(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, SELF,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);

if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_mmd_multi_dispatch_from_c_args(INTERP,
"i_pow", "PP", n, value);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
SELF.name());
}

MULTI void i_pow(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__pow");

if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = pmc_new(INTERP, dynpmc_LuaNil);

return;
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}

/*

=item C<INTVAL is_equal(PMC *value)>

Compares the string with C<value>; returns true if
Expand Down

0 comments on commit cdc873f

Please sign in to comment.