Skip to content

Commit c212cbc

Browse files
committed
fix elem_init after instrWithPos
1 parent 315c57c commit c212cbc

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎pykwasm/src/pykwasm/binary/module.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,18 @@ def elemkind(s: InputStream) -> KInner:
167167
def elem_init(init: list[list[KInner]]) -> list[int | None]:
168168
def expr_to_int(expr: list[KInner]) -> int | None:
169169
# 'expr' must be a constant expression consisting of a reference instruction
170-
match expr:
171-
case [KApply(KLabel('aRef.func'), (KToken(sfuncidx, KSort('Int')),))]:
170+
if len(expr) != 1:
171+
raise WasmParseError(f'Expected a constant reference instruction as elem initializer, got {expr}')
172+
instr = expr[0]
173+
if isinstance(instr, KApply) and instr.label == KLabel('aInstrWithPos'):
174+
instr = instr.args[0]
175+
match instr:
176+
case KApply(KLabel('aRef.func'), (KToken(sfuncidx, KSort('Int')),)):
172177
return int(sfuncidx)
173-
case [KApply(KLabel('aRef.null'), _)]:
178+
case KApply(KLabel('aRef.null'), _):
174179
return None
175180
case _:
176-
raise WasmParseError(f'Expected a constant reference instruction as elem initializer, got {expr}')
181+
raise WasmParseError(f'Expected a constant reference instruction as elem initializer, got {instr}')
177182

178183
return [expr_to_int(e) for e in init]
179184

0 commit comments

Comments
 (0)