Skip to content

Commit

Permalink
reticulate binding v0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
24sharkS committed Jul 3, 2020
1 parent 53a60c4 commit c23210a
Show file tree
Hide file tree
Showing 10 changed files with 918 additions and 328 deletions.
466 changes: 261 additions & 205 deletions autowrap/CodeGenerator.py

Large diffs are not rendered by default.

48 changes: 22 additions & 26 deletions autowrap/ConversionProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

# left Map and Vector converter for now.

from collections import defaultdict

from autowrap.Types import CppType # , printable
Expand Down Expand Up @@ -169,9 +171,11 @@ def call_method(self, res_type, cy_call_str):
cy_res_type = self.converters.cython_type(res_type)
if cy_res_type.is_ref:
cy_res_type = cy_res_type.base_type
return "cdef %s _r = %s" % (cy_res_type, cy_call_str)
return "_r = %s" % cy_call_str
# return "cdef %s _r = %s" % cy_call_str

return "cdef %s _r = %s" % (cy_res_type, cy_call_str)
return "_r = %s" % cy_call_str
# return "cdef %s _r = %s" % (cy_res_type, cy_call_str)

def matching_python_type(self, cpp_type):
raise NotImplementedError()
Expand Down Expand Up @@ -269,13 +273,13 @@ def type_check_expression(self, cpp_type, argument_var):

def input_conversion(self, cpp_type, argument_var, arg_num):
code = ""
call_as = ""
call_as = "%s" % argument_var
#call_as = "(<%s>%s)" % (cpp_type, argument_var)
cleanup = ""
return code, call_as, cleanup

def output_conversion(self, cpp_type, input_cpp_var, output_py_var):
return None
return "%s = %s" % (output_py_var, input_cpp_var)
#return "%s = <%s>%s" % (output_py_var, cpp_type, input_cpp_var)


Expand All @@ -300,13 +304,13 @@ def type_check_expression(self, cpp_type, argument_var):

def input_conversion(self, cpp_type, argument_var, arg_num):
code = ""
call_as = ""
call_as = "%s" % argument_var
#call_as = "(<%s>%s)" % (cpp_type, argument_var)
cleanup = ""
return code, call_as, cleanup

def output_conversion(self, cpp_type, input_cpp_var, output_py_var):
return None
return "%s = %s" % (output_py_var,input_cpp_var)
#return "%s = <%s>%s" % (output_py_var, cpp_type, input_cpp_var)


Expand All @@ -331,13 +335,13 @@ def type_check_expression(self, cpp_type, argument_var):

def input_conversion(self, cpp_type, argument_var, arg_num):
code = ""
call_as = ""
call_as = "%s" % argument_var
#call_as = "(<%s>%s)" % (cpp_type, argument_var)
cleanup = ""
return code, call_as, cleanup

def output_conversion(self, cpp_type, input_cpp_var, output_py_var):
return None
return "%s = %s" % (output_py_var,input_cpp_var)
#return "%s = <%s>%s" % (output_py_var, cpp_type, input_cpp_var)


Expand All @@ -362,13 +366,13 @@ def type_check_expression(self, cpp_type, argument_var):

def input_conversion(self, cpp_type, argument_var, arg_num):
code = ""
call_as = ""
call_as = "%s" % argument_var
# call_as = "(<_%s>%s)" % (cpp_type.base_type, argument_var)
cleanup = ""
return code, call_as, cleanup

def output_conversion(self, cpp_type, input_cpp_var, output_py_var):
return None
return "%s = %s" % (output_py_var, input_cpp_var)
#return "%s = <int>%s" % (output_py_var, input_cpp_var)


Expand All @@ -380,20 +384,17 @@ def get_base_types(self):
def matches(self, cpp_type):
return not cpp_type.is_ptr

def matching_r_type(self, cpp_type):
def matching_python_type(self, cpp_type):
return "bytes"

# def matching_python_type(self, cpp_type):
# return "bytes"

def type_check_expression(self, cpp_type, argument_var):
return "is_scalar_character(%s)" % (argument_var,)
#return "isinstance(%s, bytes) and len(%s) == 1" % (argument_var, argument_var,)

# not final
def input_conversion(self, cpp_type, argument_var, arg_num):
code = "py_run_string(\"%s = bytes(%s)\")" % (argument_var, argument_var,)
call_as = "%s" % argument_var
call_as = "py$%s" % argument_var
cleanup = "py_run_string(\"del %s\")" % argument_var
#code = ""
#call_as = "(<char>((%s)[0]))" % argument_var
Expand All @@ -418,19 +419,16 @@ def get_base_types(self):
def matches(self, cpp_type):
return cpp_type.is_ptr

