Starting to see how this could work with static arrays
This commit is contained in:
parent
08b1d78faf
commit
6e0c554cf2
@ -192,6 +192,13 @@ def expression(wgn: WasmGenerator, inp: ourlang.Expression) -> None:
|
|||||||
wgn.i32.const(inp.variable.data_block.address)
|
wgn.i32.const(inp.variable.data_block.address)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if isinstance(inp.type3, type3types.AppliedType3):
|
||||||
|
if inp.type3.base is type3types.static_array:
|
||||||
|
assert inp.variable.data_block is not None, 'Static arrays must be memory stored'
|
||||||
|
assert inp.variable.data_block.address is not None, 'Value not allocated'
|
||||||
|
wgn.i32.const(inp.variable.data_block.address)
|
||||||
|
return
|
||||||
|
|
||||||
# TODO: Broken after new type system
|
# TODO: Broken after new type system
|
||||||
# if isinstance(inp.type, typing.TypeTuple):
|
# if isinstance(inp.type, typing.TypeTuple):
|
||||||
# assert isinstance(inp.definition.constant, ourlang.ConstantTuple)
|
# assert isinstance(inp.definition.constant, ourlang.ConstantTuple)
|
||||||
@ -306,7 +313,20 @@ def expression(wgn: WasmGenerator, inp: ourlang.Expression) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(inp, ourlang.Subscript):
|
if isinstance(inp, ourlang.Subscript):
|
||||||
# assert inp.varref.type3 is not None, typing.ASSERTION_ERROR
|
assert isinstance(inp.varref.type3, type3types.Type3), type3types.TYPE3_ASSERTION_ERROR
|
||||||
|
|
||||||
|
if isinstance(inp.varref.type3, type3types.AppliedType3):
|
||||||
|
if inp.varref.type3.base is type3types.static_array:
|
||||||
|
assert 1 == len(inp.varref.type3.args)
|
||||||
|
assert isinstance(inp.varref.type3.args[0], type3types.Type3)
|
||||||
|
|
||||||
|
expression(wgn, inp.varref)
|
||||||
|
expression(wgn, inp.index)
|
||||||
|
wgn.i32.const(_calculate_alloc_size(inp.varref.type3.args[0]))
|
||||||
|
wgn.i32.mul()
|
||||||
|
wgn.i32.add()
|
||||||
|
return
|
||||||
|
|
||||||
#
|
#
|
||||||
# assert inp.varref.type_var is not None, typing.ASSERTION_ERROR
|
# assert inp.varref.type_var is not None, typing.ASSERTION_ERROR
|
||||||
# tc_type = inp.varref.type_var.get_type()
|
# tc_type = inp.varref.type_var.get_type()
|
||||||
|
|||||||
@ -364,6 +364,18 @@ class CanBeSubscriptedConstraint(ConstraintBase):
|
|||||||
self.index_type3 = index.type3
|
self.index_type3 = index.type3
|
||||||
|
|
||||||
def check(self, smap: SubstitutionMap) -> CheckResult:
|
def check(self, smap: SubstitutionMap) -> CheckResult:
|
||||||
|
if isinstance(self.type3, types.PlaceholderForType):
|
||||||
|
if self.type3 not in smap:
|
||||||
|
return RequireTypeSubstitutes()
|
||||||
|
|
||||||
|
self.type3 = smap[self.type3]
|
||||||
|
|
||||||
|
if isinstance(self.type3, types.AppliedType3):
|
||||||
|
if self.type3.base is types.static_array:
|
||||||
|
return [
|
||||||
|
SameTypeConstraint(types.u32, self.index_type3, comment='([]) :: Subscriptable a => a b -> u32 -> b')
|
||||||
|
]
|
||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
# if isinstance(self.type3, types.PlaceholderForType):
|
# if isinstance(self.type3, types.PlaceholderForType):
|
||||||
# return RequireTypeSubstitutes()
|
# return RequireTypeSubstitutes()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user