Coverage for tests/codegen/generated/variants/__init__.py: 87%
454 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-20 16:25 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-20 16:25 +0000
1from .exports import e
2from .imports import RootImports, host
3from .intrinsics import _clamp, _i32_to_f32, _i64_to_f64, _store
4from .types import Err, Ok, Result, Some
5import ctypes
6import importlib_resources
7import pathlib
8from typing import Optional
9import wasmtime
11class Root:
13 def __init__(self, store: wasmtime.Store, import_object: RootImports) -> None:
14 file = importlib_resources.files() / ('root.core0.wasm')
15 if isinstance(file, pathlib.Path):
16 module = wasmtime.Module.from_file(store.engine, file)
17 else:
18 module = wasmtime.Module(store.engine, file.read_bytes())
19 instance0 = wasmtime.Instance(store, module, []).exports(store)
20 def lowering0_callee(caller: wasmtime.Caller, arg0: int, arg1: float, arg2: int) -> None:
21 option: Optional[float]
22 if arg0 == 0:
23 option = None
24 elif arg0 == 1:
25 option = arg1
26 else:
27 raise TypeError("invalid variant discriminant for option")
28 ret = import_object.host.roundtrip_option(option)
29 if ret is None:
30 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 0)
31 else:
32 payload0 = ret
33 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 1)
34 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 1, _clamp(payload0, 0, 255))
35 lowering0_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.f32(), wasmtime.ValType.i32(), ], [])
36 trampoline0 = wasmtime.Func(store, lowering0_ty, lowering0_callee, access_caller = True)
37 core_memory0 = instance0["m"]
38 assert(isinstance(core_memory0, wasmtime.Memory))
39 self._core_memory0 = core_memory0
40 def lowering1_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None:
41 expected: Result[int, float]
42 if arg0 == 0:
43 expected = Ok(arg1 & 0xffffffff)
44 elif arg0 == 1:
45 expected = Err(_i32_to_f32(arg1))
46 else:
47 raise TypeError("invalid variant discriminant for expected")
48 ret = import_object.host.roundtrip_result(expected)
49 if isinstance(ret, Ok):
50 payload = ret.value
51 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 0)
52 _store(ctypes.c_double, self._core_memory0, caller, arg2, 8, payload)
53 elif isinstance(ret, Err):
54 payload0 = ret.value
55 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 1)
56 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 8, _clamp(payload0, 0, 255))
57 else:
58 raise TypeError("invalid variant specified for expected")
59 lowering1_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], [])
60 trampoline1 = wasmtime.Func(store, lowering1_ty, lowering1_callee, access_caller = True)
61 def lowering2_callee(caller: wasmtime.Caller, arg0: int) -> int:
62 ret = import_object.host.roundtrip_enum(host.E1(arg0))
63 return (ret).value
64 lowering2_ty = wasmtime.FuncType([wasmtime.ValType.i32(), ], [wasmtime.ValType.i32(), ])
65 trampoline2 = wasmtime.Func(store, lowering2_ty, lowering2_callee, access_caller = True)
66 def lowering3_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int, arg3: int, arg4: int, arg5: int, arg6: int, arg7: int, arg8: int, arg9: int, arg10: int, arg11: int, arg12: int) -> None:
67 variant: host.C1
68 if arg0 == 0:
69 variant = host.C1A(arg1)
70 elif arg0 == 1:
71 variant = host.C1B(arg1)
72 else:
73 raise TypeError("invalid variant discriminant for C1")
74 variant0: host.C2
75 if arg2 == 0:
76 variant0 = host.C2A(arg3)
77 elif arg2 == 1:
78 variant0 = host.C2B(_i32_to_f32(arg3))
79 else:
80 raise TypeError("invalid variant discriminant for C2")
81 variant1: host.C3
82 if arg4 == 0:
83 variant1 = host.C3A(arg5)
84 elif arg4 == 1:
85 variant1 = host.C3B(_i64_to_f64(arg5))
86 else:
87 raise TypeError("invalid variant discriminant for C3")
88 variant2: host.C4
89 if arg6 == 0:
90 variant2 = host.C4A(arg7)
91 elif arg6 == 1:
92 variant2 = host.C4B(_i32_to_f32((arg7) & 0xffffffff))
93 else:
94 raise TypeError("invalid variant discriminant for C4")
95 variant3: host.C5
96 if arg8 == 0:
97 variant3 = host.C5A(arg9)
98 elif arg8 == 1:
99 variant3 = host.C5B(_i64_to_f64(arg9))
100 else:
101 raise TypeError("invalid variant discriminant for C5")
102 variant4: host.C6
103 if arg10 == 0:
104 variant4 = host.C6A(_i32_to_f32((arg11) & 0xffffffff))
105 elif arg10 == 1:
106 variant4 = host.C6B(_i64_to_f64(arg11))
107 else:
108 raise TypeError("invalid variant discriminant for C6")
109 ret = import_object.host.variant_casts((variant, variant0, variant1, variant2, variant3, variant4,))
110 (tuplei,tuplei5,tuplei6,tuplei7,tuplei8,tuplei9,) = ret
111 if isinstance(tuplei, host.C1A):
112 payload = tuplei.value
113 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 0, 0)
114 _store(ctypes.c_uint32, self._core_memory0, caller, arg12, 8, _clamp(payload, -2147483648, 2147483647))
115 elif isinstance(tuplei, host.C1B):
116 payload10 = tuplei.value
117 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 0, 1)
118 _store(ctypes.c_uint64, self._core_memory0, caller, arg12, 8, _clamp(payload10, -9223372036854775808, 9223372036854775807))
119 else:
120 raise TypeError("invalid variant specified for C1")
121 if isinstance(tuplei5, host.C2A):
122 payload11 = tuplei5.value
123 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 16, 0)
124 _store(ctypes.c_uint32, self._core_memory0, caller, arg12, 20, _clamp(payload11, -2147483648, 2147483647))
125 elif isinstance(tuplei5, host.C2B):
126 payload12 = tuplei5.value
127 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 16, 1)
128 _store(ctypes.c_float, self._core_memory0, caller, arg12, 20, payload12)
129 else:
130 raise TypeError("invalid variant specified for C2")
131 if isinstance(tuplei6, host.C3A):
132 payload13 = tuplei6.value
133 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 24, 0)
134 _store(ctypes.c_uint32, self._core_memory0, caller, arg12, 32, _clamp(payload13, -2147483648, 2147483647))
135 elif isinstance(tuplei6, host.C3B):
136 payload14 = tuplei6.value
137 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 24, 1)
138 _store(ctypes.c_double, self._core_memory0, caller, arg12, 32, payload14)
139 else:
140 raise TypeError("invalid variant specified for C3")
141 if isinstance(tuplei7, host.C4A):
142 payload15 = tuplei7.value
143 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 40, 0)
144 _store(ctypes.c_uint64, self._core_memory0, caller, arg12, 48, _clamp(payload15, -9223372036854775808, 9223372036854775807))
145 elif isinstance(tuplei7, host.C4B):
146 payload16 = tuplei7.value
147 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 40, 1)
148 _store(ctypes.c_float, self._core_memory0, caller, arg12, 48, payload16)
149 else:
150 raise TypeError("invalid variant specified for C4")
151 if isinstance(tuplei8, host.C5A):
152 payload17 = tuplei8.value
153 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 56, 0)
154 _store(ctypes.c_uint64, self._core_memory0, caller, arg12, 64, _clamp(payload17, -9223372036854775808, 9223372036854775807))
155 elif isinstance(tuplei8, host.C5B):
156 payload18 = tuplei8.value
157 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 56, 1)
158 _store(ctypes.c_double, self._core_memory0, caller, arg12, 64, payload18)
159 else:
160 raise TypeError("invalid variant specified for C5")
161 if isinstance(tuplei9, host.C6A):
162 payload19 = tuplei9.value
163 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 72, 0)
164 _store(ctypes.c_float, self._core_memory0, caller, arg12, 80, payload19)
165 elif isinstance(tuplei9, host.C6B):
166 payload20 = tuplei9.value
167 _store(ctypes.c_uint8, self._core_memory0, caller, arg12, 72, 1)
168 _store(ctypes.c_double, self._core_memory0, caller, arg12, 80, payload20)
169 else:
170 raise TypeError("invalid variant specified for C6")
171 lowering3_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), ], [])
172 trampoline3 = wasmtime.Func(store, lowering3_ty, lowering3_callee, access_caller = True)
173 def lowering4_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int, arg3: int, arg4: int, arg5: float, arg6: int, arg7: float, arg8: int) -> None:
174 variant: host.Z1
175 if arg0 == 0:
176 variant = host.Z1A(arg1)
177 elif arg0 == 1:
178 variant = host.Z1B()
179 else:
180 raise TypeError("invalid variant discriminant for Z1")
181 variant0: host.Z2
182 if arg2 == 0:
183 variant0 = host.Z2A(arg3)
184 elif arg2 == 1:
185 variant0 = host.Z2B()
186 else:
187 raise TypeError("invalid variant discriminant for Z2")
188 variant1: host.Z3
189 if arg4 == 0:
190 variant1 = host.Z3A(arg5)
191 elif arg4 == 1:
192 variant1 = host.Z3B()
193 else:
194 raise TypeError("invalid variant discriminant for Z3")
195 variant2: host.Z4
196 if arg6 == 0:
197 variant2 = host.Z4A(arg7)
198 elif arg6 == 1:
199 variant2 = host.Z4B()
200 else:
201 raise TypeError("invalid variant discriminant for Z4")
202 ret = import_object.host.variant_zeros((variant, variant0, variant1, variant2,))
203 (tuplei,tuplei3,tuplei4,tuplei5,) = ret
204 if isinstance(tuplei, host.Z1A):
205 payload = tuplei.value
206 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 0, 0)
207 _store(ctypes.c_uint32, self._core_memory0, caller, arg8, 4, _clamp(payload, -2147483648, 2147483647))
208 elif isinstance(tuplei, host.Z1B):
209 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 0, 1)
210 else:
211 raise TypeError("invalid variant specified for Z1")
212 if isinstance(tuplei3, host.Z2A):
213 payload7 = tuplei3.value
214 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 8, 0)
215 _store(ctypes.c_uint64, self._core_memory0, caller, arg8, 16, _clamp(payload7, -9223372036854775808, 9223372036854775807))
216 elif isinstance(tuplei3, host.Z2B):
217 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 8, 1)
218 else:
219 raise TypeError("invalid variant specified for Z2")
220 if isinstance(tuplei4, host.Z3A):
221 payload9 = tuplei4.value
222 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 24, 0)
223 _store(ctypes.c_float, self._core_memory0, caller, arg8, 28, payload9)
224 elif isinstance(tuplei4, host.Z3B):
225 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 24, 1)
226 else:
227 raise TypeError("invalid variant specified for Z3")
228 if isinstance(tuplei5, host.Z4A):
229 payload11 = tuplei5.value
230 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 32, 0)
231 _store(ctypes.c_double, self._core_memory0, caller, arg8, 40, payload11)
232 elif isinstance(tuplei5, host.Z4B):
233 _store(ctypes.c_uint8, self._core_memory0, caller, arg8, 32, 1)
234 else:
235 raise TypeError("invalid variant specified for Z4")
236 lowering4_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), wasmtime.ValType.f32(), wasmtime.ValType.i32(), wasmtime.ValType.f64(), wasmtime.ValType.i32(), ], [])
237 trampoline4 = wasmtime.Func(store, lowering4_ty, lowering4_callee, access_caller = True)
238 def lowering5_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None:
239 variant: host.AllIntegers
240 if arg0 == 0:
241 operand = arg1
242 if operand == 0:
243 boolean = False
244 elif operand == 1:
245 boolean = True
246 else:
247 raise TypeError("invalid variant discriminant for bool")
248 variant = host.AllIntegersBool(boolean)
249 elif arg0 == 1:
250 variant = host.AllIntegersU8(_clamp(arg1, 0, 255))
251 elif arg0 == 2:
252 variant = host.AllIntegersU16(_clamp(arg1, 0, 65535))
253 elif arg0 == 3:
254 variant = host.AllIntegersU32(arg1 & 0xffffffff)
255 elif arg0 == 4:
256 variant = host.AllIntegersU64(arg1 & 0xffffffffffffffff)
257 elif arg0 == 5:
258 variant = host.AllIntegersS8(_clamp(arg1, -128, 127))
259 elif arg0 == 6:
260 variant = host.AllIntegersS16(_clamp(arg1, -32768, 32767))
261 elif arg0 == 7:
262 variant = host.AllIntegersS32(arg1)
263 elif arg0 == 8:
264 variant = host.AllIntegersS64(arg1)
265 else:
266 raise TypeError("invalid variant discriminant for AllIntegers")
267 ret = import_object.host.add_one_all_integers(variant)
268 if isinstance(ret, host.AllIntegersBool):
269 payload = ret.value
270 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 0)
271 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 8, int(payload))
272 elif isinstance(ret, host.AllIntegersU8):
273 payload0 = ret.value
274 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 1)
275 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 8, _clamp(payload0, 0, 255))
276 elif isinstance(ret, host.AllIntegersU16):
277 payload1 = ret.value
278 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 2)
279 _store(ctypes.c_uint16, self._core_memory0, caller, arg2, 8, _clamp(payload1, 0, 65535))
280 elif isinstance(ret, host.AllIntegersU32):
281 payload2 = ret.value
282 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 3)
283 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 8, _clamp(payload2, 0, 4294967295))
284 elif isinstance(ret, host.AllIntegersU64):
285 payload3 = ret.value
286 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 4)
287 _store(ctypes.c_uint64, self._core_memory0, caller, arg2, 8, _clamp(payload3, 0, 18446744073709551615))
288 elif isinstance(ret, host.AllIntegersS8):
289 payload4 = ret.value
290 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 5)
291 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 8, _clamp(payload4, -128, 127))
292 elif isinstance(ret, host.AllIntegersS16):
293 payload5 = ret.value
294 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 6)
295 _store(ctypes.c_uint16, self._core_memory0, caller, arg2, 8, _clamp(payload5, -32768, 32767))
296 elif isinstance(ret, host.AllIntegersS32):
297 payload6 = ret.value
298 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 7)
299 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 8, _clamp(payload6, -2147483648, 2147483647))
300 elif isinstance(ret, host.AllIntegersS64):
301 payload7 = ret.value
302 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 8)
303 _store(ctypes.c_uint64, self._core_memory0, caller, arg2, 8, _clamp(payload7, -9223372036854775808, 9223372036854775807))
304 else:
305 raise TypeError("invalid variant specified for AllIntegers")
306 lowering5_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), ], [])
307 trampoline5 = wasmtime.Func(store, lowering5_ty, lowering5_callee, access_caller = True)
308 def lowering6_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None:
309 variant: host.AllFloats
310 if arg0 == 0:
311 variant = host.AllFloatsF32(_i32_to_f32((arg1) & 0xffffffff))
312 elif arg0 == 1:
313 variant = host.AllFloatsF64(_i64_to_f64(arg1))
314 else:
315 raise TypeError("invalid variant discriminant for AllFloats")
316 ret = import_object.host.add_one_all_floats(variant)
317 if isinstance(ret, host.AllFloatsF32):
318 payload = ret.value
319 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 0)
320 _store(ctypes.c_float, self._core_memory0, caller, arg2, 8, payload)
321 elif isinstance(ret, host.AllFloatsF64):
322 payload0 = ret.value
323 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 1)
324 _store(ctypes.c_double, self._core_memory0, caller, arg2, 8, payload0)
325 else:
326 raise TypeError("invalid variant specified for AllFloats")
327 lowering6_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i64(), wasmtime.ValType.i32(), ], [])
328 trampoline6 = wasmtime.Func(store, lowering6_ty, lowering6_callee, access_caller = True)
329 def lowering7_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None:
330 variant: host.DuplicatedS32
331 if arg0 == 0:
332 variant = host.DuplicatedS32C1(arg1)
333 elif arg0 == 1:
334 variant = host.DuplicatedS32C2(arg1)
335 elif arg0 == 2:
336 variant = host.DuplicatedS32C3(arg1)
337 else:
338 raise TypeError("invalid variant discriminant for DuplicatedS32")
339 ret = import_object.host.add_one_duplicated_s32(variant)
340 if isinstance(ret, host.DuplicatedS32C1):
341 payload = ret.value
342 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 0)
343 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, _clamp(payload, -2147483648, 2147483647))
344 elif isinstance(ret, host.DuplicatedS32C2):
345 payload0 = ret.value
346 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 1)
347 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, _clamp(payload0, -2147483648, 2147483647))
348 elif isinstance(ret, host.DuplicatedS32C3):
349 payload1 = ret.value
350 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 2)
351 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, _clamp(payload1, -2147483648, 2147483647))
352 else:
353 raise TypeError("invalid variant specified for DuplicatedS32")
354 lowering7_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], [])
355 trampoline7 = wasmtime.Func(store, lowering7_ty, lowering7_callee, access_caller = True)
356 def lowering8_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None:
357 variant: host.Distinguished
358 if arg0 == 0:
359 variant = host.DistinguishedS32(arg1)
360 elif arg0 == 1:
361 variant = host.DistinguishedFloat32(_i32_to_f32(arg1))
362 else:
363 raise TypeError("invalid variant discriminant for Distinguished")
364 ret = import_object.host.add_one_distinguished(variant)
365 if isinstance(ret, host.DistinguishedS32):
366 payload = ret.value
367 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 0)
368 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, _clamp(payload, -2147483648, 2147483647))
369 elif isinstance(ret, host.DistinguishedFloat32):
370 payload0 = ret.value
371 _store(ctypes.c_uint8, self._core_memory0, caller, arg2, 0, 1)
372 _store(ctypes.c_float, self._core_memory0, caller, arg2, 4, payload0)
373 else:
374 raise TypeError("invalid variant specified for Distinguished")
375 lowering8_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], [])
376 trampoline8 = wasmtime.Func(store, lowering8_ty, lowering8_callee, access_caller = True)
377 def lowering9_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int, arg3: int) -> None:
378 variant0: host.NestedUnion
379 if arg0 == 0:
380 variant: host.Distinguished
381 if arg1 == 0:
382 variant = host.DistinguishedS32(arg2)
383 elif arg1 == 1:
384 variant = host.DistinguishedFloat32(_i32_to_f32(arg2))
385 else:
386 raise TypeError("invalid variant discriminant for Distinguished")
387 variant0 = host.NestedUnionD(variant)
388 elif arg0 == 1:
389 variant0 = host.NestedUnionS32(arg1)
390 elif arg0 == 2:
391 variant0 = host.NestedUnionFloat32(_i32_to_f32(arg1))
392 else:
393 raise TypeError("invalid variant discriminant for NestedUnion")
394 ret = import_object.host.add_one_nested_union(variant0)
395 if isinstance(ret, host.NestedUnionD):
396 payload = ret.value
397 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 0)
398 if isinstance(payload, host.DistinguishedS32):
399 payload1 = payload.value
400 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 4, 0)
401 _store(ctypes.c_uint32, self._core_memory0, caller, arg3, 8, _clamp(payload1, -2147483648, 2147483647))
402 elif isinstance(payload, host.DistinguishedFloat32):
403 payload2 = payload.value
404 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 4, 1)
405 _store(ctypes.c_float, self._core_memory0, caller, arg3, 8, payload2)
406 else:
407 raise TypeError("invalid variant specified for Distinguished")
408 elif isinstance(ret, host.NestedUnionS32):
409 payload3 = ret.value
410 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 1)
411 _store(ctypes.c_uint32, self._core_memory0, caller, arg3, 4, _clamp(payload3, -2147483648, 2147483647))
412 elif isinstance(ret, host.NestedUnionFloat32):
413 payload4 = ret.value
414 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 2)
415 _store(ctypes.c_float, self._core_memory0, caller, arg3, 4, payload4)
416 else:
417 raise TypeError("invalid variant specified for NestedUnion")
418 lowering9_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], [])
419 trampoline9 = wasmtime.Func(store, lowering9_ty, lowering9_callee, access_caller = True)
420 def lowering10_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int, arg3: int) -> None:
421 variant: host.OptionInUnion
422 if arg0 == 0:
423 option: Optional[int]
424 if arg1 == 0:
425 option = None
426 elif arg1 == 1:
427 option = arg2
428 else:
429 raise TypeError("invalid variant discriminant for option")
430 variant = host.OptionInUnionO(option)
431 elif arg0 == 1:
432 variant = host.OptionInUnionI(arg1)
433 else:
434 raise TypeError("invalid variant discriminant for OptionInUnion")
435 ret = import_object.host.add_one_option_in_union(variant)
436 if isinstance(ret, host.OptionInUnionO):
437 payload = ret.value
438 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 0)
439 if payload is None:
440 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 4, 0)
441 else:
442 payload1 = payload
443 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 4, 1)
444 _store(ctypes.c_uint32, self._core_memory0, caller, arg3, 8, _clamp(payload1, -2147483648, 2147483647))
445 elif isinstance(ret, host.OptionInUnionI):
446 payload2 = ret.value
447 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 1)
448 _store(ctypes.c_uint32, self._core_memory0, caller, arg3, 4, _clamp(payload2, -2147483648, 2147483647))
449 else:
450 raise TypeError("invalid variant specified for OptionInUnion")
451 lowering10_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], [])
452 trampoline10 = wasmtime.Func(store, lowering10_ty, lowering10_callee, access_caller = True)
453 def lowering11_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int, arg3: int) -> None:
454 option0: Optional[Some[Optional[int]]]
455 if arg0 == 0:
456 option0 = None
457 elif arg0 == 1:
458 option: Optional[int]
459 if arg1 == 0:
460 option = None
461 elif arg1 == 1:
462 option = arg2
463 else:
464 raise TypeError("invalid variant discriminant for option")
465 option0 = Some(option)
466 else:
467 raise TypeError("invalid variant discriminant for option")
468 ret = import_object.host.add_one_option_in_option(option0)
469 if ret is None:
470 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 0)
471 else:
472 payload1 = ret.value
473 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 0, 1)
474 if payload1 is None:
475 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 4, 0)
476 else:
477 payload3 = payload1
478 _store(ctypes.c_uint8, self._core_memory0, caller, arg3, 4, 1)
479 _store(ctypes.c_uint32, self._core_memory0, caller, arg3, 8, _clamp(payload3, -2147483648, 2147483647))
480 lowering11_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], [])
481 trampoline11 = wasmtime.Func(store, lowering11_ty, lowering11_callee, access_caller = True)
482 file = importlib_resources.files() / ('root.core1.wasm')
483 if isinstance(file, pathlib.Path):
484 module = wasmtime.Module.from_file(store.engine, file)
485 else:
486 module = wasmtime.Module(store.engine, file.read_bytes())
487 instance1 = wasmtime.Instance(store, module, [
488 instance0["m"],
489 trampoline0,
490 trampoline1,
491 trampoline2,
492 trampoline3,
493 trampoline4,
494 trampoline5,
495 trampoline6,
496 trampoline7,
497 trampoline8,
498 trampoline9,
499 trampoline10,
500 trampoline11,
501 ]).exports(store)
502 lift_callee0 = instance1["r-opt"]
503 assert(isinstance(lift_callee0, wasmtime.Func))
504 self.lift_callee0 = lift_callee0
505 lift_callee1 = instance1["r-enum"]
506 assert(isinstance(lift_callee1, wasmtime.Func))
507 self.lift_callee1 = lift_callee1
508 lift_callee2 = instance1["a-nest"]
509 assert(isinstance(lift_callee2, wasmtime.Func))
510 self.lift_callee2 = lift_callee2
511 lift_callee3 = instance1["a-oinu"]
512 assert(isinstance(lift_callee3, wasmtime.Func))
513 self.lift_callee3 = lift_callee3
514 lift_callee4 = instance1["a-float"]
515 assert(isinstance(lift_callee4, wasmtime.Func))
516 self.lift_callee4 = lift_callee4
517 lift_callee5 = instance1["a-dup"]
518 assert(isinstance(lift_callee5, wasmtime.Func))
519 self.lift_callee5 = lift_callee5
520 lift_callee6 = instance1["a-dist"]
521 assert(isinstance(lift_callee6, wasmtime.Func))
522 self.lift_callee6 = lift_callee6
523 lift_callee7 = instance1["v-casts"]
524 assert(isinstance(lift_callee7, wasmtime.Func))
525 self.lift_callee7 = lift_callee7
526 lift_callee8 = instance1["v-zeros"]
527 assert(isinstance(lift_callee8, wasmtime.Func))
528 self.lift_callee8 = lift_callee8
529 lift_callee9 = instance1["a-int"]
530 assert(isinstance(lift_callee9, wasmtime.Func))
531 self.lift_callee9 = lift_callee9
532 lift_callee10 = instance1["a-oino"]
533 assert(isinstance(lift_callee10, wasmtime.Func))
534 self.lift_callee10 = lift_callee10
535 lift_callee11 = instance1["r-result"]
536 assert(isinstance(lift_callee11, wasmtime.Func))
537 self.lift_callee11 = lift_callee11
538 def e(self) -> e.E:
539 return e.E(self)