You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/27 05:12:09 UTC
[lucy-commits] svn commit: r1074985 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Class.pm src/CFCClass.c src/CFCClass.h
Author: marvin
Date: Sun Feb 27 04:12:08 2011
New Revision: 1074985
URL: http://svn.apache.org/viewvc?rev=1074985&view=rev
Log:
Move storage of CFCMethod objects within CFCClass to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm
incubator/lucy/trunk/clownfish/src/CFCClass.c
incubator/lucy/trunk/clownfish/src/CFCClass.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1074985&r1=1074984&r2=1074985&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sun Feb 27 04:12:08 2011
@@ -116,7 +116,7 @@ CODE:
OUTPUT: RETVAL
void
-_destroy(self)
+DESTROY(self)
CFCClass *self;
PPCODE:
CFCClass_destroy(self);
@@ -150,6 +150,13 @@ PPCODE:
CFCClass_add_function(self, func);
void
+add_method(self, method)
+ CFCClass *self;
+ CFCMethod *method;
+PPCODE:
+ CFCClass_add_method(self, method);
+
+void
add_attribute(self, name, value_sv)
CFCClass *self;
const char *name;
@@ -196,6 +203,23 @@ CODE:
: newSV(0);
OUTPUT: RETVAL
+SV*
+method(self, sym)
+ CFCClass *self;
+ const char *sym;
+CODE:
+ CFCMethod *method = CFCClass_method(self, sym);
+ RETVAL = method
+ ? newRV((SV*)CFCBase_get_perl_obj((CFCBase*)method))
+ : newSV(0);
+OUTPUT: RETVAL
+
+void
+_zap_methods(self)
+ CFCClass *self;
+PPCODE:
+ CFCClass_zap_methods(self);
+
void
_set_or_get(self, ...)
CFCClass *self;
@@ -219,6 +243,7 @@ ALIAS:
get_docucomment = 30
children = 32
functions = 34
+ methods = 36
member_vars = 38
inert_vars = 40
tree_to_ladder = 42
@@ -337,6 +362,18 @@ PPCODE:
SvREFCNT_dec(av);
break;
}
+ case 36: {
+ AV *av = newAV();
+ CFCMethod **methods = CFCClass_methods(self);
+ size_t i;
+ for (i = 0; methods[i] != NULL; i++) {
+ SV *val = newRV(CFCBase_get_perl_obj((CFCBase*)methods[i]));
+ av_store(av, i, val);
+ }
+ retval = newRV((SV*)av);
+ SvREFCNT_dec(av);
+ break;
+ }
case 38: {
AV *av = newAV();
CFCVariable **vars = CFCClass_member_vars(self);
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm?rev=1074985&r1=1074984&r2=1074985&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm Sun Feb 27 04:12:08 2011
@@ -30,8 +30,6 @@ use Clownfish::Dumpable;
use File::Spec::Functions qw( catfile );
use Scalar::Util qw( reftype );
-our %methods;
-
our %create_PARAMS = (
source_class => undef,
class_name => undef,
@@ -94,8 +92,6 @@ sub create {
@args{qw( parcel exposure class_name class_cnick micro_sym
docucomment source_class parent_class_name final inert )} );
- $methods{$self} = [];
-
# Store in registry.
my $key = $self->full_struct_sym;
my $existing = $registry{$key};
@@ -109,16 +105,6 @@ sub create {
return $self;
}
-sub DESTROY {
- my $self = shift;
- delete $methods{$self};
- $self->_destroy;
-}
-
-sub _set_methods { $methods{ $_[0] } = $_[1] }
-
-sub methods { $methods{ +shift } }
-
sub novel_methods {
my $self = shift;
my $cnick = $self->get_cnick;
@@ -126,13 +112,6 @@ sub novel_methods {
return \@methods;
}
-sub method {
- my ( $self, $micro_sym ) = @_;
- $micro_sym = lc($micro_sym);
- my ($match) = grep { $_->micro_sym eq $micro_sym } @{ $self->methods };
- return $match;
-}
-
sub novel_method {
my ( $self, $micro_sym ) = @_;
my $method = $self->method($micro_sym);
@@ -146,14 +125,6 @@ sub novel_method {
}
}
-sub add_method {
- my ( $self, $method ) = @_;
- confess("Not a Method") unless a_isa_b( $method, "Clownfish::Method" );
- confess("Can't call add_method after grow_tree") if $self->_tree_grown;
- confess("Can't add_method to an inert class") if $self->inert;
- push @{ $self->methods }, $method;
-}
-
# Create dumpable functions unless hand coded versions were supplied.
sub _create_dumpables {
my $self = shift;
@@ -207,7 +178,8 @@ sub _bequeath_methods {
}
push @new_method_set, $meth;
}
- $child->_set_methods(\@new_method_set);
+ $child->_zap_methods;
+ $child->add_method($_) for @new_method_set;
# Pass it all down to the next generation.
$child->_bequeath_methods;
Modified: incubator/lucy/trunk/clownfish/src/CFCClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.c?rev=1074985&r1=1074984&r2=1074985&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.c Sun Feb 27 04:12:08 2011
@@ -30,6 +30,7 @@
#include "CFCSymbol.h"
#include "CFCClass.h"
#include "CFCFunction.h"
+#include "CFCMethod.h"
#include "CFCParcel.h"
#include "CFCDocuComment.h"
#include "CFCUtil.h"
@@ -49,6 +50,8 @@ struct CFCClass {
size_t num_kids;
CFCFunction **functions;
size_t num_functions;
+ CFCMethod **methods;
+ size_t num_methods;
CFCVariable **member_vars;
size_t num_member_vars;
CFCVariable **inert_vars;
@@ -98,6 +101,8 @@ CFCClass_init(CFCClass *self, struct CFC
self->num_kids = 0;
self->functions = (CFCFunction**)CALLOCATE(1, sizeof(CFCFunction*));
self->num_functions = 0;
+ self->methods = (CFCMethod**)CALLOCATE(1, sizeof(CFCMethod*));
+ self->num_methods = 0;
self->member_vars = (CFCVariable**)CALLOCATE(1, sizeof(CFCVariable*));
self->num_member_vars = 0;
self->inert_vars = (CFCVariable**)CALLOCATE(1, sizeof(CFCVariable*));
@@ -174,6 +179,9 @@ CFCClass_destroy(CFCClass *self)
for (i = 0; self->functions[i] != NULL; i++) {
CFCBase_decref((CFCBase*)self->functions[i]);
}
+ for (i = 0; self->methods[i] != NULL; i++) {
+ CFCBase_decref((CFCBase*)self->methods[i]);
+ }
for (i = 0; self->member_vars[i] != NULL; i++) {
CFCBase_decref((CFCBase*)self->member_vars[i]);
}
@@ -188,6 +196,7 @@ CFCClass_destroy(CFCClass *self)
}
FREEMEM(self->children);
FREEMEM(self->functions);
+ FREEMEM(self->methods);
FREEMEM(self->member_vars);
FREEMEM(self->inert_vars);
FREEMEM(self->attributes);
@@ -231,6 +240,35 @@ CFCClass_add_function(CFCClass *self, CF
}
void
+CFCClass_add_method(CFCClass *self, CFCMethod *method)
+{
+ CFCUTIL_NULL_CHECK(method);
+ if (self->tree_grown) {
+ croak("Can't call add_method after grow_tree");
+ }
+ if (self->is_inert) {
+ croak("Can't add_method to an inert class");
+ }
+ self->num_methods++;
+ size_t size = (self->num_methods + 1) * sizeof(CFCMethod*);
+ self->methods = (CFCMethod**)REALLOCATE(self->methods, size);
+ self->methods[self->num_methods - 1]
+ = (CFCMethod*)CFCBase_incref((CFCBase*)method);
+ self->methods[self->num_methods] = NULL;
+}
+
+void
+CFCClass_zap_methods(CFCClass *self)
+{
+ size_t i;
+ for (i = 0; self->methods[i] != NULL; i++) {
+ CFCBase_decref((CFCBase*)self->methods[i]);
+ }
+ self->methods[0] = NULL;
+ self->num_methods = 0;
+}
+
+void
CFCClass_add_member_var(CFCClass *self, CFCVariable *var)
{
CFCUTIL_NULL_CHECK(var);
@@ -292,8 +330,8 @@ CFCClass_has_attribute(CFCClass *self, c
return false;
}
-CFCFunction*
-CFCClass_function(CFCClass *self, const char *sym)
+static CFCFunction*
+S_find_func(CFCFunction **funcs, const char *sym)
{
const size_t MAX_LEN = 128;
char lcsym[MAX_LEN + 1];
@@ -303,8 +341,8 @@ CFCClass_function(CFCClass *self, const
for (i = 0; i <= sym_len; i++) {
lcsym[i] = tolower(sym[i]);
}
- for (i = 0; self->functions[i] != NULL; i++) {
- CFCFunction *func = self->functions[i];
+ for (i = 0; funcs[i] != NULL; i++) {
+ CFCFunction *func = funcs[i];
const char *func_micro_sym = CFCSymbol_micro_sym((CFCSymbol*)func);
if (strcmp(lcsym, func_micro_sym) == 0) {
return func;
@@ -313,6 +351,18 @@ CFCClass_function(CFCClass *self, const
return NULL;
}
+CFCFunction*
+CFCClass_function(CFCClass *self, const char *sym)
+{
+ return S_find_func(self->functions, sym);
+}
+
+CFCMethod*
+CFCClass_method(CFCClass *self, const char *sym)
+{
+ return (CFCMethod*)S_find_func((CFCFunction**)self->methods, sym);
+}
+
// Pass down member vars to from parent to children.
void
CFCClass_bequeath_member_vars(CFCClass *self)
@@ -418,6 +468,12 @@ CFCClass_functions(CFCClass *self)
return self->functions;
}
+CFCMethod**
+CFCClass_methods(CFCClass *self)
+{
+ return self->methods;
+}
+
CFCVariable**
CFCClass_member_vars(CFCClass *self)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCClass.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCClass.h?rev=1074985&r1=1074984&r2=1074985&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCClass.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCClass.h Sun Feb 27 04:12:08 2011
@@ -21,6 +21,7 @@ typedef struct CFCClass CFCClass;
struct CFCParcel;
struct CFCDocuComment;
struct CFCFunction;
+struct CFCMethod;
struct CFCVariable;
CFCClass*
@@ -48,6 +49,12 @@ void
CFCClass_add_function(CFCClass *self, struct CFCFunction *func);
void
+CFCClass_add_method(CFCClass *self, struct CFCMethod *method);
+
+void
+CFCClass_zap_methods(CFCClass *self);
+
+void
CFCClass_add_member_var(CFCClass *self, struct CFCVariable *var);
void
@@ -62,6 +69,9 @@ CFCClass_has_attribute(CFCClass *self, c
struct CFCFunction*
CFCClass_function(CFCClass *self, const char *sym);
+struct CFCMethod*
+CFCClass_method(CFCClass *self, const char *sym);
+
/** Pass down member vars to from parent to children.
*/
void
@@ -82,6 +92,9 @@ CFCClass_children(CFCClass *self);
struct CFCFunction**
CFCClass_functions(CFCClass *self);
+struct CFCMethod**
+CFCClass_methods(CFCClass *self);
+
struct CFCVariable**
CFCClass_member_vars(CFCClass *self);