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/05 21:21:50 UTC
[lucy-commits] svn commit: r1067512 - in /incubator/lucy/trunk/clownfish: lib/
lib/Clownfish/ lib/Clownfish/Type/ src/
Author: marvin
Date: Sat Feb 5 20:21:49 2011
New Revision: 1067512
URL: http://svn.apache.org/viewvc?rev=1067512&view=rev
Log:
Differentiate between types using flags rather than class identities.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Float.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Integer.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm
incubator/lucy/trunk/clownfish/src/CFCType.c
incubator/lucy/trunk/clownfish/src/CFCType.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sat Feb 5 20:21:49 2011
@@ -466,6 +466,54 @@ CODE:
RETVAL = CFCTYPE_VOID;
OUTPUT: RETVAL
+unsigned
+OBJECT(...)
+CODE:
+ RETVAL = CFCTYPE_OBJECT;
+OUTPUT: RETVAL
+
+unsigned
+PRIMITIVE(...)
+CODE:
+ RETVAL = CFCTYPE_PRIMITIVE;
+OUTPUT: RETVAL
+
+unsigned
+INTEGER(...)
+CODE:
+ RETVAL = CFCTYPE_INTEGER;
+OUTPUT: RETVAL
+
+unsigned
+FLOATING(...)
+CODE:
+ RETVAL = CFCTYPE_FLOATING;
+OUTPUT: RETVAL
+
+unsigned
+STRING_TYPE(...)
+CODE:
+ RETVAL = CFCTYPE_STRING_TYPE;
+OUTPUT: RETVAL
+
+unsigned
+VA_LIST(...)
+CODE:
+ RETVAL = CFCTYPE_VA_LIST;
+OUTPUT: RETVAL
+
+unsigned
+ARBITRARY(...)
+CODE:
+ RETVAL = CFCTYPE_ARBITRARY;
+OUTPUT: RETVAL
+
+unsigned
+COMPOSITE(...)
+CODE:
+ RETVAL = CFCTYPE_COMPOSITE;
+OUTPUT: RETVAL
+
void
_set_or_get(self, ...)
CFCType *self;
@@ -480,6 +528,14 @@ ALIAS:
set_nullable = 11
nullable = 12
is_void = 14
+ is_object = 16
+ is_primitive = 18
+ is_integer = 20
+ is_floating = 22
+ is_string_type = 24
+ is_va_list = 26
+ is_arbitrary = 28
+ is_composite = 30
PPCODE:
{
START_SET_OR_GET_SWITCH
@@ -516,6 +572,30 @@ PPCODE:
case 14:
retval = newSViv(CFCType_is_void(self));
break;
+ case 16:
+ retval = newSViv(CFCType_is_object(self));
+ break;
+ case 18:
+ retval = newSViv(CFCType_is_primitive(self));
+ break;
+ case 20:
+ retval = newSViv(CFCType_is_integer(self));
+ break;
+ case 22:
+ retval = newSViv(CFCType_is_floating(self));
+ break;
+ case 24:
+ retval = newSViv(CFCType_is_string_type(self));
+ break;
+ case 26:
+ retval = newSViv(CFCType_is_va_list(self));
+ break;
+ case 28:
+ retval = newSViv(CFCType_is_arbitrary(self));
+ break;
+ case 30:
+ retval = newSViv(CFCType_is_composite(self));
+ break;
END_SET_OR_GET_SWITCH
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm Sat Feb 5 20:21:49 2011
@@ -32,6 +32,14 @@ our %new_PARAMS = (
parcel => undef,
c_string => undef,
void => undef,
+ object => undef,
+ primitive => undef,
+ integer => undef,
+ floating => undef,
+ string_type => undef,
+ va_list => undef,
+ arbitrary => undef,
+ composite => undef,
);
sub new {
@@ -42,9 +50,17 @@ sub new {
verify_args( \%new_PARAMS, %args ) or confess $@;
my $flags = 0;
- $flags |= CONST if $args{const};
- $flags |= NULLABLE if $args{nullable};
- $flags |= VOID if $args{void};
+ $flags |= CONST if $args{const};
+ $flags |= NULLABLE if $args{nullable};
+ $flags |= VOID if $args{void};
+ $flags |= OBJECT if $args{object};
+ $flags |= PRIMITIVE if $args{primitive};
+ $flags |= INTEGER if $args{integer};
+ $flags |= FLOATING if $args{floating};
+ $flags |= STRING_TYPE if $args{string_type};
+ $flags |= VA_LIST if $args{va_list};
+ $flags |= ARBITRARY if $args{arbitrary};
+ $flags |= COMPOSITE if $args{composite};
my $parcel = $args{parcel};
if ( defined $parcel ) {
@@ -63,13 +79,6 @@ sub new {
$c_string );
}
-sub is_object {0}
-sub is_primitive {0}
-sub is_integer {0}
-sub is_floating {0}
-sub is_composite {0}
-sub is_string_type {0}
-
sub equals {
my ( $self, $other ) = @_;
return 0 unless blessed($other);
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm Sat Feb 5 20:21:49 2011
@@ -30,7 +30,7 @@ our %new_PARAMS = (
sub new {
my $either = shift;
verify_args( \%new_PARAMS, @_ ) or confess $@;
- my $self = $either->SUPER::new(@_);
+ my $self = $either->SUPER::new( @_, arbitrary => 1 );
# Validate specifier.
my $specifier = $self->get_specifier;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm Sat Feb 5 20:21:49 2011
@@ -42,7 +42,7 @@ sub new {
confess("Missing required param 'child'")
unless a_isa_b( $child, "Clownfish::Type" );
verify_args( \%new_PARAMS, %args ) or confess $@;
- my $self = $either->SUPER::new(%args);
+ my $self = $either->SUPER::new( %args, composite => 1 );
$child{$self} = $child;
$array{$self} = $array;
$self->set_nullable($nullable);
@@ -68,7 +68,6 @@ sub DESTROY {
sub get_specifier { shift->_get_child->get_specifier }
sub get_array { $array{ +shift } }
sub _get_child { $child{ +shift } }
-sub is_composite {1}
sub equals {
my ( $self, $other ) = @_;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Float.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Float.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Float.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Float.pm Sat Feb 5 20:21:49 2011
@@ -40,11 +40,13 @@ sub new {
# Cache the C representation of this type.
my $c_string = $args{const} ? "const $args{specifier}" : $args{specifier};
- return $either->SUPER::new( %args, c_string => $c_string );
+ return $either->SUPER::new(
+ %args,
+ c_string => $c_string,
+ floating => 1,
+ );
}
-sub is_floating {1}
-
1;
__END__
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Integer.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Integer.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Integer.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Integer.pm Sat Feb 5 20:21:49 2011
@@ -60,7 +60,11 @@ sub new {
}
$c_string .= $args{specifier};
- my $self = $either->SUPER::new( %args, c_string => $c_string );
+ my $self = $either->SUPER::new(
+ %args,
+ c_string => $c_string,
+ integer => 1,
+ );
$sizeof{$self} = $sizeof;
return $self;
}
@@ -71,8 +75,7 @@ sub DESTROY {
$self->SUPER::DESTROY;
}
-sub is_integer {1}
-sub sizeof { $sizeof{ +shift } }
+sub sizeof { $sizeof{ +shift } }
1;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm Sat Feb 5 20:21:49 2011
@@ -26,7 +26,6 @@ use Carp;
# Inside-out member vars.
our %incremented;
our %decremented;
-our %is_string_type;
our %new_PARAMS = (
const => undef,
@@ -47,7 +46,17 @@ sub new {
$args{indirection} = 1 unless defined $args{indirection};
my $indirection = $args{indirection};
$args{parcel} ||= Clownfish::Parcel->default_parcel;
- my $self = $either->SUPER::new(%args);
+ confess("Missing required param 'specifier'")
+ unless defined $args{specifier};
+
+ # Derive boolean indicating whether this type is a string type.
+ my $is_string_type = $args{specifier} =~ /CharBuf/ ? 1 : 0;
+
+ my $self = $either->SUPER::new(
+ %args,
+ object => 1,
+ string_type => $is_string_type,
+ );
$incremented{$self} = $incremented;
$decremented{$self} = $decremented;
$self->set_nullable($nullable);
@@ -58,8 +67,6 @@ sub new {
confess("Indirection must be 1") unless $indirection == 1;
confess("Can't be both incremented and decremented")
if ( $incremented && $decremented );
- confess("Missing required param 'specifier'")
- unless defined $specifier;
confess("Illegal specifier: '$specifier'")
unless $specifier
=~ /^(?:$prefix)?[A-Z][A-Za-z0-9]*[a-z]+[A-Za-z0-9]*(?!\w)/;
@@ -75,8 +82,6 @@ sub new {
$string .= "$specifier*";
$self->set_c_string($string);
- # Cache boolean indicating whether this type is a string type.
- $is_string_type{$self} = $specifier =~ /CharBuf/ ? 1 : 0;
return $self;
}
@@ -85,14 +90,11 @@ sub DESTROY {
my $self = shift;
delete $incremented{$self};
delete $decremented{$self};
- delete $is_string_type{$self};
$self->SUPER::DESTROY;
}
-sub is_object {1}
sub incremented { $incremented{ +shift } }
sub decremented { $decremented{ +shift } }
-sub is_string_type { $is_string_type{ +shift } }
sub similar {
my ( $self, $other ) = @_;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm Sat Feb 5 20:21:49 2011
@@ -26,6 +26,8 @@ our %new_PARAMS = (
const => undef,
specifier => undef,
c_string => undef,
+ integer => undef,
+ floating => undef,
);
sub new {
@@ -33,11 +35,9 @@ sub new {
my $package = ref($either) || $either;
confess( __PACKAGE__ . " is abstract" ) if $package eq __PACKAGE__;
verify_args( \%new_PARAMS, %args ) or confess $@;
- return $package->SUPER::new( %new_PARAMS, %args );
+ return $package->SUPER::new( %new_PARAMS, %args, primitive => 1 );
}
-sub is_primitive {1}
-
sub equals {
my ( $self, $other ) = @_;
return 0 unless blessed($other);
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm Sat Feb 5 20:21:49 2011
@@ -29,7 +29,8 @@ sub new {
verify_args( \%new_PARAMS, %args ) or confess $@;
return $either->SUPER::new(
specifier => 'va_list',
- c_string => 'va_list'
+ c_string => 'va_list',
+ va_list => 1,
);
}
Modified: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Sat Feb 5 20:21:49 2011
@@ -127,3 +127,51 @@ CFCType_is_void(CFCType *self)
return !!(self->flags & CFCTYPE_VOID);
}
+int
+CFCType_is_object(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_OBJECT);
+}
+
+int
+CFCType_is_primitive(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_PRIMITIVE);
+}
+
+int
+CFCType_is_integer(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_INTEGER);
+}
+
+int
+CFCType_is_floating(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_FLOATING);
+}
+
+int
+CFCType_is_string_type(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_STRING_TYPE);
+}
+
+int
+CFCType_is_va_list(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_VA_LIST);
+}
+
+int
+CFCType_is_arbitrary(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_ARBITRARY);
+}
+
+int
+CFCType_is_composite(CFCType *self)
+{
+ return !!(self->flags & CFCTYPE_COMPOSITE);
+}
+
Modified: incubator/lucy/trunk/clownfish/src/CFCType.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.h?rev=1067512&r1=1067511&r2=1067512&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.h Sat Feb 5 20:21:49 2011
@@ -16,9 +16,17 @@
typedef struct CFCType CFCType;
-#define CFCTYPE_CONST 0x1
-#define CFCTYPE_NULLABLE 0x2
-#define CFCTYPE_VOID 0x4
+#define CFCTYPE_CONST 0x00000001
+#define CFCTYPE_NULLABLE 0x00000002
+#define CFCTYPE_VOID 0x00000004
+#define CFCTYPE_OBJECT 0x00000008
+#define CFCTYPE_PRIMITIVE 0x00000010
+#define CFCTYPE_INTEGER 0x00000020
+#define CFCTYPE_FLOATING 0x00000040
+#define CFCTYPE_STRING_TYPE 0x00000080
+#define CFCTYPE_VA_LIST 0x00000100
+#define CFCTYPE_ARBITRARY 0x00000200
+#define CFCTYPE_COMPOSITE 0x00000400
CFCType*
CFCType_new(int flags, void *parcel, const char *specifier, int indirection,
@@ -58,3 +66,27 @@ CFCType_nullable(CFCType *self);
int
CFCType_is_void(CFCType *self);
+int
+CFCType_is_object(CFCType *self);
+
+int
+CFCType_is_primitive(CFCType *self);
+
+int
+CFCType_is_integer(CFCType *self);
+
+int
+CFCType_is_floating(CFCType *self);
+
+int
+CFCType_is_string_type(CFCType *self);
+
+int
+CFCType_is_va_list(CFCType *self);
+
+int
+CFCType_is_arbitrary(CFCType *self);
+
+int
+CFCType_is_composite(CFCType *self);
+