Cleanup type comments, old generator file
This commit is contained in:
parent
1afa3efc31
commit
4876be77fd
@ -259,64 +259,7 @@ class OurVisitor:
|
|||||||
data_block,
|
data_block,
|
||||||
)
|
)
|
||||||
|
|
||||||
raise NotImplementedError('TODO: Broken after new typing system')
|
raise NotImplementedError(f'{node} on Module AnnAssign')
|
||||||
|
|
||||||
# if isinstance(exp_type, TypeTuple):
|
|
||||||
# if not isinstance(node.value, ast.Tuple):
|
|
||||||
# _raise_static_error(node, 'Must be tuple')
|
|
||||||
#
|
|
||||||
# if len(exp_type.members) != len(node.value.elts):
|
|
||||||
# _raise_static_error(node, 'Invalid number of tuple values')
|
|
||||||
#
|
|
||||||
# tuple_data = [
|
|
||||||
# self.visit_Module_Constant(module, arg_node)
|
|
||||||
# for arg_node, mem in zip(node.value.elts, exp_type.members)
|
|
||||||
# if isinstance(arg_node, ast.Constant)
|
|
||||||
# ]
|
|
||||||
# if len(exp_type.members) != len(tuple_data):
|
|
||||||
# _raise_static_error(node, 'Tuple arguments must be constants')
|
|
||||||
#
|
|
||||||
# # Allocate the data
|
|
||||||
# data_block = ModuleDataBlock(tuple_data)
|
|
||||||
# module.data.blocks.append(data_block)
|
|
||||||
#
|
|
||||||
# # Then return the constant as a pointer
|
|
||||||
# return ModuleConstantDef(
|
|
||||||
# node.target.id,
|
|
||||||
# node.lineno,
|
|
||||||
# exp_type,
|
|
||||||
# ConstantTuple(tuple_data),
|
|
||||||
# data_block,
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# if isinstance(exp_type, TypeStaticArray):
|
|
||||||
# if not isinstance(node.value, ast.Tuple):
|
|
||||||
# _raise_static_error(node, 'Must be static array')
|
|
||||||
#
|
|
||||||
# if len(exp_type.members) != len(node.value.elts):
|
|
||||||
# _raise_static_error(node, 'Invalid number of static array values')
|
|
||||||
#
|
|
||||||
# static_array_data = [
|
|
||||||
# self.visit_Module_Constant(module, arg_node)
|
|
||||||
# for arg_node in node.value.elts
|
|
||||||
# if isinstance(arg_node, ast.Constant)
|
|
||||||
# ]
|
|
||||||
# if len(exp_type.members) != len(static_array_data):
|
|
||||||
# _raise_static_error(node, 'Static array arguments must be constants')
|
|
||||||
#
|
|
||||||
# # Allocate the data
|
|
||||||
# data_block = ModuleDataBlock(static_array_data)
|
|
||||||
# module.data.blocks.append(data_block)
|
|
||||||
#
|
|
||||||
# # Then return the constant as a pointer
|
|
||||||
# return ModuleConstantDef(
|
|
||||||
# node.target.id,
|
|
||||||
# node.lineno,
|
|
||||||
# ConstantStaticArray(static_array_data),
|
|
||||||
# data_block,
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# raise NotImplementedError(f'{node} on Module AnnAssign')
|
|
||||||
|
|
||||||
def visit_Module_stmt(self, module: Module, node: ast.stmt) -> None:
|
def visit_Module_stmt(self, module: Module, node: ast.stmt) -> None:
|
||||||
if isinstance(node, ast.FunctionDef):
|
if isinstance(node, ast.FunctionDef):
|
||||||
@ -399,9 +342,6 @@ class OurVisitor:
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError(f'Operator {node.op}')
|
raise NotImplementedError(f'Operator {node.op}')
|
||||||
|
|
||||||
# Assume the type doesn't change when descending into a binary operator
|
|
||||||
# e.g. you can do `"hello" * 3` with the code below (yet)
|
|
||||||
|
|
||||||
return BinaryOp(
|
return BinaryOp(
|
||||||
operator,
|
operator,
|
||||||
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.left),
|
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.left),
|
||||||
@ -434,9 +374,6 @@ class OurVisitor:
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError(f'Operator {node.ops}')
|
raise NotImplementedError(f'Operator {node.ops}')
|
||||||
|
|
||||||
# Assume the type doesn't change when descending into a binary operator
|
|
||||||
# e.g. you can do `"hello" * 3` with the code below (yet)
|
|
||||||
|
|
||||||
return BinaryOp(
|
return BinaryOp(
|
||||||
operator,
|
operator,
|
||||||
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.left),
|
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.left),
|
||||||
@ -528,8 +465,6 @@ class OurVisitor:
|
|||||||
if 1 != len(node.args):
|
if 1 != len(node.args):
|
||||||
_raise_static_error(node, f'Function {node.func.id} requires 1 arguments but {len(node.args)} are given')
|
_raise_static_error(node, f'Function {node.func.id} requires 1 arguments but {len(node.args)} are given')
|
||||||
|
|
||||||
# FIXME: This is a stub, proper casting is todo
|
|
||||||
|
|
||||||
return UnaryOp(
|
return UnaryOp(
|
||||||
'cast',
|
'cast',
|
||||||
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.args[0]),
|
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.args[0]),
|
||||||
@ -543,15 +478,10 @@ class OurVisitor:
|
|||||||
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.args[0]),
|
self.visit_Module_FunctionDef_expr(module, function, our_locals, node.args[0]),
|
||||||
)
|
)
|
||||||
elif node.func.id == 'foldl':
|
elif node.func.id == 'foldl':
|
||||||
# TODO: This should a much more generic function!
|
|
||||||
# For development purposes, we're assuming you're doing a foldl(Callable[[u8, u8], u8], u8, bytes)
|
|
||||||
# In the future, we should probably infer the type of the second argument,
|
|
||||||
# and use it as expected types for the other u8s and the Iterable[u8] (i.e. bytes)
|
|
||||||
|
|
||||||
if 3 != len(node.args):
|
if 3 != len(node.args):
|
||||||
_raise_static_error(node, f'Function {node.func.id} requires 3 arguments but {len(node.args)} are given')
|
_raise_static_error(node, f'Function {node.func.id} requires 3 arguments but {len(node.args)} are given')
|
||||||
|
|
||||||
# TODO: This is not generic
|
# TODO: This is not generic, you cannot return a function
|
||||||
subnode = node.args[0]
|
subnode = node.args[0]
|
||||||
if not isinstance(subnode, ast.Name):
|
if not isinstance(subnode, ast.Name):
|
||||||
raise NotImplementedError(f'Calling methods that are not a name {subnode}')
|
raise NotImplementedError(f'Calling methods that are not a name {subnode}')
|
||||||
|
|||||||
@ -1,69 +0,0 @@
|
|||||||
"""
|
|
||||||
Helper functions to quickly generate WASM code
|
|
||||||
"""
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
import functools
|
|
||||||
|
|
||||||
from . import wasm
|
|
||||||
|
|
||||||
#pylint: disable=C0103,C0115,C0116,R0201,R0902
|
|
||||||
|
|
||||||
class Prefix_inn_fnn:
|
|
||||||
def __init__(self, prefix: str) -> None:
|
|
||||||
self.prefix = prefix
|
|
||||||
|
|
||||||
# 6.5.5. Memory Instructions
|
|
||||||
self.load = functools.partial(wasm.Statement, f'{self.prefix}.load')
|
|
||||||
self.store = functools.partial(wasm.Statement, f'{self.prefix}.store')
|
|
||||||
|
|
||||||
# 6.5.6. Numeric Instructions
|
|
||||||
self.clz = functools.partial(wasm.Statement, f'{self.prefix}.clz')
|
|
||||||
self.ctz = functools.partial(wasm.Statement, f'{self.prefix}.ctz')
|
|
||||||
self.popcnt = functools.partial(wasm.Statement, f'{self.prefix}.popcnt')
|
|
||||||
self.add = functools.partial(wasm.Statement, f'{self.prefix}.add')
|
|
||||||
self.sub = functools.partial(wasm.Statement, f'{self.prefix}.sub')
|
|
||||||
self.mul = functools.partial(wasm.Statement, f'{self.prefix}.mul')
|
|
||||||
self.div_s = functools.partial(wasm.Statement, f'{self.prefix}.div_s')
|
|
||||||
self.div_u = functools.partial(wasm.Statement, f'{self.prefix}.div_u')
|
|
||||||
self.rem_s = functools.partial(wasm.Statement, f'{self.prefix}.rem_s')
|
|
||||||
self.rem_u = functools.partial(wasm.Statement, f'{self.prefix}.rem_u')
|
|
||||||
self.and_ = functools.partial(wasm.Statement, f'{self.prefix}.and')
|
|
||||||
self.or_ = functools.partial(wasm.Statement, f'{self.prefix}.or')
|
|
||||||
self.xor = functools.partial(wasm.Statement, f'{self.prefix}.xor')
|
|
||||||
self.shl = functools.partial(wasm.Statement, f'{self.prefix}.shl')
|
|
||||||
self.shr_s = functools.partial(wasm.Statement, f'{self.prefix}.shr_s')
|
|
||||||
self.shr_u = functools.partial(wasm.Statement, f'{self.prefix}.shr_u')
|
|
||||||
self.rotl = functools.partial(wasm.Statement, f'{self.prefix}.rotl')
|
|
||||||
self.rotr = functools.partial(wasm.Statement, f'{self.prefix}.rotr')
|
|
||||||
|
|
||||||
self.eqz = functools.partial(wasm.Statement, f'{self.prefix}.eqz')
|
|
||||||
self.eq = functools.partial(wasm.Statement, f'{self.prefix}.eq')
|
|
||||||
self.ne = functools.partial(wasm.Statement, f'{self.prefix}.ne')
|
|
||||||
self.lt_s = functools.partial(wasm.Statement, f'{self.prefix}.lt_s')
|
|
||||||
self.lt_u = functools.partial(wasm.Statement, f'{self.prefix}.lt_u')
|
|
||||||
self.gt_s = functools.partial(wasm.Statement, f'{self.prefix}.gt_s')
|
|
||||||
self.gt_u = functools.partial(wasm.Statement, f'{self.prefix}.gt_u')
|
|
||||||
self.le_s = functools.partial(wasm.Statement, f'{self.prefix}.le_s')
|
|
||||||
self.le_u = functools.partial(wasm.Statement, f'{self.prefix}.le_u')
|
|
||||||
self.ge_s = functools.partial(wasm.Statement, f'{self.prefix}.ge_s')
|
|
||||||
self.ge_u = functools.partial(wasm.Statement, f'{self.prefix}.ge_u')
|
|
||||||
|
|
||||||
def const(self, value: int, comment: Optional[str] = None) -> wasm.Statement:
|
|
||||||
return wasm.Statement(f'{self.prefix}.const', f'0x{value:08x}', comment=comment)
|
|
||||||
|
|
||||||
i32 = Prefix_inn_fnn('i32')
|
|
||||||
i64 = Prefix_inn_fnn('i64')
|
|
||||||
|
|
||||||
class Block:
|
|
||||||
def __init__(self, start: str) -> None:
|
|
||||||
self.start = start
|
|
||||||
|
|
||||||
def __call__(self, *statements: wasm.Statement) -> List[wasm.Statement]:
|
|
||||||
return [
|
|
||||||
wasm.Statement('if'),
|
|
||||||
*statements,
|
|
||||||
wasm.Statement('end'),
|
|
||||||
]
|
|
||||||
|
|
||||||
if_ = Block('if')
|
|
||||||
Loading…
x
Reference in New Issue
Block a user