Import service names
This commit is contained in:
parent
cea236494f
commit
0aa8207987
@ -599,7 +599,7 @@ def import_(inp: ourlang.Function) -> wasm.Import:
|
||||
assert inp.imported
|
||||
|
||||
return wasm.Import(
|
||||
'imports',
|
||||
inp.imported,
|
||||
inp.name,
|
||||
inp.name,
|
||||
[
|
||||
|
||||
@ -292,7 +292,7 @@ class Function:
|
||||
name: str
|
||||
lineno: int
|
||||
exported: bool
|
||||
imported: bool
|
||||
imported: Optional[str]
|
||||
statements: List[Statement]
|
||||
returns_type3: Type3
|
||||
posonlyargs: List[FunctionParam]
|
||||
@ -301,7 +301,7 @@ class Function:
|
||||
self.name = name
|
||||
self.lineno = lineno
|
||||
self.exported = False
|
||||
self.imported = False
|
||||
self.imported = None
|
||||
self.statements = []
|
||||
self.returns_type3 = type3types.none # FIXME: This could be a placeholder
|
||||
self.posonlyargs = []
|
||||
|
||||
@ -133,6 +133,24 @@ class OurVisitor:
|
||||
# Do stmts at the end so we have the return value
|
||||
|
||||
for decorator in node.decorator_list:
|
||||
if isinstance(decorator, ast.Call):
|
||||
if not isinstance(decorator.func, ast.Name):
|
||||
_raise_static_error(decorator, 'Function decorators must be string')
|
||||
if not isinstance(decorator.func.ctx, ast.Load):
|
||||
_raise_static_error(decorator, 'Must be load context')
|
||||
_not_implemented(decorator.func.id == 'imported', 'Custom decorators')
|
||||
|
||||
if 1 != len(decorator.args):
|
||||
_raise_static_error(decorator, 'One argument expected')
|
||||
if not isinstance(decorator.args[0], ast.Constant):
|
||||
_raise_static_error(decorator, 'Service name must be a constant')
|
||||
if not isinstance(decorator.args[0].value, str):
|
||||
_raise_static_error(decorator, 'Service name must be a stirng')
|
||||
if 0 != len(decorator.keywords): # TODO: Allow for namespace keyword
|
||||
_raise_static_error(decorator, 'No keyword arguments expected')
|
||||
|
||||
function.imported = decorator.args[0].value
|
||||
else:
|
||||
if not isinstance(decorator, ast.Name):
|
||||
_raise_static_error(decorator, 'Function decorators must be string')
|
||||
if not isinstance(decorator.ctx, ast.Load):
|
||||
@ -142,7 +160,7 @@ class OurVisitor:
|
||||
if decorator.id == 'exported':
|
||||
function.exported = True
|
||||
else:
|
||||
function.imported = True
|
||||
function.imported = 'imports'
|
||||
|
||||
if node.returns is not None: # Note: `-> None` would be a ast.Constant
|
||||
function.returns_type3 = self.visit_type(module, node.returns)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user