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