ideas [skip-ci]
This commit is contained in:
parent
edd12e5b7c
commit
633267b37d
@ -16,32 +16,47 @@ class Visitor(ast.NodeVisitor):
|
|||||||
# ))
|
# ))
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
|
is_export = False
|
||||||
|
|
||||||
if node.decorator_list:
|
if node.decorator_list:
|
||||||
# TODO: Support normal decorators
|
# TODO: Support normal decorators
|
||||||
assert 1 == len(node.decorator_list)
|
assert 1 == len(node.decorator_list)
|
||||||
|
|
||||||
call = node.decorator_list[0]
|
call = node.decorator_list[0]
|
||||||
assert 'external' == call.func.id
|
if not isinstance(call, ast.Name):
|
||||||
assert 1 == len(call.args)
|
assert isinstance(call, ast.Call)
|
||||||
assert isinstance(call.args[0].value, str)
|
|
||||||
|
|
||||||
import_ = Import(
|
assert 'external' == call.func.id
|
||||||
call.args[0].value,
|
assert 1 == len(call.args)
|
||||||
node.name,
|
assert isinstance(call.args[0].value, str)
|
||||||
node.name,
|
|
||||||
)
|
|
||||||
|
|
||||||
import_.params = [
|
import_ = Import(
|
||||||
arg.annotation.id
|
call.args[0].value,
|
||||||
for arg in node.args.args
|
node.name,
|
||||||
]
|
node.name,
|
||||||
|
)
|
||||||
|
|
||||||
self.module.imports.append(import_)
|
import_.params = [
|
||||||
return
|
arg.annotation.id
|
||||||
|
for arg in node.args.args
|
||||||
|
]
|
||||||
|
|
||||||
|
self.module.imports.append(import_)
|
||||||
|
return
|
||||||
|
|
||||||
|
assert call.id == 'export'
|
||||||
|
is_export = True
|
||||||
|
|
||||||
func = Function(
|
func = Function(
|
||||||
node.name,
|
node.name,
|
||||||
|
is_export,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for arg in node.args.args:
|
||||||
|
func.params.append(
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
self._stack.append(func)
|
self._stack.append(func)
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
self._stack.pop()
|
self._stack.pop()
|
||||||
|
|||||||
@ -25,6 +25,7 @@ class Function:
|
|||||||
def __init__(self, name, exported=True):
|
def __init__(self, name, exported=True):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.exported = exported # TODO: Use __all__!
|
self.exported = exported # TODO: Use __all__!
|
||||||
|
self.params = []
|
||||||
self.statements = []
|
self.statements = []
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
@ -39,7 +40,7 @@ class Module:
|
|||||||
self.functions = functions or []
|
self.functions = functions or []
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
return '(module\n {}\n {})'.format(
|
return '(module\n {}\n {})\n'.format(
|
||||||
'\n '.join(x.generate() for x in self.imports),
|
'\n '.join(x.generate() for x in self.imports),
|
||||||
'\n '.join(x.generate() for x in self.functions),
|
'\n '.join(x.generate() for x in self.functions),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -75,8 +75,12 @@ def test_fib():
|
|||||||
def logInt32(value: i32) -> None:
|
def logInt32(value: i32) -> None:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def helper(arg: i32) -> i32:
|
||||||
|
return arg + 1
|
||||||
|
|
||||||
|
@export
|
||||||
def testEntry():
|
def testEntry():
|
||||||
logInt32(13 + 13 * 123)
|
logInt32(13 + 13 * helper(122))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = Suite(code_py, 'test_fib').run_code()
|
result = Suite(code_py, 'test_fib').run_code()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user