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/07/27 21:41:19 UTC

[lucy-commits] svn commit: r1151602 - in /incubator/lucy/trunk/clownfish: include/CFC.h lib/Clownfish.xs lib/Clownfish/Binding/Perl/TypeMap.pm src/CFCPerlTypeMap.c src/CFCPerlTypeMap.h

Author: marvin
Date: Wed Jul 27 19:41:17 2011
New Revision: 1151602

URL: http://svn.apache.org/viewvc?rev=1151602&view=rev
Log:
Port Clownfish binding code which autogenerates Perl typemap.

Added:
    incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.c   (with props)
    incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.h   (with props)
Modified:
    incubator/lucy/trunk/clownfish/include/CFC.h
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm

Modified: incubator/lucy/trunk/clownfish/include/CFC.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/include/CFC.h?rev=1151602&r1=1151601&r2=1151602&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Wed Jul 27 19:41:17 2011
@@ -40,4 +40,5 @@
 #include "CFCPerlSub.h"
 #include "CFCPerlMethod.h"
 #include "CFCPerlClass.h"
+#include "CFCPerlTypeMap.h"
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1151602&r1=1151601&r2=1151602&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Wed Jul 27 19:41:17 2011
@@ -2017,4 +2017,11 @@ PPCODE:
     END_SET_OR_GET_SWITCH
 }
 