def matching_r_type(self, cpp_type):
return "character"

# def matching_python_type(self, cpp_type):
# return "bytes"
def matching_python_type(self, cpp_type):
return "bytes"

def type_check_expression(self, cpp_type, argument_var):
return "is_scalar_character(%s)" % (argument_var,)
#return "isinstance(%s, bytes)" % (argument_var,)

def input_conversion(self, cpp_type, argument_var, arg_num):
code = "py_run_string(\"%s = bytes(%s)\")" % (argument_var, argument_var,)
call_as = "%s" % argument_var
call_as = "py%s" % argument_var
cleanup = "py_run_string(\"del %s\")" % argument_var
# code = Code().add("cdef const_char * input_%s = <const_char *> %s" % (argument_var, argument_var))
# call_as = "input_%s" % argument_var
Expand All @@ -455,11 +453,9 @@ def get_base_types(self):
def matches(self, cpp_type):
return cpp_type.is_ptr

def matching_r_type(self, cpp_type):
return "character"

# def matching_python_type(self, cpp_type):
# return "bytes"
def matching_python_type(self, cpp_type):
return "bytes"

def type_check_expression(self, cpp_type, argument_var):
return "is_scalar_character(%s)" % (argument_var,)
Expand Down Expand Up @@ -735,7 +731,7 @@ def output_conversion(self, cpp_type, input_cpp_var, output_py_var):
# """, locals())
return code

# named list in R

class StdMapConverter(TypeConverterBase):

def get_base_types(self):
Expand Down
1 change: 1 addition & 0 deletions autowrap/DeclResolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def filter_out(tt):
enum_decls = filter_out(PXDParser.EnumDecl)
class_decls = filter_out(PXDParser.CppClassDecl)

# add methods from base class to the class_decl
class_decls = _resolve_all_inheritances(class_decls)

typedef_mapping = _build_typedef_mapping(typedef_decls)
Expand Down
6 changes: 3 additions & 3 deletions autowrap/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def register_converters(converters):
mod.register_converters()
sys.path.pop(0)


# generates the extension module; for e.g. pyd for windows.
def run_cython(inc_dirs, extra_opts, out):
from Cython.Compiler.Main import compile, CompilationOptions

Expand Down Expand Up @@ -207,11 +207,11 @@ def create_wrapper_code(decls, instance_map, addons, converters, out, extra_inc_
if extra_inc_dirs is not None:
inc_dirs += extra_inc_dirs

run_cython(inc_dirs, extra_opts, out)
# run_cython(inc_dirs, extra_opts, out)
return inc_dirs


def run(pxds, addons, converters, out, extra_inc_dirs=None, extra_opts=None):
decls, instance_map = autowrap.parse(pxds, ".")
return create_wrapper_code(decls, instance_map, addons, converters, out, extra_inc_dirs,
extra_opts)
extra_opts)
29 changes: 0 additions & 29 deletions autowrap/Types.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
# encoding: utf-8

__license__ = """
Copyright (c) 2012-2014, Uwe Schmitt, all rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the ETH Zurich nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

import copy
import re
Expand Down
29 changes: 0 additions & 29 deletions autowrap/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,6 @@

from __future__ import print_function

__license__ = """
Copyright (c) 2012-2014, Uwe Schmitt, all rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the ETH Zurich nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

import sys

Expand Down
13 changes: 10 additions & 3 deletions autowrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ def generate_code(decls, instance_map, target, debug=False, manual_code=None,
import autowrap.CodeGenerator
gen = CodeGenerator.CodeGenerator(decls,
instance_map,
pyx_target_path=target,
r_target_path=target,
manual_code=manual_code,
extra_cimports=extra_cimports,
extra_cimports=extra_cimports,
allDecl=allDecl)
# gen = CodeGenerator.CodeGenerator(decls,
# instance_map,
# pyx_target_path=target,
# manual_code=manual_code,
# extra_cimports=extra_cimports,
# allDecl=allDecl)
gen.include_numpy=include_numpy
gen.create_pyx_file(debug)
gen.create_r_file(debug)
# gen.create_pyx_file(debug)
includes = gen.get_include_dirs(include_boost)
print("Autowrap has wrapped %s classes, %s methods and %s enums" % (
gen.wrapped_classes_cnt,
Expand Down
Loading

0 comments on commit c23210a

Please sign in to comment.