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

Commit

Permalink
full refactor with PMCNULL & PMC_IS_NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Sep 29, 2009
1 parent 6df18b2 commit e2e4a89
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 105 deletions.
73 changes: 36 additions & 37 deletions src/pmc/luaany.pmc
Expand Up @@ -52,7 +52,7 @@ The metatable supports the OO mecanism.

PMC *
_LuaAny_find_meth(PARROT_INTERP, PMC *obj, const char *name) {
PMC *meta = NULL;
PMC *meta = PMCNULL;
const INTVAL type = PMC_type(obj);

if (type == dynpmc_LuaTable) {
Expand All @@ -65,8 +65,8 @@ _LuaAny_find_meth(PARROT_INTERP, PMC *obj, const char *name) {
meta = _LuaString_get_metatable(interp);
}

if (!meta)
return NULL;
if (PMC_IS_NULL(meta))
return PMCNULL;

if (dynpmc_LuaTable != PMC_type(meta)) {
return meta;
Expand All @@ -78,7 +78,7 @@ _LuaAny_find_meth(PARROT_INTERP, PMC *obj, const char *name) {

method = VTABLE_get_pmc_keyed(interp, meta, key);

return (dynpmc_LuaNil != PMC_type(method)) ? method : NULL;
return (dynpmc_LuaNil != PMC_type(method)) ? method : PMCNULL;
}
}

Expand Down Expand Up @@ -142,21 +142,20 @@ Throws an exception.
VTABLE PMC* get_pmc_keyed(PMC *key) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__index");

if (meth) {
if (dynpmc_LuaFunction == PMC_type(meth)) {
PMC * const retval = Parrot_runops_fromc_args(INTERP, meth, "PPP",
SELF, key);
if (retval)
return retval;
if (PMC_IS_NULL(meth))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to index a %Ss value", SELF.name());

if (dynpmc_LuaFunction == PMC_type(meth)) {
PMC * const retval = Parrot_runops_fromc_args(INTERP, meth, "PPP",
SELF, key);
if (PMC_IS_NULL(retval))
return pmc_new(INTERP, dynpmc_LuaNil);
}
else
return VTABLE_get_pmc_keyed(INTERP, meth, key);
}

Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to index a %Ss value", SELF.name());
return retval;
}
else
return VTABLE_get_pmc_keyed(INTERP, meth, key);
}

/*
Expand All @@ -171,7 +170,7 @@ Throws an exception.
VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__newindex");

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

Expand All @@ -197,7 +196,7 @@ Throws an exception.
VTABLE PMC* neg(PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__unm");

if (!meth)
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());

Expand All @@ -212,7 +211,7 @@ Throws an exception.
VTABLE void i_neg() {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__unm");

if (!meth)
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());

Expand Down Expand Up @@ -264,14 +263,14 @@ Throws an exception.
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__call");
PMC *retval;

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

/* fix me */
#if 1
retval = Parrot_runops_fromc_args(INTERP, meth, "PP", SELF);
if (!retval)
if (PMC_IS_NULL(retval))
retval = pmc_new(INTERP, dynpmc_LuaNil);
#else
next = VTABLE_invoke(INTERP, meth, next);
Expand Down Expand Up @@ -322,7 +321,7 @@ Throws an exception.
*/
MULTI PMC* add(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__add");
if (!meth)
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());

Expand All @@ -337,7 +336,7 @@ Throws an exception.
MULTI void i_add(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__add");

if (!meth)
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());

Expand All @@ -348,7 +347,7 @@ Throws an exception.

MULTI PMC* subtract(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__sub");
if (!meth)
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());

Expand All @@ -362,7 +361,7 @@ Throws an exception.

MULTI void i_subtract(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__sub");
if (!meth)
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());

Expand All @@ -375,7 +374,7 @@ Throws an exception.
MULTI PMC* multiply(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__mul");

if (!meth)
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());

Expand All @@ -390,7 +389,7 @@ Throws an exception.
MULTI void i_multiply(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__mul");

if (!meth)
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());

Expand All @@ -403,7 +402,7 @@ Throws an exception.
MULTI PMC* divide(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__div");

if (!meth)
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());

Expand All @@ -418,7 +417,7 @@ Throws an exception.
MULTI void i_divide(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__div");

if (!meth)
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());

Expand All @@ -431,7 +430,7 @@ Throws an exception.
MULTI PMC* modulus(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__mod");

if (!meth)
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());

Expand All @@ -446,7 +445,7 @@ Throws an exception.
MULTI void i_modulus(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__mod");

if (!meth)
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());

Expand All @@ -459,7 +458,7 @@ Throws an exception.
MULTI PMC* pow(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__pow");

if (!meth)
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());

Expand All @@ -474,7 +473,7 @@ Throws an exception.
MULTI void i_pow(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__pow");

if (!meth)
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());

Expand All @@ -487,7 +486,7 @@ Throws an exception.
MULTI PMC* concatenate(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__concat");

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

Expand All @@ -501,7 +500,7 @@ Throws an exception.

MULTI void i_concatenate(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__concat");
if (!meth)
if (PMC_IS_NULL(meth))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to concatenate a %Ss value", SELF.name());

Expand Down Expand Up @@ -581,7 +580,7 @@ Without shortcut like in Default PMC.
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__len");
PMC *retval;

if (!meth)
if (PMC_IS_NULL(meth))
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to get length of a %Ss value", SELF.name());

Expand Down Expand Up @@ -622,7 +621,7 @@ Common implementation (use C<__tostring> or C<get_string>).
PMC * const meth = _LuaAny_find_meth(INTERP, SELF, "__tostring");
PMC *retval;

if (meth) {
if (!PMC_IS_NULL(meth)) {
retval = Parrot_runops_fromc_args(INTERP, meth, "PP", SELF);

if (PMC_IS_NULL(retval))
Expand Down
3 changes: 2 additions & 1 deletion src/pmc/luafunction.pmc
Expand Up @@ -51,6 +51,7 @@ Initializes the function.
VTABLE void init() {
Parrot_LuaFunction_attributes *attrs = PARROT_LUAFUNCTION(SELF);
attrs->seg = INTERP->code;
attrs->env = PMCNULL;
PObj_custom_mark_destroy_SETALL(SELF);
}

Expand Down Expand Up @@ -85,7 +86,7 @@ Marks the function as live.
*/
VTABLE void mark() {
SUPER();
if (f_env(SELF))
if (!PMC_IS_NULL(f_env(SELF)))
Parrot_gc_mark_PMC_alive(INTERP, f_env(SELF));
}

Expand Down

0 comments on commit e2e4a89

Please sign in to comment.