Skip to content

Commit

Permalink
Modernity: Remove a bunch of DRY violations ( bacek++ )
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Mar 24, 2010
1 parent 601fb01 commit 6f5d950
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
14 changes: 7 additions & 7 deletions src/pmc/p5interpreter.pmc
Expand Up @@ -89,7 +89,7 @@ Set up P5Interpreter PMC.
perl_parse(my_perl, xs_init, 3, embedding, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(my_perl);
SETATTR_P5Interpreter_my_perl(interp, SELF, my_perl);
SET_ATTR_my_perl(interp, SELF, my_perl);

/* We turn on auto-flush to avoid oddness in interactions between
* IO systems. */
Expand All @@ -108,7 +108,7 @@ Mark source string, if we have one.
VTABLE void mark() {
if (PMC_data(SELF)) {
STRING *source;
GETATTR_P5Interpreter_source(interp, SELF, source);
GET_ATTR_source(interp, SELF, source);
if (source)
Parrot_gc_mark_PObj_alive(interp, (PObj*)source);
}
Expand All @@ -127,10 +127,10 @@ Destructor for the P5Interpreter PMC.
struct interpreter *my_perl;

/* Destroy interpreter if it's got no more usage. */
GETATTR_P5Interpreter_my_perl(interp, SELF, my_perl);
GET_ATTR_my_perl(interp, SELF, my_perl);
perl_destruct(my_perl);
perl_free(my_perl);

/* XXX We should only call PERL_SYS_TERM right at the end, not per
* interpreter destroy. Skip doing it for now at all, but need to
* work out where to put this. */
Expand All @@ -152,7 +152,7 @@ Set the source code that we will run.
*/

VTABLE void set_string_native(STRING *source) {
SETATTR_P5Interpreter_source(interp, SELF, source);
SET_ATTR_source(interp, SELF, source);
}

/*
Expand All @@ -174,11 +174,11 @@ Run the Perl 5 code.

/* Get source into a C string so we can give it to Perl 5.
* XXX We'd best care about encodings and charset here some day. */
GETATTR_P5Interpreter_source(interp, SELF, source);
GET_ATTR_source(interp, SELF, source);
c_source = Parrot_str_to_cstring(interp, source);

/* Evaluate it. */
GETATTR_P5Interpreter_my_perl(interp, SELF, my_perl);
GET_ATTR_my_perl(interp, SELF, my_perl);
return_code = eval_pv(c_source, TRUE);
result = pmc_new(interp, pmc_type(interp, string_from_literal(interp, "P5Scalar")));
SETATTR_P5Scalar_p5i(interp, result, SELF);
Expand Down
16 changes: 8 additions & 8 deletions src/pmc/p5invocation.pmc
Expand Up @@ -139,9 +139,9 @@ Mark GC-ables.
if (PMC_data(SELF)) {
PMC *p5i, *invocant_ns;
STRING *name;
GETATTR_P5Invocation_p5i(interp, SELF, p5i);
GETATTR_P5Invocation_invocant_ns(interp, SELF, invocant_ns);
GETATTR_P5Invocation_name(interp, SELF, name);
GET_ATTR_p5i(interp, SELF, p5i);
GET_ATTR_invocant_ns(interp, SELF, invocant_ns);
GET_ATTR_name(interp, SELF, name);
if (p5i)
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i);
if (invocant_ns)
Expand Down Expand Up @@ -173,14 +173,14 @@ Handles the actual invocation.
PMC *p5i, *results, *ns, *ns_key, *return_helper;
PMC *capture, *named_names, *named_args, *iter;
PerlInterpreter *my_perl;

/* Get the interpreter, SV and the name. */
GETATTR_P5Invocation_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Invocation_name(interp, SELF, name);
GET_ATTR_name(interp, SELF, name);
c_name = Parrot_str_to_cstring(interp, name);
GETATTR_P5Invocation_invocant_sv(interp, SELF, invocant_sv);
GETATTR_P5Invocation_invocant_ns(interp, SELF, invocant_ns);
GET_ATTR_invocant_sv(interp, SELF, invocant_sv);
GET_ATTR_invocant_ns(interp, SELF, invocant_ns);

/* Grab the parameters; toss the invocant as we already have that. */
capture = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
Expand Down
16 changes: 7 additions & 9 deletions src/pmc/p5namespace.pmc
Expand Up @@ -52,8 +52,8 @@ Set up P5Namespace PMC.
PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_P5Namespace_attributes);
PObj_custom_mark_SET(SELF);
PObj_custom_destroy_SET(SELF);
SETATTR_P5Namespace_p5i(interp, SELF, p5i);
SETATTR_P5Namespace_marshall_cache(interp, SELF, PMCNULL);
SET_ATTR_p5i(interp, SELF, p5i);
SET_ATTR_marshall_cache(interp, SELF, PMCNULL);
}


