@@ -2827,16 +2827,13 @@ of component-level values with types `ts`.
2827
2827
def lift_flat_values (cx , max_flat , vi , ts ):
2828
2828
flat_types = flatten_types(ts)
2829
2829
if len (flat_types) > max_flat:
2830
- return lift_heap_values(cx, vi, ts)
2830
+ ptr = vi.next(' i32' )
2831
+ tuple_type = TupleType(ts)
2832
+ trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2833
+ trap_if(ptr + elem_size(tuple_type) > len (cx.opts.memory))
2834
+ return list (load(cx, ptr, tuple_type).values())
2831
2835
else :
2832
2836
return [ lift_flat(cx, vi, t) for t in ts ]
2833
-
2834
- def lift_heap_values (cx , vi , ts ):
2835
- ptr = vi.next(' i32' )
2836
- tuple_type = TupleType(ts)
2837
- trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2838
- trap_if(ptr + elem_size(tuple_type) > len (cx.opts.memory))
2839
- return list (load(cx, ptr, tuple_type).values())
2840
2837
```
2841
2838
2842
2839
Symmetrically, the ` lower_flat_values ` function defines how to lower a
@@ -2850,27 +2847,23 @@ def lower_flat_values(cx, max_flat, vs, ts, out_param = None):
2850
2847
cx.inst.may_leave = False
2851
2848
flat_types = flatten_types(ts)
2852
2849
if len (flat_types) > max_flat:
2853
- flat_vals = lower_heap_values(cx, vs, ts, out_param)
2850
+ tuple_type = TupleType(ts)
2851
+ tuple_value = {str (i): v for i,v in enumerate (vs)}
2852
+ if out_param is None :
2853
+ ptr = cx.opts.realloc(0 , 0 , alignment(tuple_type), elem_size(tuple_type))
2854
+ flat_vals = [ptr]
2855
+ else :
2856
+ ptr = out_param.next(' i32' )
2857
+ flat_vals = []
2858
+ trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2859
+ trap_if(ptr + elem_size(tuple_type) > len (cx.opts.memory))
2860
+ store(cx, tuple_value, tuple_type, ptr)
2854
2861
else :
2855
2862
flat_vals = []
2856
2863
for i in range (len (vs)):
2857
2864
flat_vals += lower_flat(cx, vs[i], ts[i])
2858
2865
cx.inst.may_leave = True
2859
2866
return flat_vals
2860
-
2861
- def lower_heap_values (cx , vs , ts , out_param ):
2862
- tuple_type = TupleType(ts)
2863
- tuple_value = {str (i): v for i,v in enumerate (vs)}
2864
- if out_param is None :
2865
- ptr = cx.opts.realloc(0 , 0 , alignment(tuple_type), elem_size(tuple_type))
2866
- flat_vals = [ptr]
2867
- else :
2868
- ptr = out_param.next(' i32' )
2869
- flat_vals = []
2870
- trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2871
- trap_if(ptr + elem_size(tuple_type) > len (cx.opts.memory))
2872
- store(cx, tuple_value, tuple_type, ptr)
2873
- return flat_vals
2874
2867
```
2875
2868
The ` may_leave ` flag is guarded by ` canon_lower ` below to prevent a component
2876
2869
from calling out of the component while in the middle of lowering, ensuring
0 commit comments