Commit 78ed7c3a authored by Robert Bradshaw's avatar Robert Bradshaw

Figured out how to use the Python/C API for some builtin functions (such as...

Figured out how to use the Python/C API for some builtin functions (such as len) to avoid python calling conventions.
parent bf95cba8
......@@ -1290,7 +1290,6 @@ class SliceNode(ExprNode):
self.result_code,
code.error_goto(self.pos)))
class SimpleCallNode(ExprNode):
# Function call without keyword, * or ** args.
#
......@@ -1440,8 +1439,7 @@ class SimpleCallNode(ExprNode):
lhs,
rhs,
" && ".join(exc_checks),
code.error_goto(self.pos)))
code.error_goto(self.pos)))
class GeneralCallNode(ExprNode):
# General Python function call, including keyword,
......
......@@ -484,7 +484,7 @@ class CFuncType(CType):
self.has_varargs = has_varargs
self.exception_value = exception_value
self.exception_check = exception_check
def __repr__(self):
arg_reprs = map(repr, self.args)
if self.has_varargs:
......
......@@ -6,9 +6,7 @@ import re
from Errors import error, InternalError, warning
import Options
import Naming
from PyrexTypes import c_int_type, \
py_object_type, c_char_array_type, \
CEnumType, CStructOrUnionType, PyExtensionType
from PyrexTypes import *
from TypeSlots import \
pyfunction_signature, pymethod_signature, \
get_special_method_signature, get_property_accessor_signature
......@@ -447,12 +445,31 @@ class BuiltinScope(Scope):
def __init__(self):
Scope.__init__(self, "__builtin__", None, None)
for name, definition in self.builtin_functions.iteritems():
if len(definition) < 4: definition.append(None) # exception_value
if len(definition) < 5: definition.append(False) # exception_check
cname, type, arg_types, exception_value, exception_check = definition
function = CFuncType(type, [CFuncTypeArg("", t, None) for t in arg_types], False, exception_value, exception_check)
self.add_cfunction(name, function, None, cname, False)
def declare_builtin(self, name, pos):
entry = self.declare(name, name, py_object_type, pos)
entry.is_builtin = 1
return entry
builtin_functions = {
"hasattr": ["PyObject_HasAttrString", c_int_type, (py_object_type, c_char_ptr_type)],
"cmp": ["PyObject_Compare", c_int_type, (py_object_type, py_object_type), None, True],
"repr": ["PyObject_Repr", py_object_type, (py_object_type, ), 0],
"str": ["PyObject_Str", py_object_type, (py_object_type, ), 0],
"unicode": ["PyObject_Unicode", py_object_type, (py_object_type, ), 0],
"isinstance": ["PyObject_IsInstance", c_int_type, (py_object_type, py_object_type), -1],
"hash": ["PyObject_Hash", c_long_type, (py_object_type, ), -1, True],
"type": ["PyObject_Type", py_object_type, (py_object_type, ), 0],
"len": ["PyObject_Size", c_py_ssize_t_type, (py_object_type, ), -1],
"dir": ["PyObject_Dir", py_object_type, (py_object_type, ), 0],
"iter": ["PyObject_GetIter", py_object_type, (py_object_type, ), 0],
}
class ModuleScope(Scope):
# module_name string Python name of the module
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment