Skip to content

Commit

Permalink
Add support for tuples.
Browse files Browse the repository at this point in the history
This had to reorganize a lot of the emitters code because the parts
outside of Emitter got too complicated and we needed to share code
between visit_box and the return result boxing and so forth.

NOTE: The tuples have basically nothing supported (indexing does
not work and no time to figure out why). However, the code generation
and unboxing/inner unboxing IS functional.
  • Loading branch information
jhance committed Jul 26, 2017
1 parent 362715b commit 947b0f7
Show file tree
Hide file tree
Showing 6 changed files with 295 additions and 157 deletions.
23 changes: 15 additions & 8 deletions mypyc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,45 @@

from mypyc.emitter import (
native_function_header,
generate_c_for_function,
wrapper_function_header,
generate_wrapper_function
CodeGenerator,
)
from mypyc.common import PREFIX
from mypyc.ops import FuncIR


def generate_c_module(name: str, fns: List[FuncIR]) -> str:
result = []
result.append('#include <Python.h>')
result.append('#include <CPy.h>')
result.append('')

for fn in fns:
fragments = generate_function_declaration(fn)
result.extend(fragments)

result.append('')

code_generator = CodeGenerator()

fragments = generate_module_def(name, fns)
result.extend(fragments)

for fn in fns:
result.append('')
fragments = generate_c_for_function(fn)
fragments = code_generator.generate_c_for_function(fn)
result.extend([frag.rstrip() for frag in fragments])
result.append('')
fragments = generate_wrapper_function(fn)
fragments = code_generator.generate_wrapper_function(fn)
result.extend(fragments)

return '\n'.join(result)
fresult = []
fresult.append('#include <Python.h>')
fresult.append('#include <CPy.h>')
fresult.append('')

fresult += code_generator.struct_declarations

fresult += result

return '\n'.join(fresult)


def generate_function_declaration(fn: FuncIR) -> List[str]:
Expand Down
Loading

0 comments on commit 947b0f7

Please sign in to comment.