Coverage for tests/codegen/generated/lists/__init__.py: 99%

155 statements  

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

1from .imports import RootImports 

2from .intrinsics import _decode_utf8, _encode_utf8, _list_canon_lift, _list_canon_lower, _load, _store 

3import ctypes 

4import importlib_resources 

5import pathlib 

6from typing import List, cast 

7import wasmtime 

8 

9class Root: 

10 

11 def __init__(self, store: wasmtime.Store, import_object: RootImports) -> None: 

12 file = importlib_resources.files() / ('root.core0.wasm') 

13 if isinstance(file, pathlib.Path): 

14 module = wasmtime.Module.from_file(store.engine, file) 

15 else: 

16 module = wasmtime.Module(store.engine, file.read_bytes()) 

17 instance0 = wasmtime.Instance(store, module, []).exports(store) 

18 def lowering0_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None: 

19 ptr = arg0 

20 len0 = arg1 

21 list = _decode_utf8(self._core_memory0, caller, ptr, len0) 

22 ret = import_object.host.strings(list) 

23 ptr1, len2 = _encode_utf8(ret, self._realloc0, self._core_memory0, caller) 

24 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, len2) 

25 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 0, ptr1) 

26 lowering0_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], []) 

27 trampoline0 = wasmtime.Func(store, lowering0_ty, lowering0_callee, access_caller = True) 

28 core_memory0 = instance0["mem"] 

29 assert(isinstance(core_memory0, wasmtime.Memory)) 

30 self._core_memory0 = core_memory0 

31 realloc0 = instance0["realloc"] 

32 assert(isinstance(realloc0, wasmtime.Func)) 

33 self._realloc0 = realloc0 

34 def lowering1_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None: 

35 ptr = arg0 

36 len0 = arg1 

37 list = cast(bytes, _list_canon_lift(ptr, len0, 1, ctypes.c_uint8, self._core_memory0, caller)) 

38 ret = import_object.host.bytes(list) 

39 ptr1, len2 = _list_canon_lower(ret, ctypes.c_uint8, 1, 1, self._realloc0, self._core_memory0, caller) 

40 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, len2) 

41 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 0, ptr1) 

42 lowering1_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], []) 

43 trampoline1 = wasmtime.Func(store, lowering1_ty, lowering1_callee, access_caller = True) 

44 def lowering2_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None: 

45 ptr = arg0 

46 len0 = arg1 

47 list = cast(List[int], _list_canon_lift(ptr, len0, 4, ctypes.c_uint32, self._core_memory0, caller)) 

48 ret = import_object.host.ints(list) 

49 ptr1, len2 = _list_canon_lower(ret, ctypes.c_uint32, 4, 4, self._realloc0, self._core_memory0, caller) 

50 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, len2) 

51 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 0, ptr1) 

52 lowering2_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], []) 

53 trampoline2 = wasmtime.Func(store, lowering2_ty, lowering2_callee, access_caller = True) 

54 def lowering3_callee(caller: wasmtime.Caller, arg0: int, arg1: int, arg2: int) -> None: 

55 ptr3 = arg0 

56 len4 = arg1 

57 result: List[str] = [] 

58 for i5 in range(0, len4): 

59 base0 = ptr3 + i5 * 8 

60 load = _load(ctypes.c_int32, self._core_memory0, caller, base0, 0) 

61 load1 = _load(ctypes.c_int32, self._core_memory0, caller, base0, 4) 

62 ptr = load 

63 len2 = load1 

64 list = _decode_utf8(self._core_memory0, caller, ptr, len2) 

65 result.append(list) 

66 ret = import_object.host.string_list(result) 

67 vec = ret 

68 len10 = len(vec) 

69 result9 = self._realloc0(caller, 0, 0, 4, len10 * 8) 

70 assert(isinstance(result9, int)) 

71 for i11 in range(0, len10): 

72 e = vec[i11] 

73 base6 = result9 + i11 * 8 

74 ptr7, len8 = _encode_utf8(e, self._realloc0, self._core_memory0, caller) 

75 _store(ctypes.c_uint32, self._core_memory0, caller, base6, 4, len8) 

76 _store(ctypes.c_uint32, self._core_memory0, caller, base6, 0, ptr7) 

77 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 4, len10) 

78 _store(ctypes.c_uint32, self._core_memory0, caller, arg2, 0, result9) 

79 lowering3_ty = wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), ], []) 

80 trampoline3 = wasmtime.Func(store, lowering3_ty, lowering3_callee, access_caller = True) 

81 file = importlib_resources.files() / ('root.core1.wasm') 

82 if isinstance(file, pathlib.Path): 

83 module = wasmtime.Module.from_file(store.engine, file) 

