Commit 99327e65 authored by Robert Bradshaw's avatar Robert Bradshaw

more compiler cythonization

more balancing needs to be done.
parent b754b352
...@@ -716,9 +716,11 @@ class CVarDefNode(StatNode): ...@@ -716,9 +716,11 @@ class CVarDefNode(StatNode):
# in_pxd boolean # in_pxd boolean
# api boolean # api boolean
# need_properties [entry] # need_properties [entry]
# pxd_locals [CVarDefNode] (used for functions declared in pxd)
child_attrs = ["base_type", "declarators"] child_attrs = ["base_type", "declarators"]
need_properties = () need_properties = ()
pxd_locals = []
def analyse_declarations(self, env, dest_scope = None): def analyse_declarations(self, env, dest_scope = None):
if not dest_scope: if not dest_scope:
...@@ -754,6 +756,7 @@ class CVarDefNode(StatNode): ...@@ -754,6 +756,7 @@ class CVarDefNode(StatNode):
entry = dest_scope.declare_cfunction(name, type, declarator.pos, entry = dest_scope.declare_cfunction(name, type, declarator.pos,
cname = cname, visibility = self.visibility, in_pxd = self.in_pxd, cname = cname, visibility = self.visibility, in_pxd = self.in_pxd,
api = self.api) api = self.api)
entry.pxd_locals = self.pxd_locals
else: else:
if self.in_pxd and self.visibility != 'extern': if self.in_pxd and self.visibility != 'extern':
error(self.pos, error(self.pos,
...@@ -890,10 +893,12 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -890,10 +893,12 @@ class FuncDefNode(StatNode, BlockNode):
# #filename string C name of filename string const # #filename string C name of filename string const
# entry Symtab.Entry # entry Symtab.Entry
# needs_closure boolean Whether or not this function has inner functions/classes/yield # needs_closure boolean Whether or not this function has inner functions/classes/yield
# pxd_locals [CVarDefNode] locals defined in the pxd
py_func = None py_func = None
assmt = None assmt = None
needs_closure = False needs_closure = False
pxd_locals = []
def analyse_default_values(self, env): def analyse_default_values(self, env):
genv = env.global_scope() genv = env.global_scope()
...@@ -1497,7 +1502,8 @@ class DefNode(FuncDefNode): ...@@ -1497,7 +1502,8 @@ class DefNode(FuncDefNode):
with_gil = cfunc.type.with_gil, with_gil = cfunc.type.with_gil,
nogil = cfunc.type.nogil, nogil = cfunc.type.nogil,
visibility = 'private', visibility = 'private',
api = False) api = False,
pxd_locals = cfunc.pxd_locals)
def analyse_declarations(self, env): def analyse_declarations(self, env):
if 'locals' in env.directives: if 'locals' in env.directives:
......
...@@ -234,6 +234,22 @@ class PxdPostParse(CythonTransform): ...@@ -234,6 +234,22 @@ class PxdPostParse(CythonTransform):
if (isinstance(node, DefNode) and self.scope_type == 'cclass' if (isinstance(node, DefNode) and self.scope_type == 'cclass'
and node.name in ('__getbuffer__', '__releasebuffer__')): and node.name in ('__getbuffer__', '__releasebuffer__')):
ok = True ok = True
if isinstance(node, CFuncDefNode):
ok = True
for stat in node.body.stats:
if not isinstance(stat, CVarDefNode):
self.context.error("C function definition not allowed here")
ok = False
break
node = CVarDefNode(node.pos,
visibility = node.visibility,
base_type = node.base_type,
declarators = [node.declarator],
in_pxd = True,
api = node.api,
overridable = node.overridable,
pxd_locals = node.body.stats)
if not ok: if not ok:
self.context.nonfatal_error(PostParseError(node.pos, self.context.nonfatal_error(PostParseError(node.pos,
...@@ -547,6 +563,8 @@ property NAME: ...@@ -547,6 +563,8 @@ property NAME:
lenv.declare_var(var, type, type_node.pos) lenv.declare_var(var, type, type_node.pos)
else: else:
error(type_node.pos, "Not a type") error(type_node.pos, "Not a type")
for stat in node.pxd_locals:
stat.analyse_declarations(lenv)
node.body.analyse_declarations(lenv) node.body.analyse_declarations(lenv)
self.env_stack.append(lenv) self.env_stack.append(lenv)
self.visitchildren(node) self.visitchildren(node)
......
...@@ -2128,7 +2128,7 @@ def p_c_func_or_var_declaration(s, pos, ctx): ...@@ -2128,7 +2128,7 @@ def p_c_func_or_var_declaration(s, pos, ctx):
assignable = 1, nonempty = 1) assignable = 1, nonempty = 1)
declarator.overridable = ctx.overridable declarator.overridable = ctx.overridable
if s.sy == ':': if s.sy == ':':
if ctx.level not in ('module', 'c_class'): if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd'):
s.error("C function definition not allowed here") s.error("C function definition not allowed here")
doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1) doc, suite = p_suite(s, Ctx(level = 'function'), with_doc = 1)
result = Nodes.CFuncDefNode(pos, result = Nodes.CFuncDefNode(pos,
......
...@@ -13,3 +13,14 @@ cdef class PyrexScanner(Scanner): ...@@ -13,3 +13,14 @@ cdef class PyrexScanner(Scanner):
cdef public int bracket_nesting_level cdef public int bracket_nesting_level
cdef public sy cdef public sy
cdef public systring cdef public systring
cdef long current_level(self)
cpdef begin(self, state)
cpdef next(self)
cpdef bint expect(self, what, message = *) except -2
cpdef indentation_action(self, text):
cdef:
long current_level
long new_level
...@@ -415,7 +415,7 @@ class PyrexScanner(Scanner): ...@@ -415,7 +415,7 @@ class PyrexScanner(Scanner):
systring.encoding = self.source_encoding systring.encoding = self.source_encoding
self.sy = sy self.sy = sy
self.systring = systring self.systring = systring
if debug_scanner: if False: # debug_scanner:
_, line, col = self.position() _, line, col = self.position()
if not self.systring or self.sy == self.systring: if not self.systring or self.sy == self.systring:
t = self.sy t = self.sy
......
import cython
cdef class Scanner: cdef class Scanner:
cdef public lexicon cdef public lexicon
cdef public stream cdef public stream
...@@ -12,12 +14,31 @@ cdef class Scanner: ...@@ -12,12 +14,31 @@ cdef class Scanner:
cdef public long start_line cdef public long start_line
cdef public long start_col cdef public long start_col
cdef public text cdef public text
cdef public initial_state cdef public initial_state # int?
cdef public state_name cdef public state_name
cdef public list queue cdef public list queue
cdef public bint trace cdef public bint trace
cdef public cur_char cdef public cur_char
cdef public input_state cdef public input_state
cdef public level cdef public level # int?
\ No newline at end of file cpdef next_char(self):
cdef:
long input_state
cpdef run_machine_inlined(self):
cdef:
long cur_pos
long cur_line
long cur_line_start
long input_state
long next_pos
long buf_start_pos
long buf_len
long buf_index
bint trace
long discard
cpdef begin(self, state)
cpdef produce(self, value, text = *)
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