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/06/20 20:38:40 UTC

[lucy-commits] svn commit: r1137736 - in /incubator/lucy/trunk/clownfish: include/CFC.h lib/Clownfish.xs lib/Clownfish/Binding/Core/Function.pm src/CFCBindFunction.c src/CFCBindFunction.h

Author: marvin
Date: Mon Jun 20 18:38:40 2011
New Revision: 1137736

URL: http://svn.apache.org/viewvc?rev=1137736&view=rev
Log:
Port Clownfish::Binding::Core::Function to C.

Added:
    incubator/lucy/trunk/clownfish/src/CFCBindFunction.c   (with props)
    incubator/lucy/trunk/clownfish/src/CFCBindFunction.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/Core/Function.pm

Modified: incubator/lucy/trunk/clownfish/include/CFC.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/include/CFC.h?rev=1137736&r1=1137735&r2=1137736&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Mon Jun 20 18:38:40 2011
@@ -30,3 +30,4 @@
 #include "CFCUtil.h"
 #include "CFCVariable.h"
 
+#include "CFCBindFunction.h"

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1137736&r1=1137735&r2=1137736&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Mon Jun 20 18:38:40 2011
@@ -1666,3 +1666,17 @@ PPCODE:
     END_SET_OR_GET_SWITCH
 }
 
+MODULE = Clownfish   PACKAGE = Clownfish::Binding::Core::Function
+
+SV*
+func_declaration(unused, func)
+    SV *unused;
+    CFCFunction *func;
+CODE:
+{
+    char *declaration = CFCBindFunc_func_declaration(func);
+    RETVAL = newSVpvn(declaration, strlen(declaration));
+    FREEMEM(declaration);
+}
+OUTPUT: RETVAL
+

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Function.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Function.pm?rev=1137736&r1=1137735&r2=1137736&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Function.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Function.pm Mon Jun 20 18:38:40 2011
@@ -13,24 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-use strict;
-use warnings;
-
-package Clownfish::Binding::Core::Function;
-use Clownfish::Util qw( a_isa_b );
-
-sub func_declaration {
-    my ( undef, $function ) = @_;
-    confess("Not a Function")
-        unless a_isa_b( $function, "Clownfish::Function" );
-    my $return_type = $function->get_return_type;
-    my $param_list  = $function->get_param_list;
-    my $dec         = $function->inline ? 'static CHY_INLINE ' : '';
-    $dec .= $return_type->to_c . "\n";
-    $dec .= $function->full_func_sym;
-    $dec .= "(" . $param_list->to_c . ");";
-    return $dec;
-}
+use Clownfish;
 
 1;
 

Added: incubator/lucy/trunk/clownfish/src/CFCBindFunction.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindFunction.c?rev=1137736&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindFunction.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCBindFunction.c Mon Jun 20 18:38:40 2011
@@ -0,0 +1,46 @@
+/* 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 <stdio.h>
+#include <string.h>
+#include "CFCBindFunction.h"
+#include "CFCUtil.h"
+#include "CFCFunction.h"
+#include "CFCParamList.h"
+#include "CFCType.h"
+
+char*
+CFCBindFunc_func_declaration(CFCFunction *func) {
+    CFCType      *return_type    = CFCFunction_get_return_type(func);
+    CFCParamList *param_list     = CFCFunction_get_param_list(func);
+    const char   *ret_type_str   = CFCType_to_c(return_type);
+    const char   *full_func_sym  = CFCFunction_full_func_sym(func);
+    const char   *param_list_str = CFCParamList_to_c(param_list);
+    const char   *inline_prop    = CFCFunction_inline(func)
+                                   ? "static CHY_INLINE "
+                                   : "";
+    size_t size = strlen(inline_prop)
+                  + strlen(ret_type_str)
+                  + strlen(full_func_sym)
+                  + strlen(param_list_str)
+                  + 20
+                  + strlen("\0");
+    char *buf = MALLOCATE(size);
+    sprintf(buf, "%s%s\n%s(%s);", inline_prop, ret_type_str, full_func_sym,
+            param_list_str);
+    return buf;
+}
+

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

Added: incubator/lucy/trunk/clownfish/src/CFCBindFunction.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindFunction.h?rev=1137736&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindFunction.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCBindFunction.h Mon Jun 20 18:38:40 2011
@@ -0,0 +1,35 @@
+/* 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_CFCBINDFUNCTION
+#define H_CFCBINDFUNCTION
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct CFCFunction;
+
+char*
+CFCBindFunc_func_declaration(struct CFCFunction *func);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCBINDFUNCTION */
+
+

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