84 else: 

85 module = wasmtime.Module(store.engine, file.read_bytes()) 

86 instance1 = wasmtime.Instance(store, module, [ 

87 instance0["mem"], 

88 trampoline0, 

89 trampoline1, 

90 trampoline2, 

91 trampoline3, 

92 ]).exports(store) 

93 lift_callee0 = instance1["strings"] 

94 assert(isinstance(lift_callee0, wasmtime.Func)) 

95 self.lift_callee0 = lift_callee0 

96 lift_callee1 = instance1["bytes"] 

97 assert(isinstance(lift_callee1, wasmtime.Func)) 

98 self.lift_callee1 = lift_callee1 

99 lift_callee2 = instance1["ints"] 

100 assert(isinstance(lift_callee2, wasmtime.Func)) 

101 self.lift_callee2 = lift_callee2 

102 lift_callee3 = instance1["string-list"] 

103 assert(isinstance(lift_callee3, wasmtime.Func)) 

104 self.lift_callee3 = lift_callee3 

105 def strings(self, caller: wasmtime.Store, a: str) -> str: 

106 ptr, len0 = _encode_utf8(a, self._realloc0, self._core_memory0, caller) 

107 ret = self.lift_callee0(caller, ptr, len0) 

108 assert(isinstance(ret, int)) 

109 load = _load(ctypes.c_int32, self._core_memory0, caller, ret, 0) 

110 load1 = _load(ctypes.c_int32, self._core_memory0, caller, ret, 4) 

111 ptr2 = load 

112 len3 = load1 

113 list = _decode_utf8(self._core_memory0, caller, ptr2, len3) 

114 tmp = list 

115 return tmp 

116 def bytes(self, caller: wasmtime.Store, a: bytes) -> bytes: 

117 ptr, len0 = _list_canon_lower(a, ctypes.c_uint8, 1, 1, self._realloc0, self._core_memory0, caller) 

118 ret = self.lift_callee1(caller, ptr, len0) 

119 assert(isinstance(ret, int)) 

120 load = _load(ctypes.c_int32, self._core_memory0, caller, ret, 0) 

121 load1 = _load(ctypes.c_int32, self._core_memory0, caller, ret, 4) 

122 ptr2 = load 

123 len3 = load1 

124 list = cast(bytes, _list_canon_lift(ptr2, len3, 1, ctypes.c_uint8, self._core_memory0, caller)) 

125 tmp = list 

126 return tmp 

127 def ints(self, caller: wasmtime.Store, a: List[int]) -> List[int]: 

128 ptr, len0 = _list_canon_lower(a, ctypes.c_uint32, 4, 4, self._realloc0, self._core_memory0, caller) 

129 ret = self.lift_callee2(caller, ptr, len0) 

130 assert(isinstance(ret, int)) 

131 load = _load(ctypes.c_int32, self._core_memory0, caller, ret, 0) 

132 load1 = _load(ctypes.c_int32, self._core_memory0, caller, ret, 4) 

133 ptr2 = load 

134 len3 = load1 

135 list = cast(List[int], _list_canon_lift(ptr2, len3, 4, ctypes.c_uint32, self._core_memory0, caller)) 

136 tmp = list 

137 return tmp 

138 def string_list(self, caller: wasmtime.Store, a: List[str]) -> List[str]: 

139 vec = a 

140 len2 = len(vec) 

141 result = self._realloc0(caller, 0, 0, 4, len2 * 8) 

142 assert(isinstance(result, int)) 

143 for i3 in range(0, len2): 

144 e = vec[i3] 

145 base0 = result + i3 * 8 

146 ptr, len1 = _encode_utf8(e, self._realloc0, self._core_memory0, caller) 

147 _store(ctypes.c_uint32, self._core_memory0, caller, base0, 4, len1) 

148 _store(ctypes.c_uint32, self._core_memory0, caller, base0, 0, ptr) 

149 ret = self.lift_callee3(caller, result, len2) 

150 assert(isinstance(ret, int)) 

151 load = _load(ctypes.c_int32, self._core_memory0, caller, ret, 0) 

152 load4 = _load(ctypes.c_int32, self._core_memory0, caller, ret, 4) 

153 ptr10 = load 

154 len11 = load4 

155 result12: List[str] = [] 

156 for i13 in range(0, len11): 

157 base5 = ptr10 + i13 * 8 

158 load6 = _load(ctypes.c_int32, self._core_memory0, caller, base5, 0) 

159 load7 = _load(ctypes.c_int32, self._core_memory0, caller, base5, 4) 

160 ptr8 = load6 

161 len9 = load7 

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

163 result12.append(list) 

164 tmp = result12 

165 return tmp