+MODULE = Clownfish   PACKAGE = Clownfish::Binding::Perl::TypeMap
+
+void
+_write_xs_typemap(hierarchy)
+    CFCHierarchy *hierarchy;
+PPCODE:
+    CFCPerlTypeMap_write_xs_typemap(hierarchy);
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm?rev=1151602&r1=1151601&r2=1151602&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm Wed Jul 27 19:41:17 2011
@@ -128,97 +128,7 @@ sub to_perl {
 
 sub write_xs_typemap {
     my ( undef, %args ) = @_;
-    my $hierarchy = $args{hierarchy};
-
-    my $class_typemap_start  = "";
-    my $class_typemap_input  = "";
-    my $class_typemap_output = "";
-
-    for my $class ( @{ $hierarchy->ordered_classes } ) {
-        my $full_struct_sym = $class->full_struct_sym;
-        my $vtable          = $class->full_vtable_var;
-        my $label           = $vtable . "_";
-        $class_typemap_start .= "$full_struct_sym*\t$label\n";
-        $class_typemap_input .= <<END_INPUT;
-$label
-    \$var = ($full_struct_sym*)XSBind_sv_to_cfish_obj(\$arg, $vtable, NULL);
-
-END_INPUT
-
-        $class_typemap_output .= <<END_OUTPUT;
-$label
-    \$arg = (SV*)Cfish_Obj_To_Host((cfish_Obj*)\$var);
-    LUCY_DECREF(\$var);
-
-END_OUTPUT
-    }
-
-    # Blast it out.
-    sysopen( my $typemap_fh, 'typemap', O_CREAT | O_WRONLY | O_EXCL )
-        or die "Couldn't open 'typemap' for writing: $!";
-    print $typemap_fh <<END_STUFF;
-# Auto-generated file.
-
-TYPEMAP
-chy_bool_t\tCHY_BOOL
-int8_t\tCHY_SIGNED_INT
-int16_t\tCHY_SIGNED_INT
-int32_t\tCHY_SIGNED_INT
-int64_t\tCHY_BIG_SIGNED_INT
-uint8_t\tCHY_UNSIGNED_INT
-uint16_t\tCHY_UNSIGNED_INT
-uint32_t\tCHY_UNSIGNED_INT
-uint64_t\tCHY_BIG_UNSIGNED_INT
-
-const lucy_CharBuf*\tCONST_CHARBUF
-$class_typemap_start
-
-INPUT
-
-CHY_BOOL
-    \$var = (\$type)SvTRUE(\$arg);
-
-CHY_SIGNED_INT 
-    \$var = (\$type)SvIV(\$arg);
-
-CHY_UNSIGNED_INT
-    \$var = (\$type)SvUV(\$arg);
-
-CHY_BIG_SIGNED_INT 
-    \$var = (sizeof(IV) == 8) ? (\$type)SvIV(\$arg) : (\$type)SvNV(\$arg);
-
-CHY_BIG_UNSIGNED_INT 
-    \$var = (sizeof(UV) == 8) ? (\$type)SvUV(\$arg) : (\$type)SvNV(\$arg);
-
-CONST_CHARBUF
-    \$var = (const cfish_CharBuf*)CFISH_ZCB_WRAP_STR(SvPVutf8_nolen(\$arg), SvCUR(\$arg));
-
-$class_typemap_input
-
-OUTPUT
-
-CHY_BOOL
-    sv_setiv(\$arg, (IV)\$var);
-
-CHY_SIGNED_INT
-    sv_setiv(\$arg, (IV)\$var);
-
-CHY_UNSIGNED_INT
-    sv_setuv(\$arg, (UV)\$var);
-
-CHY_BIG_SIGNED_INT
-    if (sizeof(IV) == 8) { sv_setiv(\$arg, (IV)\$var); }
-    else                 { sv_setnv(\$arg, (NV)\$var); }
-
-CHY_BIG_UNSIGNED_INT
-    if (sizeof(UV) == 8) { sv_setuv(\$arg, (UV)\$var); }
-    else                 { sv_setnv(\$arg, (NV)\$var); }
-
-$class_typemap_output
-
-END_STUFF
-
-    close $typemap_fh or die $!;
+    _write_xs_typemap( $args{hierarchy} );
 }
 
 1;

Added: incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.c?rev=1151602&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.c Wed Jul 27 19:41:17 2011
@@ -0,0 +1,123 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include "CFCPerlTypeMap.h"
+#include "CFCUtil.h"
+#include "CFCHierarchy.h"
+#include "CFCClass.h"
+
+#ifndef true
+    #define true 1
+    #define false 0
+#endif
+
+static const char typemap_start[] =
+    "# Auto-generated file.\n"
+    "\n"
+    "TYPEMAP\n"
+    "chy_bool_t\tCHY_BOOL\n"
+    "int8_t\tCHY_SIGNED_INT\n"
+    "int16_t\tCHY_SIGNED_INT\n"
+    "int32_t\tCHY_SIGNED_INT\n"
+    "int64_t\tCHY_BIG_SIGNED_INT\n"
+    "uint8_t\tCHY_UNSIGNED_INT\n"
+    "uint16_t\tCHY_UNSIGNED_INT\n"
+    "uint32_t\tCHY_UNSIGNED_INT\n"
+    "uint64_t\tCHY_BIG_UNSIGNED_INT\n"
+    "\n"
+    "const lucy_CharBuf*\tCONST_CHARBUF\n";
+
+
+static const char typemap_input[] =
+    "INPUT\n"
+    "\n"
+    "CHY_BOOL\n"
+    "    $var = ($type)SvTRUE($arg);\n"
+    "\n"
+    "CHY_SIGNED_INT \n"
+    "    $var = ($type)SvIV($arg);\n"
+    "\n"
+    "CHY_UNSIGNED_INT\n"
+    "    $var = ($type)SvUV($arg);\n"
+    "\n"
+    "CHY_BIG_SIGNED_INT \n"
+    "    $var = (sizeof(IV) == 8) ? ($type)SvIV($arg) : ($type)SvNV($arg);\n"
+    "\n"
+    "CHY_BIG_UNSIGNED_INT \n"
+    "    $var = (sizeof(UV) == 8) ? ($type)SvUV($arg) : ($type)SvNV($arg);\n"
+    "\n"
+    "CONST_CHARBUF\n"
+    "    $var = (const cfish_CharBuf*)CFISH_ZCB_WRAP_STR(SvPVutf8_nolen($arg), SvCUR($arg));\n"
+    "\n";
+
+static const char typemap_output[] =
+    "OUTPUT\n"
+    "\n"
+    "CHY_BOOL\n"
+    "    sv_setiv($arg, (IV)$var);\n"
+    "\n"
+    "CHY_SIGNED_INT\n"
+    "    sv_setiv($arg, (IV)$var);\n"
+    "\n"
+    "CHY_UNSIGNED_INT\n"
+    "    sv_setuv($arg, (UV)$var);\n"
+    "\n"
+    "CHY_BIG_SIGNED_INT\n"
+    "    if (sizeof(IV) == 8) { sv_setiv($arg, (IV)$var); }\n"
+    "    else                 { sv_setnv($arg, (NV)$var); }\n"
+    "\n"
+    "CHY_BIG_UNSIGNED_INT\n"
+    "    if (sizeof(UV) == 8) { sv_setuv($arg, (UV)$var); }\n"
+    "    else                 { sv_setnv($arg, (NV)$var); }\n"
+    "\n";
+
+void
+CFCPerlTypeMap_write_xs_typemap(CFCHierarchy *hierarchy) {
+    CFCClass **classes = CFCHierarchy_ordered_classes(hierarchy);
+    char *start  = CFCUtil_strdup("");
+    char *input  = CFCUtil_strdup("");
+    char *output = CFCUtil_strdup("");
+    for (int i = 0; classes[i] != NULL; i++) {
+        CFCClass *klass = classes[i];
+        const char *full_struct_sym = CFCClass_full_struct_sym(klass);
+        const char *vtable_var      = CFCClass_full_vtable_var(klass);
+
+        start = CFCUtil_cat(start, full_struct_sym, "*\t", vtable_var, "_\n",
+                            NULL);
+        input = CFCUtil_cat(input, vtable_var, "_\n"
+                            "    $var = (", full_struct_sym,
+                            "*)XSBind_sv_to_cfish_obj($arg, ", vtable_var,
+                            ", NULL);\n\n", NULL);
+
+        output = CFCUtil_cat(output, vtable_var, "_\n"
+            "    $arg = (SV*)Cfish_Obj_To_Host((cfish_Obj*)$var);\n"
+            "    LUCY_DECREF($var);\n"
+            "\n", NULL);
+    }
+
+    char *content = CFCUtil_strdup("");
+    content = CFCUtil_cat(content, typemap_start, start, "\n\n",
+                          typemap_input, input, "\n\n", 
+                          typemap_output, output, "\n\n", NULL);
+    CFCUtil_write_if_changed("typemap", content, strlen(content));
+
+    FREEMEM(content);
+    FREEMEM(output);
+    FREEMEM(input);
+    FREEMEM(start);
+}
+

Propchange: incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.h?rev=1151602&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.h Wed Jul 27 19:41:17 2011
@@ -0,0 +1,34 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_CFCPERLTYPEMAP
+#define H_CFCPERLTYPEMAP
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct CFCHierarchy;
+
+void
+CFCPerlTypeMap_write_xs_typemap(struct CFCHierarchy *hierarchy);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCPERLTYPEMAP */
+

Propchange: incubator/lucy/trunk/clownfish/src/CFCPerlTypeMap.h
------------------------------------------------------------------------------
    svn:eol-style = native