@@ -348,12 +348,18 @@ def test_roundtrip(t, v):
348
348
caller_inst = ComponentInstance ()
349
349
caller_cx = CallContext (caller_opts , caller_inst )
350
350
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 )) ]
352
356
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 ])
354
360
355
361
if got != v :
356
- fail ("test_roundtrip({},{},{} ) got {}" .format (t , v , caller_args , got ))
362
+ fail ("test_roundtrip({},{}) got {}" .format (t , v , got ))
357
363
358
364
assert (caller_inst .may_leave and caller_inst .may_enter )
359
365
assert (callee_inst .may_leave and callee_inst .may_enter )
@@ -364,6 +370,9 @@ def test_roundtrip(t, v):
364
370
test_roundtrip (List (String ()), [mk_str ("hello there" )])
365
371
test_roundtrip (List (List (String ())), [[mk_str ("one" ),mk_str ("two" )],[mk_str ("three" )]])
366
372
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" ))})
367
376
368
377
def test_handles ():
369
378
before = definitions .MAX_FLAT_RESULTS
0 commit comments