Compare commits
2 Commits
bd80210ba3
...
4a4c62c728
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a4c62c728 | ||
|
|
fcbd32a880 |
@ -39,7 +39,7 @@ def type3(inp: Type3OrPlaceholder) -> str:
|
||||
assert isinstance(inp.args[0], Type3), TYPE3_ASSERTION_ERROR
|
||||
assert isinstance(inp.args[1], type3types.IntType3), TYPE3_ASSERTION_ERROR
|
||||
|
||||
return inp.args[0].name + '[' + inp.args[1].name + ']'
|
||||
return type3(inp.args[0]) + '[' + inp.args[1].name + ']'
|
||||
|
||||
return inp.name
|
||||
|
||||
|
||||
@ -194,7 +194,7 @@ def tuple_instantiation(wgn: WasmGenerator, inp: ourlang.TupleInstantiation) ->
|
||||
|
||||
assert element.type3 == exp_type3
|
||||
|
||||
if isinstance(exp_type3, type3types.AppliedType3) and exp_type3.base is type3types.tuple:
|
||||
if isinstance(exp_type3, type3types.StructType3) or isinstance(exp_type3, type3types.AppliedType3):
|
||||
mtyp = 'i32'
|
||||
else:
|
||||
assert isinstance(exp_type3, type3types.PrimitiveType3), NotImplementedError('Tuple of applied types / structs')
|
||||
@ -859,7 +859,7 @@ def _generate_struct_constructor(wgn: WasmGenerator, inp: ourlang.StructConstruc
|
||||
# Store each member individually
|
||||
for memname, mtyp3 in inp.struct_type3.members.items():
|
||||
mtyp: Optional[str]
|
||||
if isinstance(mtyp3, type3types.StructType3):
|
||||
if isinstance(mtyp3, type3types.StructType3) or isinstance(mtyp3, type3types.AppliedType3):
|
||||
mtyp = 'i32'
|
||||
else:
|
||||
mtyp = LOAD_STORE_TYPE_MAP.get(mtyp3.name)
|
||||
|
||||
@ -431,7 +431,7 @@ class OurVisitor:
|
||||
arguments = [
|
||||
self.visit_Module_FunctionDef_expr(module, function, our_locals, arg_node)
|
||||
for arg_node in node.elts
|
||||
if isinstance(arg_node, (ast.Constant, ast.Tuple, ))
|
||||
if isinstance(arg_node, (ast.Constant, ast.Tuple, ast.Call, ))
|
||||
]
|
||||
|
||||
if len(arguments) != len(node.elts):
|
||||
@ -644,8 +644,6 @@ class OurVisitor:
|
||||
_raise_static_error(node, f'Unrecognized type {node.id}')
|
||||
|
||||
if isinstance(node, ast.Subscript):
|
||||
if not isinstance(node.value, ast.Name):
|
||||
_raise_static_error(node, 'Must be name')
|
||||
if isinstance(node.slice, ast.Slice):
|
||||
_raise_static_error(node, 'Must subscript using an index')
|
||||
if not isinstance(node.slice, ast.Constant):
|
||||
@ -655,9 +653,6 @@ class OurVisitor:
|
||||
if not isinstance(node.ctx, ast.Load):
|
||||
_raise_static_error(node, 'Must be load context')
|
||||
|
||||
if node.value.id not in type3types.LOOKUP_TABLE: # FIXME: Tuple of tuples?
|
||||
_raise_static_error(node, f'Unrecognized type {node.value.id}')
|
||||
|
||||
return type3types.AppliedType3(
|
||||
type3types.static_array,
|
||||
[self.visit_type(module, node.value), type3types.IntType3(node.slice.value)],
|
||||
|
||||
@ -47,22 +47,26 @@ def generate_assertion_expect_type_error(result, error_msg, error_comment = None
|
||||
result.append(f'assert {repr(error_msg)} == exc_info.value.args[0][0].msg')
|
||||
result.append(f'assert {repr(error_comment)} == exc_info.value.args[0][0].comment')
|
||||
|
||||
def json_does_not_support_byte_values_fix(inp: Dict[Any, Any]):
|
||||
def json_does_not_support_byte_or_tuple_values_fix(inp: Any):
|
||||
if isinstance(inp, (int, float, )):
|
||||
return inp
|
||||
|
||||
if isinstance(inp, str):
|
||||
if inp.startswith('bytes:'):
|
||||
return inp[6:].encode()
|
||||
return inp
|
||||
|
||||
if isinstance(inp, list):
|
||||
return tuple(map(json_does_not_support_byte_or_tuple_values_fix, inp))
|
||||
|
||||
if isinstance(inp, dict):
|
||||
key_names = list(inp)
|
||||
for key in key_names:
|
||||
value = inp[key]
|
||||
return {
|
||||
key: json_does_not_support_byte_or_tuple_values_fix(val)
|
||||
for key, val in inp.items()
|
||||
}
|
||||
|
||||
if isinstance(value, str):
|
||||
if value.startswith('bytes:'):
|
||||
inp[key] = value[6:].encode()
|
||||
continue
|
||||
|
||||
if isinstance(value, dict):
|
||||
json_does_not_support_byte_values_fix(value)
|
||||
continue
|
||||
|
||||
if isinstance(value, list):
|
||||
raise NotImplementedError
|
||||
raise NotImplementedError(inp)
|
||||
|
||||
def generate_assertions(settings, result_code):
|
||||
result = []
|
||||
@ -75,13 +79,11 @@ def generate_assertions(settings, result_code):
|
||||
}
|
||||
|
||||
if 'PYTHON' in settings:
|
||||
locals_.update(settings['PYTHON'])
|
||||
locals_.update(json_does_not_support_byte_or_tuple_values_fix(settings['PYTHON']))
|
||||
|
||||
if 'VAL0' not in locals_:
|
||||
locals_['VAL0'] = eval(settings['VAL0'])
|
||||
|
||||
json_does_not_support_byte_values_fix(locals_)
|
||||
|
||||
exec(result_code, {}, locals_)
|
||||
|
||||
return ' ' + '\n '.join(result) + '\n'
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"TYPE_NAME": "static_array_tuple_u32_u32_3",
|
||||
"TYPE": "(u32, u32, )[3]",
|
||||
"VAL0": "((1, 100, ), (2, 200, ), (3, 300, ), )"
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
{
|
||||
"TYPE_NAME": "static_array_with_structs",
|
||||
"TYPE": "StructMain[3]",
|
||||
"VAL0": "(StructMain(1, (StructCode(-4), 4, 4.0, ), (StructCode(-1), StructCode(-2), )), StructMain(2, (StructCode(-16), 16, 16.0, ), (StructCode(3), StructCode(14), )), StructMain(3, (StructCode(-256), 256, 256.0, ), (StructCode(-9), StructCode(-98), )), )",
|
||||
"CODE_HEADER": [
|
||||
"class StructCode:",
|
||||
" code: i32",
|
||||
"",
|
||||
"class StructMain:",
|
||||
" val00: u8",
|
||||
" val01: (StructCode, u64, f32, )",
|
||||
" val02: StructCode[2]"
|
||||
],
|
||||
"PYTHON": {
|
||||
"VAL0": [
|
||||
{
|
||||
"val00": 1,
|
||||
"val01": [{"code": -4}, 4, 4.0],
|
||||
"val02": [{"code": -1}, {"code": -2}]
|
||||
},
|
||||
{
|
||||
"val00": 2,
|
||||
"val01": [{"code": -16}, 16, 16.0],
|
||||
"val02": [{"code": 3}, {"code": 14}]
|
||||
},
|
||||
{
|
||||
"val00": 3,
|
||||
"val01": [{"code": -256}, 256, 256.0],
|
||||
"val02": [{"code": -9}, {"code": -98}]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user