Skip to content

Commit 971d649

Browse files
committed
Fix typo in lower_values
1 parent 9eda882 commit 971d649

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

design/mvp/CanonicalABI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ def lower_values(cx, max_flat, vs, ts, out_param = None):
15011501
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
15021502
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
15031503
store(cx, tuple_value, tuple_type, ptr)
1504-
flat_vales = [ptr]
1504+
flat_vals = [ptr]
15051505
else:
15061506
flat_vals = []
15071507
for i in range(len(vs)):

design/mvp/canonical-abi/definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ def lower_values(cx, max_flat, vs, ts, out_param = None):
11161116
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
11171117
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
11181118
store(cx, tuple_value, tuple_type, ptr)
1119-
flat_vales = [ptr]
1119+
flat_vals = [ptr]
11201120
else:
11211121
flat_vals = []
11221122
for i in range(len(vs)):

design/mvp/canonical-abi/run_tests.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,18 @@ def test_roundtrip(t, v):
348348
caller_inst = ComponentInstance()
349349
caller_cx = CallContext(caller_opts, caller_inst)
350350

351-
flat_args = lower_flat(caller_cx, v, t)
351+
return_in_heap = len(flatten_types([t])) > definitions.MAX_FLAT_RESULTS
352+
353+
flat_args = lower_values(caller_cx, definitions.MAX_FLAT_PARAMS, [v], [t])
354+
if return_in_heap:
355+
flat_args += [ caller_heap.realloc(0, 0, alignment(t), elem_size(t)) ]
352356
flat_results = canon_lower(caller_opts, caller_inst, lifted_callee, True, ft, flat_args)
353-
got = lift_flat(caller_cx, CoreValueIter(flat_results), t)
357+
if return_in_heap:
358+
flat_results = [ flat_args[-1] ]
359+
[got] = lift_values(caller_cx, definitions.MAX_FLAT_PARAMS, CoreValueIter(flat_results), [t])
354360

355361
if got != v:
356-
fail("test_roundtrip({},{},{}) got {}".format(t, v, caller_args, got))
362+
fail("test_roundtrip({},{}) got {}".format(t, v, got))
357363

358364
assert(caller_inst.may_leave and caller_inst.may_enter)
359365
assert(callee_inst.may_leave and callee_inst.may_enter)
@@ -364,6 +370,9 @@ def test_roundtrip(t, v):
364370
test_roundtrip(List(String()), [mk_str("hello there")])
365371
test_roundtrip(List(List(String())), [[mk_str("one"),mk_str("two")],[mk_str("three")]])
366372
test_roundtrip(List(Option(Tuple([String(),U16()]))), [{'some':mk_tup(mk_str("answer"),42)}])
373+
test_roundtrip(Variant([Case('x', Tuple([U32(),U32(),U32(),U32(), U32(),U32(),U32(),U32(),
374+
U32(),U32(),U32(),U32(), U32(),U32(),U32(),U32(), String()]))]),
375+
{'x': mk_tup(1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16, mk_str("wat"))})
367376

368377
def test_handles():
369378
before = definitions.MAX_FLAT_RESULTS

0 commit comments

Comments
 (0)