Compare commits
No commits in common. "4a4c62c7287613e390c2f0fcef877137a7bd41de" and "bd80210ba3072e443ad40222f49ceccb9e9e6b55" have entirely different histories.
4a4c62c728
...
bd80210ba3
@ -39,7 +39,7 @@ def type3(inp: Type3OrPlaceholder) -> str:
|
|||||||
assert isinstance(inp.args[0], Type3), TYPE3_ASSERTION_ERROR
|
assert isinstance(inp.args[0], Type3), TYPE3_ASSERTION_ERROR
|
||||||
assert isinstance(inp.args[1], type3types.IntType3), TYPE3_ASSERTION_ERROR
|
assert isinstance(inp.args[1], type3types.IntType3), TYPE3_ASSERTION_ERROR
|
||||||
|
|
||||||
return type3(inp.args[0]) + '[' + inp.args[1].name + ']'
|
return inp.args[0].name + '[' + inp.args[1].name + ']'
|
||||||
|
|
||||||
return inp.name
|
return inp.name
|
||||||
|
|
||||||
|
|||||||
@ -194,7 +194,7 @@ def tuple_instantiation(wgn: WasmGenerator, inp: ourlang.TupleInstantiation) ->
|
|||||||
|
|
||||||
assert element.type3 == exp_type3
|
assert element.type3 == exp_type3
|
||||||
|
|
||||||
if isinstance(exp_type3, type3types.StructType3) or isinstance(exp_type3, type3types.AppliedType3):
|
if isinstance(exp_type3, type3types.AppliedType3) and exp_type3.base is type3types.tuple:
|
||||||
mtyp = 'i32'
|
mtyp = 'i32'
|
||||||
else:
|
else:
|
||||||
assert isinstance(exp_type3, type3types.PrimitiveType3), NotImplementedError('Tuple of applied types / structs')
|
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
|
# Store each member individually
|
||||||
for memname, mtyp3 in inp.struct_type3.members.items():
|
for memname, mtyp3 in inp.struct_type3.members.items():
|
||||||
mtyp: Optional[str]
|
mtyp: Optional[str]
|
||||||
if isinstance(mtyp3, type3types.StructType3) or isinstance(mtyp3, type3types.AppliedType3):
|
if isinstance(mtyp3, type3types.StructType3):
|
||||||
mtyp = 'i32'
|
mtyp = 'i32'
|
||||||
else:
|
else:
|
||||||
mtyp = LOAD_STORE_TYPE_MAP.get(mtyp3.name)
|
mtyp = LOAD_STORE_TYPE_MAP.get(mtyp3.name)
|
||||||
|
|||||||
@ -431,7 +431,7 @@ class OurVisitor:
|
|||||||
arguments = [
|
arguments = [
|
||||||
self.visit_Module_FunctionDef_expr(module, function, our_locals, arg_node)
|
self.visit_Module_FunctionDef_expr(module, function, our_locals, arg_node)
|
||||||
for arg_node in node.elts
|
for arg_node in node.elts
|
||||||
if isinstance(arg_node, (ast.Constant, ast.Tuple, ast.Call, ))
|
if isinstance(arg_node, (ast.Constant, ast.Tuple, ))
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(arguments) != len(node.elts):
|
if len(arguments) != len(node.elts):
|
||||||
@ -644,6 +644,8 @@ class OurVisitor:
|
|||||||
_raise_static_error(node, f'Unrecognized type {node.id}')
|
_raise_static_error(node, f'Unrecognized type {node.id}')
|
||||||
|
|
||||||
if isinstance(node, ast.Subscript):
|
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):
|
if isinstance(node.slice, ast.Slice):
|
||||||
_raise_static_error(node, 'Must subscript using an index')
|
_raise_static_error(node, 'Must subscript using an index')
|
||||||
if not isinstance(node.slice, ast.Constant):
|
if not isinstance(node.slice, ast.Constant):
|
||||||
@ -653,6 +655,9 @@ class OurVisitor:
|
|||||||
if not isinstance(node.ctx, ast.Load):
|
if not isinstance(node.ctx, ast.Load):
|
||||||
_raise_static_error(node, 'Must be load context')
|
_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(
|
return type3types.AppliedType3(
|
||||||
type3types.static_array,
|
type3types.static_array,
|
||||||
[self.visit_type(module, node.value), type3types.IntType3(node.slice.value)],
|
[self.visit_type(module, node.value), type3types.IntType3(node.slice.value)],
|
||||||
|
|||||||
@ -47,26 +47,22 @@ 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_msg)} == exc_info.value.args[0][0].msg')
|
||||||
result.append(f'assert {repr(error_comment)} == exc_info.value.args[0][0].comment')
|
result.append(f'assert {repr(error_comment)} == exc_info.value.args[0][0].comment')
|
||||||
|
|
||||||
def json_does_not_support_byte_or_tuple_values_fix(inp: Any):
|
def json_does_not_support_byte_values_fix(inp: Dict[Any, Any]):
|
||||||
if isinstance(inp, (int, float, )):
|
key_names = list(inp)
|
||||||
return inp
|
for key in key_names:
|
||||||
|
value = inp[key]
|
||||||
|
|
||||||
if isinstance(inp, str):
|
if isinstance(value, str):
|
||||||
if inp.startswith('bytes:'):
|
if value.startswith('bytes:'):
|
||||||
return inp[6:].encode()
|
inp[key] = value[6:].encode()
|
||||||
return inp
|
continue
|
||||||
|
|
||||||
if isinstance(inp, list):
|
if isinstance(value, dict):
|
||||||
return tuple(map(json_does_not_support_byte_or_tuple_values_fix, inp))
|
json_does_not_support_byte_values_fix(value)
|
||||||
|
continue
|
||||||
|
|
||||||
if isinstance(inp, dict):
|
if isinstance(value, list):
|
||||||
key_names = list(inp)
|
raise NotImplementedError
|
||||||
return {
|
|
||||||
key: json_does_not_support_byte_or_tuple_values_fix(val)
|
|
||||||
for key, val in inp.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
raise NotImplementedError(inp)
|
|
||||||
|
|
||||||
def generate_assertions(settings, result_code):
|
def generate_assertions(settings, result_code):
|
||||||
result = []
|
result = []
|
||||||
@ -79,11 +75,13 @@ def generate_assertions(settings, result_code):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 'PYTHON' in settings:
|
if 'PYTHON' in settings:
|
||||||
locals_.update(json_does_not_support_byte_or_tuple_values_fix(settings['PYTHON']))
|
locals_.update(settings['PYTHON'])
|
||||||
|
|
||||||
if 'VAL0' not in locals_:
|
if 'VAL0' not in locals_:
|
||||||
locals_['VAL0'] = eval(settings['VAL0'])
|
locals_['VAL0'] = eval(settings['VAL0'])
|
||||||
|
|
||||||
|
json_does_not_support_byte_values_fix(locals_)
|
||||||
|
|
||||||
exec(result_code, {}, locals_)
|
exec(result_code, {}, locals_)
|
||||||
|
|
||||||
return ' ' + '\n '.join(result) + '\n'
|
return ' ' + '\n '.join(result) + '\n'
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"TYPE_NAME": "static_array_tuple_u32_u32_3",
|
|
||||||
"TYPE": "(u32, u32, )[3]",
|
|
||||||
"VAL0": "((1, 100, ), (2, 200, ), (3, 300, ), )"
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"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