Some fixes for static array
This commit is contained in:
parent
d4d5e9e482
commit
1ab6dfd333
@ -35,11 +35,18 @@ def type3(inp: Type3OrPlaceholder) -> str:
|
|||||||
"""
|
"""
|
||||||
assert isinstance(inp, Type3), TYPE3_ASSERTION_ERROR
|
assert isinstance(inp, Type3), TYPE3_ASSERTION_ERROR
|
||||||
|
|
||||||
if isinstance(inp, type3types.AppliedType3) and inp.base is type3types.tuple:
|
if isinstance(inp, type3types.AppliedType3):
|
||||||
return '(' + ', '.join(
|
if inp.base is type3types.tuple:
|
||||||
type3(x)
|
return '(' + ', '.join(
|
||||||
for x in inp.args
|
type3(x)
|
||||||
) + ', )'
|
for x in inp.args
|
||||||
|
) + ', )'
|
||||||
|
|
||||||
|
if inp.base is type3types.static_array:
|
||||||
|
assert 1 == len(inp.args)
|
||||||
|
assert isinstance(inp.args[0], Type3), TYPE3_ASSERTION_ERROR
|
||||||
|
|
||||||
|
return inp.args[0].name + '[3]' # FIXME: Where to store this value?
|
||||||
|
|
||||||
return inp.name
|
return inp.name
|
||||||
|
|
||||||
|
|||||||
@ -723,7 +723,7 @@ class OurVisitor:
|
|||||||
if not isinstance(node.value, ast.Name):
|
if not isinstance(node.value, ast.Name):
|
||||||
_raise_static_error(node, 'Must be name')
|
_raise_static_error(node, 'Must be name')
|
||||||
if not isinstance(node.slice, ast.Index):
|
if not isinstance(node.slice, ast.Index):
|
||||||
_raise_static_error(node, 'Must subscript using an index')
|
_raise_static_error(node, 'Must subscript using an index') # FIXME: Do we use type level length?
|
||||||
if not isinstance(node.slice.value, ast.Constant):
|
if not isinstance(node.slice.value, ast.Constant):
|
||||||
_raise_static_error(node, 'Must subscript using a constant index')
|
_raise_static_error(node, 'Must subscript using a constant index')
|
||||||
if not isinstance(node.slice.value.value, int):
|
if not isinstance(node.slice.value.value, int):
|
||||||
|
|||||||
@ -264,25 +264,49 @@ class LiteralFitsConstraint(ConstraintBase):
|
|||||||
|
|
||||||
res: NewConstraintList
|
res: NewConstraintList
|
||||||
|
|
||||||
if isinstance(self.type3, types.AppliedType3) and self.type3.base is types.tuple:
|
if isinstance(self.type3, types.AppliedType3):
|
||||||
if not isinstance(self.literal, ourlang.ConstantTuple):
|
if self.type3.base is types.tuple:
|
||||||
return Error('Must be tuple')
|
if not isinstance(self.literal, ourlang.ConstantTuple):
|
||||||
|
return Error('Must be tuple')
|
||||||
|
|
||||||
if len(self.type3.args) != len(self.literal.value):
|
if len(self.type3.args) != len(self.literal.value):
|
||||||
return Error('Tuple element count mismatch')
|
return Error('Tuple element count mismatch')
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
res.extend(
|
res.extend(
|
||||||
LiteralFitsConstraint(x, y)
|
LiteralFitsConstraint(x, y)
|
||||||
for x, y in zip(self.type3.args, self.literal.value)
|
for x, y in zip(self.type3.args, self.literal.value)
|
||||||
)
|
)
|
||||||
res.extend(
|
res.extend(
|
||||||
SameTypeConstraint(x, y.type3)
|
SameTypeConstraint(x, y.type3)
|
||||||
for x, y in zip(self.type3.args, self.literal.value)
|
for x, y in zip(self.type3.args, self.literal.value)
|
||||||
)
|
)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
if self.type3.base is types.static_array:
|
||||||
|
if not isinstance(self.literal, ourlang.ConstantTuple):
|
||||||
|
return Error('Must be tuple')
|
||||||
|
|
||||||
|
assert 1 == len(self.type3.args)
|
||||||
|
|
||||||
|
# FIXME: How to store type level length?
|
||||||
|
# if len(self.type3.args) != len(self.literal.value):
|
||||||
|
# return Error('Tuple element count mismatch')
|
||||||
|
|
||||||
|
res = []
|
||||||
|
|
||||||
|
res.extend(
|
||||||
|
LiteralFitsConstraint(self.type3.args[0], y)
|
||||||
|
for y in self.literal.value
|
||||||
|
)
|
||||||
|
res.extend(
|
||||||
|
SameTypeConstraint(self.type3.args[0], y.type3)
|
||||||
|
for y in self.literal.value
|
||||||
|
)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
if isinstance(self.type3, types.StructType3):
|
if isinstance(self.type3, types.StructType3):
|
||||||
if not isinstance(self.literal, ourlang.ConstantStruct):
|
if not isinstance(self.literal, ourlang.ConstantStruct):
|
||||||
|
|||||||
@ -7,9 +7,23 @@ from ..constants import (
|
|||||||
)
|
)
|
||||||
from ..helpers import Suite
|
from ..helpers import Suite
|
||||||
|
|
||||||
|
@pytest.mark.integration_test
|
||||||
|
def test_module_constant_def():
|
||||||
|
code_py = """
|
||||||
|
CONSTANT: u8[3] = (24, 57, 80, )
|
||||||
|
|
||||||
|
@exported
|
||||||
|
def testEntry() -> i32:
|
||||||
|
return 0
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = Suite(code_py).run_code()
|
||||||
|
|
||||||
|
assert 0 == result.returned_value
|
||||||
|
|
||||||
@pytest.mark.integration_test
|
@pytest.mark.integration_test
|
||||||
@pytest.mark.parametrize('type_', ALL_INT_TYPES)
|
@pytest.mark.parametrize('type_', ALL_INT_TYPES)
|
||||||
def test_module_constant(type_):
|
def test_module_constant_3(type_):
|
||||||
code_py = f"""
|
code_py = f"""
|
||||||
CONSTANT: {type_}[3] = (24, 57, 80, )
|
CONSTANT: {type_}[3] = (24, 57, 80, )
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user