Expand All @@ -70,9 +70,9 @@ Mark GC-ables.
if (PMC_data(SELF)) {
PMC *p5i, *cache;
STRING *name;
GETATTR_P5Namespace_p5i(interp, SELF, p5i);
GETATTR_P5Namespace_marshall_cache(interp, SELF, cache);
GETATTR_P5Namespace_ns_name(interp, SELF, name);
GET_ATTR_p5i(interp, SELF, p5i);
GET_ATTR_marshall_cache(interp, SELF, cache);
GET_ATTR_ns_name(interp, SELF, name);
if (p5i)
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i);
if (cache)
Expand Down Expand Up @@ -108,11 +108,9 @@ Set the name of the Perl 5 namespace that we map to.

*/
VTABLE void set_string_native(STRING *name) {
SETATTR_P5Namespace_ns_name(interp, SELF, name);
SET_ATTR_ns_name(interp, SELF, name);
}



/*

=item C<PMC *find_method(STRING *name)>
Expand All @@ -124,7 +122,7 @@ Hands back a P5Invocation so we can call a method on the package.
*/
VTABLE PMC *find_method(STRING *name) {
PMC *p5i, *result;
GETATTR_P5Namespace_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);

/* Make and return a P5Invocation object. */
result = pmc_new(interp, pmc_type(interp, CONST_STRING(interp, "P5Invocation")));
Expand Down
22 changes: 11 additions & 11 deletions src/pmc/p5scalar.pmc
Expand Up @@ -62,9 +62,9 @@ Returns the integer value of the SV.
PMC *p5i;
PerlInterpreter *my_perl;
struct sv *sv;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Scalar_sv(interp, SELF, sv);
GET_ATTR_sv(interp, SELF, sv);
return SvIV(sv);
}

Expand All @@ -82,9 +82,9 @@ Returns the number value of the SV.
PMC *p5i;
PerlInterpreter *my_perl;
struct sv *sv;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Scalar_sv(interp, SELF, sv);
GET_ATTR_sv(interp, SELF, sv);
return SvNV(sv);
}

Expand All @@ -102,9 +102,9 @@ Returns the string value of the SV.
PerlInterpreter *my_perl;
struct sv *sv;
char *perl5_str;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Scalar_sv(interp, SELF, sv);
GET_ATTR_sv(interp, SELF, sv);
perl5_str = SvPVutf8_nolen(sv);
return Parrot_str_new(interp, perl5_str, strlen(perl5_str));
}
Expand All @@ -125,15 +125,15 @@ the given name on the given Perl 5 Scalar invocant.
PerlInterpreter *my_perl;
struct sv *invocant;

GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Scalar_sv(interp, SELF, invocant);
GET_ATTR_sv(interp, SELF, invocant);

result = pmc_new(interp, pmc_type(interp, string_from_literal(interp, "P5Invocation")));
SETATTR_P5Invocation_p5i(interp, result, p5i);
SETATTR_P5Invocation_invocant_sv(interp, result, SvREFCNT_inc(invocant));
SETATTR_P5Invocation_name(interp, result, name);

return result;
}

Expand All @@ -153,9 +153,9 @@ Checks if a class can do a given method.
INTVAL result;
char *c_name;

GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Scalar_sv(interp, SELF, invocant);
GET_ATTR_sv(interp, SELF, invocant);
c_name = Parrot_str_to_cstring(interp, name);

/* If it's not blessed, the answer is "no" right off. */
Expand Down
6 changes: 3 additions & 3 deletions src/pmc/p5sv.pmc
Expand Up @@ -63,7 +63,7 @@ Mark GC-ables.
VTABLE void mark() {
if (PMC_data(SELF)) {
PMC *p5i;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
if (p5i)
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i);
}
Expand All @@ -84,7 +84,7 @@ Decrement reference count of held SV.
PMC *p5i;
PerlInterpreter *my_perl;
struct sv *sv;
GETATTR_P5SV_p5i(interp, SELF, p5i);
GET_ATTR_p5i(interp, SELF, p5i);
/* There is a small destruction order issue here; Parrot
may destroy the interpreter before the last SV references.
But if the interpreter is destroyed, we have no need, the
Expand All @@ -105,7 +105,7 @@ Decrement reference count of held SV.

if (PMC_data(p5i)) {
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5SV_sv(interp, SELF, sv);
GET_ATTR_sv(interp, SELF, sv);
SvREFCNT_dec(sv);
}
mem_sys_free(PMC_data(SELF));
Expand Down

0 comments on commit 6f5d950

Please sign in to comment.