MVP #1

Merged
jbwdevries merged 73 commits from idea_crc32 into master 2022-08-21 12:59:21 +00:00
2 changed files with 58 additions and 13 deletions
Showing only changes of commit bd7e8d33bf - Show all commits

View File

@ -124,10 +124,8 @@ class Visitor:
if not isinstance(arg.annotation, ast.Name): if not isinstance(arg.annotation, ast.Name):
raise NotImplementedError raise NotImplementedError
print(class_lookup)
print(arg.annotation.id)
if arg.annotation.id in class_lookup: if arg.annotation.id in class_lookup:
params.append((arg.arg, arg.annotation.id, )) params.append((arg.arg, 'i32', ))
else: else:
params.append((arg.arg, _parse_annotation(arg.annotation), )) params.append((arg.arg, _parse_annotation(arg.annotation), ))
@ -296,7 +294,7 @@ class Visitor:
return self.visit_Name(wlocals, exp_type, node) return self.visit_Name(wlocals, exp_type, node)
if isinstance(node, ast.Attribute): if isinstance(node, ast.Attribute):
return [] # TODO return self.visit_Attribute(wlocals, exp_type, node)
raise NotImplementedError(node) raise NotImplementedError(node)
@ -411,14 +409,46 @@ class Visitor:
'Could not find function {}'.format(node.func.id) 'Could not find function {}'.format(node.func.id)
if isinstance(called_func_list[0], wasm.Class): if isinstance(called_func_list[0], wasm.Class):
called_params = [ return self.visit_Call_class(module, wlocals, exp_type, node, called_func_list[0])
(x.name, x.type, )
for x in called_func_list[0].members return self.visit_Call_func(module, wlocals, exp_type, node, called_func_list[0])
]
called_result: Optional[str] = called_func_list[0].name def visit_Call_class(
else: self,
called_params = called_func_list[0].params module: wasm.Module,
called_result = called_func_list[0].result wlocals: WLocals,
exp_type: str,
node: ast.Call,
func: wasm.Class,
) -> StatementGenerator:
"""
Visits a Call node as (part of) an expression
This instantiates the class
"""
# TODO: malloc call
yield wasm.Statement('i32.const 0')
yield wasm.Statement('i32.load')
def visit_Call_func(
self,
module: wasm.Module,
wlocals: WLocals,
exp_type: str,
node: ast.Call,
func: Union[wasm.Function, wasm.Import],
) -> StatementGenerator:
"""
Visits a Call node as (part of) an expression
"""
assert isinstance(node.func, ast.Name)
called_name = node.func.id
called_params = func.params
called_result = func.result
assert exp_type == called_result assert exp_type == called_result
@ -470,6 +500,20 @@ class Visitor:
raise NotImplementedError(exp_type) raise NotImplementedError(exp_type)
def visit_Attribute(self, wlocals: WLocals, exp_type: str, node: ast.Attribute) -> StatementGenerator:
"""
Visits an Attribute node as (part of) an expression
"""
if not isinstance(node.value, ast.Name):
raise NotImplementedError
if not isinstance(node.ctx, ast.Load):
raise NotImplementedError
yield wasm.Statement('local.get', '$' + node.value.id)
yield wasm.Statement(exp_type + '.load', 'offset=0') # TODO: Calculate offset based on set struct
def visit_Name(self, wlocals: WLocals, exp_type: str, node: ast.Name) -> StatementGenerator: def visit_Name(self, wlocals: WLocals, exp_type: str, node: ast.Name) -> StatementGenerator:
""" """
Visits a Name node as (part of) an expression Visits a Name node as (part of) an expression

View File

@ -120,7 +120,8 @@ class Module:
""" """
Generates the text version Generates the text version
""" """
return '(module\n {}\n {})\n'.format( return '(module\n (memory 1)\n (data (memory 0) (i32.const 0) {})\n {}\n {})\n'.format(
'"\\\\04\\\\00\\\\00\\\\00"',
'\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),
) )