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 03:27:36 UTC

[lucy-commits] svn commit: r1069664 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Binding/Core/Method.pm lib/Clownfish/Type.pm src/CFCType.c src/CFCType.h

Author: marvin
Date: Fri Feb 11 02:27:36 2011
New Revision: 1069664

URL: http://svn.apache.org/viewvc?rev=1069664&view=rev
Log:
 Port integer-related routines for Clownfish::Type to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm
    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=1069664&r1=1069663&r2=1069664&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Feb 11 02:27:36 2011
@@ -448,6 +448,17 @@ CODE:
 OUTPUT: RETVAL
 
 SV*
+_new_integer(klass, flags, specifier)
+    const char *klass;
+    int flags;
+    const char *specifier;
+CODE:
+    CFCType *self = CFCType_new_integer(flags, specifier);
+    RETVAL = newSV(0);
+	sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+SV*
 _new_float(klass, flags, specifier)
     const char *klass;
     int flags;
@@ -595,6 +606,7 @@ ALIAS:
     is_va_list      = 26
     is_arbitrary    = 28
     is_composite    = 30
+    get_width       = 32
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -659,6 +671,9 @@ PPCODE:
         case 30:
             retval = newSViv(CFCType_is_composite(self));
             break;
+        case 32:
+            retval = newSVuv(CFCType_get_width(self));
+            break;
     END_SET_OR_GET_SWITCH
 }
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm?rev=1069664&r1=1069663&r2=1069664&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Method.pm Fri Feb 11 02:27:36 2011
@@ -163,9 +163,9 @@ sub _callback_params {
             $param = qq|CFISH_ARG_OBJ("$name", $name)|;
         }
         elsif ( $type->is_integer ) {
-            my $sizeof = $type->sizeof;
-            if ( defined($sizeof) ) {
-                if ($sizeof <= 4) {
+            my $width = $type->get_width;
+            if ($width) {
+                if ($width <= 4) {
                     $param = qq|CFISH_ARG_I32("$name", $name)|;
                 }
                 else {

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm?rev=1069664&r1=1069663&r2=1069664&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm Fri Feb 11 02:27:36 2011
@@ -28,7 +28,6 @@ our %incremented;
 our %decremented;
 our %array;
 our %child;
-our %sizeof;
 
 our %new_PARAMS = (
     const       => undef,
@@ -82,23 +81,6 @@ sub new {
         $c_string );
 }
 
-our %int_specifiers = (
-    bool_t   => undef,
-    int8_t   => 1,
-    int16_t  => 2,
-    int32_t  => 4,
-    int64_t  => 8,
-    uint8_t  => 1,
-    uint16_t => 2,
-    uint32_t => 4,
-    uint64_t => 8,
-    char     => 1,
-    int      => undef,
-    short    => undef,
-    long     => undef,
-    size_t   => undef,
-);
-
 our %new_integer_PARAMS = (
     const     => undef,
     specifier => undef,
@@ -107,24 +89,10 @@ our %new_integer_PARAMS = (
 sub new_integer {
     my ( $either, %args ) = @_;
     verify_args( \%new_integer_PARAMS, %args ) or confess $@;
-    confess("Unknown specifier: '$args{specifier}'")
-        unless exists $int_specifiers{ $args{specifier} };
-
-    # Cache the C representation of this type.
-    my $c_string = $args{const} ? 'const ' : '';
-    if ( $args{specifier} eq 'bool_t' ) {
-        $c_string .= "chy_";
-    }
-    $c_string .= $args{specifier};
-
-    my $self = $either->new(
-        %args,
-        c_string  => $c_string,
-        integer   => 1,
-        primitive => 1,
-    );
-    $sizeof{$self} = $int_specifiers{ $args{specifier} };
-    return $self;
+    my $flags = 0;
+    $flags |= CONST if $args{const};
+    my $package = ref($either) || $either;
+    return $package->_new_integer( $flags, $args{specifier} );
 }
 
 our %new_object_PARAMS = (
@@ -273,7 +241,6 @@ sub DESTROY {
     delete $child{$self};
     delete $incremented{$self};
     delete $decremented{$self};
-    delete $sizeof{$self};
     $self->_destroy;
 }
 
@@ -281,7 +248,6 @@ sub get_array     { $array{ +shift } }
 sub _get_child    { $child{ +shift } }
 sub incremented   { $incremented{ +shift } }
 sub decremented   { $decremented{ +shift } }
-sub sizeof        { $sizeof{ +shift } }
 
 sub similar {
     my ( $self, $other ) = @_;

Modified: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1069664&r1=1069663&r2=1069664&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Fri Feb 11 02:27:36 2011
@@ -34,6 +34,7 @@ struct CFCType {
     int   indirection;
     struct CFCParcel *parcel;
     char *c_string;
+    size_t width;
 };
 
 CFCType*
@@ -55,6 +56,64 @@ CFCType_init(CFCType *self, int flags, s
     self->specifier   = savepv(specifier);
     self->indirection = indirection;
     self->c_string    = c_string ? savepv(c_string) : savepv("");
+    self->width       = 0;
+    return self;
+}
+
+CFCType*
+CFCType_new_integer(int flags, const char *specifier)
+{
+    // Validate specifier, find width.
+    size_t width; 
+    if (!strcmp(specifier, "int8_t") || !strcmp(specifier, "uint8_t")) {
+        width = 1;
+    }
+    else if (!strcmp(specifier, "int16_t") || !strcmp(specifier, "uint16_t")) {
+        width = 2;
+    }
+    else if (!strcmp(specifier, "int32_t") || !strcmp(specifier, "uint32_t")) {
+        width = 4;
+    }
+    else if (!strcmp(specifier, "int64_t") || !strcmp(specifier, "uint64_t")) {
+        width = 8;
+    }
+    else if (   !strcmp(specifier, "char") 
+             || !strcmp(specifier, "short")
+             || !strcmp(specifier, "int")
+             || !strcmp(specifier, "long")
+             || !strcmp(specifier, "size_t")
+             || !strcmp(specifier, "bool_t") // Charmonizer type.
+    ) {
+        width = 0;
+    }
+    else {
+        croak("Unknown integer specifier: '%s'", specifier);
+    }
+
+    // Add Charmonizer prefix if necessary.
+    char full_specifier[32];
+    if (strcmp(specifier, "bool_t") == 0) {
+        strcpy(full_specifier, "chy_bool_t");
+    }
+    else {
+        strcpy(full_specifier, specifier);
+    }
+
+    // Cache the C representation of this type.
+    char c_string[32];
+    if (flags & CFCTYPE_CONST) {
+        sprintf(c_string, "const %s", full_specifier);
+    }
+    else {
+        strcpy(c_string, full_specifier);
+    }
+
+    // Add flags.
+    flags |= CFCTYPE_PRIMITIVE;
+    flags |= CFCTYPE_INTEGER;
+
+    CFCType *self = CFCType_new(flags, NULL, full_specifier, 0, c_string);
+    self->width = width;
     return self;
 }
 
@@ -210,6 +269,12 @@ CFCType_to_c(CFCType *self)
     return self->c_string;
 }
 
+size_t
+CFCType_get_width(CFCType *self)
+{
+    return self->width;
+}
+
 int
 CFCType_const(CFCType *self)
 {

Modified: incubator/lucy/trunk/clownfish/src/CFCType.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.h?rev=1069664&r1=1069663&r2=1069664&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.h Fri Feb 11 02:27:36 2011
@@ -38,6 +38,9 @@ CFCType_init(CFCType *self, int flags, s
              const char *specifier, int indirection, const char *c_string);
 
 CFCType*
+CFCType_new_integer(int flags, const char *specifier);
+
+CFCType*
 CFCType_new_float(int flags, const char *specifier);
 
 CFCType*
@@ -73,6 +76,9 @@ CFCType_set_c_string(CFCType *self, cons
 const char*
 CFCType_to_c(CFCType *self);
 
+size_t
+CFCType_get_width(CFCType *self);
+
 int
 CFCType_set_nullable(CFCType *self, int nullable);