Coverage for tests/codegen/generated/external_types/exports/e.py: 70%

53 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-20 16:25 +0000

1from ..intrinsics import _decode_utf8, _encode_utf8, _load 

2import ctypes 

3from dataclasses import dataclass 

4from typing import Union 

5import wasmtime 

6 

7from typing import TYPE_CHECKING 

8if TYPE_CHECKING: 

9 from .. import Root 

10 

11@dataclass 

12class RuntimeValueId: 

13 value: str 

14 

15@dataclass 

16class RuntimeValueId2: 

17 value: str 

18 

19RuntimeValue = Union[RuntimeValueId, RuntimeValueId2] 

20 

21class E: 

22 component: 'Root' 

23 

24 def __init__(self, component: 'Root') -> None: 

25 self.component = component 

26 def some_fn(self, caller: wasmtime.Store, a: RuntimeValue) -> RuntimeValue: 

27 if isinstance(a, RuntimeValueId): 

28 payload = a.value 

29 ptr, len0 = _encode_utf8(payload, self.component._realloc0, self.component._core_memory0, caller) 

30 variant = 0 

31 variant4 = ptr 

32 variant5 = len0 

33 elif isinstance(a, RuntimeValueId2): 

34 payload1 = a.value 

35 ptr2, len3 = _encode_utf8(payload1, self.component._realloc0, self.component._core_memory0, caller) 

36 variant = 1 

37 variant4 = ptr2 

38 variant5 = len3 

39 else: 

40 raise TypeError("invalid variant specified for RuntimeValue") 

41 ret = self.component.lift_callee0(caller, variant, variant4, variant5) 

42 assert(isinstance(ret, int)) 

43 load = _load(ctypes.c_uint8, self.component._core_memory0, caller, ret, 0) 

44 variant15: RuntimeValue 

45 if load == 0: 

46 load6 = _load(ctypes.c_int32, self.component._core_memory0, caller, ret, 4) 

47 load7 = _load(ctypes.c_int32, self.component._core_memory0, caller, ret, 8) 

48 ptr8 = load6 

49 len9 = load7 

50 list = _decode_utf8(self.component._core_memory0, caller, ptr8, len9) 

51 variant15 = RuntimeValueId(list) 

52 elif load == 1: 

53 load10 = _load(ctypes.c_int32, self.component._core_memory0, caller, ret, 4) 

54 load11 = _load(ctypes.c_int32, self.component._core_memory0, caller, ret, 8) 

55 ptr12 = load10 

56 len13 = load11 

57 list14 = _decode_utf8(self.component._core_memory0, caller, ptr12, len13) 

58 variant15 = RuntimeValueId2(list14) 

59 else: 

60 raise TypeError("invalid variant discriminant for RuntimeValue") 

61 tmp = variant15 

62 return tmp 

63