Import service names
This commit is contained in:
parent
7ec273a732
commit
d1b593d4e5
@ -613,7 +613,7 @@ def import_(inp: ourlang.Function) -> wasm.Import:
|
|||||||
assert inp.imported
|
assert inp.imported
|
||||||
|
|
||||||
return wasm.Import(
|
return wasm.Import(
|
||||||
'imports',
|
inp.imported,
|
||||||
inp.name,
|
inp.name,
|
||||||
inp.name,
|
inp.name,
|
||||||
[
|
[
|
||||||
|
|||||||
@ -305,7 +305,7 @@ class Function:
|
|||||||
name: str
|
name: str
|
||||||
lineno: int
|
lineno: int
|
||||||
exported: bool
|
exported: bool
|
||||||
imported: bool
|
imported: Optional[str]
|
||||||
statements: List[Statement]
|
statements: List[Statement]
|
||||||
returns_type3: Type3
|
returns_type3: Type3
|
||||||
posonlyargs: List[FunctionParam]
|
posonlyargs: List[FunctionParam]
|
||||||
@ -314,7 +314,7 @@ class Function:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.lineno = lineno
|
self.lineno = lineno
|
||||||
self.exported = False
|
self.exported = False
|
||||||
self.imported = False
|
self.imported = None
|
||||||
self.statements = []
|
self.statements = []
|
||||||
self.returns_type3 = type3types.none # FIXME: This could be a placeholder
|
self.returns_type3 = type3types.none # FIXME: This could be a placeholder
|
||||||
self.posonlyargs = []
|
self.posonlyargs = []
|
||||||
|
|||||||
@ -134,16 +134,34 @@ class OurVisitor:
|
|||||||
# Do stmts at the end so we have the return value
|
# Do stmts at the end so we have the return value
|
||||||
|
|
||||||
for decorator in node.decorator_list:
|
for decorator in node.decorator_list:
|
||||||
if not isinstance(decorator, ast.Name):
|
if isinstance(decorator, ast.Call):
|
||||||
_raise_static_error(decorator, 'Function decorators must be string')
|
if not isinstance(decorator.func, ast.Name):
|
||||||
if not isinstance(decorator.ctx, ast.Load):
|
_raise_static_error(decorator, 'Function decorators must be string')
|
||||||
_raise_static_error(decorator, 'Must be load context')
|
if not isinstance(decorator.func.ctx, ast.Load):
|
||||||
_not_implemented(decorator.id in ('exported', 'imported'), 'Custom decorators')
|
_raise_static_error(decorator, 'Must be load context')
|
||||||
|
_not_implemented(decorator.func.id == 'imported', 'Custom decorators')
|
||||||
|
|
||||||
if decorator.id == 'exported':
|
if 1 != len(decorator.args):
|
||||||
function.exported = True
|
_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:
|
else:
|
||||||
function.imported = True
|
if not isinstance(decorator, ast.Name):
|
||||||
|
_raise_static_error(decorator, 'Function decorators must be string')
|
||||||
|
if not isinstance(decorator.ctx, ast.Load):
|
||||||
|
_raise_static_error(decorator, 'Must be load context')
|
||||||
|
_not_implemented(decorator.id in ('exported', 'imported'), 'Custom decorators')
|
||||||
|
|
||||||
|
if decorator.id == 'exported':
|
||||||
|
function.exported = True
|
||||||
|
else:
|
||||||
|
function.imported = 'imports'
|
||||||
|
|
||||||
if node.returns is not None: # Note: `-> None` would be a ast.Constant
|
if node.returns is not None: # Note: `-> None` would be a ast.Constant
|
||||||
function.returns_type3 = self.visit_type(module, node.returns)
|
function.returns_type3 = self.visit_type(module, node.returns)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user