ideas [skip-ci]

This commit is contained in:
Johan B.W. de Vries 2021-04-04 16:43:55 +02:00
parent edd12e5b7c
commit 633267b37d
3 changed files with 36 additions and 16 deletions

View File

@ -16,10 +16,16 @@ 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]
if not isinstance(call, ast.Name):
assert isinstance(call, ast.Call)
assert 'external' == call.func.id assert 'external' == call.func.id
assert 1 == len(call.args) assert 1 == len(call.args)
assert isinstance(call.args[0].value, str) assert isinstance(call.args[0].value, str)
@ -38,8 +44,17 @@ class Visitor(ast.NodeVisitor):
self.module.imports.append(import_) self.module.imports.append(import_)
return 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)

View File

@ -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),
) )

View File

@ -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()