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/11 02:48:11 UTC
[lucy-commits] svn commit: r1069660 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Type.pm src/CFCType.c src/CFCType.h
Author: marvin
Date: Fri Feb 11 01:48:10 2011
New Revision: 1069660
URL: http://svn.apache.org/viewvc?rev=1069660&view=rev
Log:
Port new_float() constructor for Clownfish::Type to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Type.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=1069660&r1=1069659&r2=1069660&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Feb 11 01:48:10 2011
@@ -448,6 +448,17 @@ CODE:
OUTPUT: RETVAL
SV*
+_new_float(klass, flags, specifier)
+ const char *klass;
+ int flags;
+ const char *specifier;
+CODE:
+ CFCType *self = CFCType_new_float(flags, specifier);
+ RETVAL = newSV(0);
+ sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+SV*
_new_void(klass, is_const)
const char *klass;
int is_const;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm?rev=1069660&r1=1069659&r2=1069660&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm Fri Feb 11 01:48:10 2011
@@ -143,26 +143,13 @@ our %new_float_PARAMS = (
specifier => undef,
);
-our %float_specifiers = (
- float => undef,
- double => undef,
-);
-
sub new_float {
my ( $either, %args ) = @_;
verify_args( \%new_float_PARAMS, %args ) or confess $@;
- confess("Unknown specifier: '$args{specifier}'")
- unless exists $float_specifiers{ $args{specifier} };
-
- # Cache the C representation of this type.
- my $c_string = $args{const} ? "const $args{specifier}" : $args{specifier};
-
- return $either->new(
- %args,
- c_string => $c_string,
- floating => 1,
- primitive => 1,
- );
+ my $flags = 0;
+ $flags |= CONST if $args{const};
+ my $package = ref($either) || $either;
+ return $package->_new_float( $flags, $args{specifier} );
}
sub new_object {
Modified: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1069660&r1=1069659&r2=1069660&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Fri Feb 11 01:48:10 2011
@@ -58,6 +58,41 @@ CFCType_init(CFCType *self, int flags, s
return self;
}
+static const char *float_specifiers[] = {
+ "float",
+ "double",
+ NULL
+};
+
+CFCType*
+CFCType_new_float(int flags, const char *specifier)
+{
+ // Validate specifier.
+ size_t i;
+ for (i = 0; ; i++) {
+ if (!float_specifiers[i]) {
+ croak("Unknown float specifier: '%s'", specifier);
+ }
+ if (strcmp(float_specifiers[i], specifier) == 0) {
+ break;
+ }
+ }
+
+ // Cache the C representation of this type.
+ char c_string[32];
+ if (flags & CFCTYPE_CONST) {
+ sprintf(c_string, "const %s", specifier);
+ }
+ else {
+ strcpy(c_string, specifier);
+ }
+
+ flags |= CFCTYPE_PRIMITIVE;
+ flags |= CFCTYPE_FLOATING;
+
+ return CFCType_new(flags, NULL, specifier, 0, c_string);
+}
+
CFCType*
CFCType_new_void(int is_const)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCType.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.h?rev=1069660&r1=1069659&r2=1069660&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.h Fri Feb 11 01:48:10 2011
@@ -38,6 +38,9 @@ CFCType_init(CFCType *self, int flags, s
const char *specifier, int indirection, const char *c_string);
CFCType*
+CFCType_new_float(int flags, const char *specifier);
+
+CFCType*
CFCType_new_void(int is_const);
CFCType*