Coverage for tests/codegen/generated/scalars/__init__.py: 98%

168 statements  

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

1from .imports import RootImports 

2from .intrinsics import _clamp, _validate_guest_char 

3import importlib_resources 

4import pathlib 

5import wasmtime 

6 

7class Root: 

8 

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

10 def lowering0_callee(caller: wasmtime.Caller, arg0: int) -> int: 

11 ret = import_object.host.roundtrip_u8(_clamp(arg0, 0, 255)) 

12 return _clamp(ret, 0, 255) 

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

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

15 def lowering1_callee(caller: wasmtime.Caller, arg0: int) -> int: 

16 ret = import_object.host.roundtrip_s8(_clamp(arg0, -128, 127)) 

17 return _clamp(ret, -128, 127) 

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

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

20 def lowering2_callee(caller: wasmtime.Caller, arg0: int) -> int: 

21 ret = import_object.host.roundtrip_u16(_clamp(arg0, 0, 65535)) 

22 return _clamp(ret, 0, 65535) 

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

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

25 def lowering3_callee(caller: wasmtime.Caller, arg0: int) -> int: 

26 ret = import_object.host.roundtrip_s16(_clamp(arg0, -32768, 32767)) 

27 return _clamp(ret, -32768, 32767) 

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

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

30 def lowering4_callee(caller: wasmtime.Caller, arg0: int) -> int: 

31 ret = import_object.host.roundtrip_u32(arg0 & 0xffffffff) 

32 return _clamp(ret, 0, 4294967295) 

33 lowering4_ty = wasmtime.FuncType([wasmtime.ValType.i32(), ], [wasmtime.ValType.i32(), ]) 

34 trampoline4 = wasmtime.Func(store, lowering4_ty, lowering4_callee, access_caller = True) 

35 def lowering5_callee(caller: wasmtime.Caller, arg0: int) -> int: 

36 ret = import_object.host.roundtrip_s32(arg0) 

37 return _clamp(ret, -2147483648, 2147483647) 

38 lowering5_ty = wasmtime.FuncType([wasmtime.ValType.i32(), ], [wasmtime.ValType.i32(), ]) 

39 trampoline5 = wasmtime.Func(store, lowering5_ty, lowering5_callee, access_caller = True) 

40 def lowering6_callee(caller: wasmtime.Caller, arg0: int) -> int: 

41 ret = import_object.host.roundtrip_u64(arg0 & 0xffffffffffffffff) 

42 return _clamp(ret, 0, 18446744073709551615) 

43 lowering6_ty = wasmtime.FuncType([wasmtime.ValType.i64(), ], [wasmtime.ValType.i64(), ]) 

44 trampoline6 = wasmtime.Func(store, lowering6_ty, lowering6_callee, access_caller = True) 

45 def lowering7_callee(caller: wasmtime.Caller, arg0: int) -> int: 

46 ret = import_object.host.roundtrip_s64(arg0) 

47 return _clamp(ret, -9223372036854775808, 9223372036854775807) 

48 lowering7_ty = wasmtime.FuncType([wasmtime.ValType.i64(), ], [wasmtime.ValType.i64(), ]) 

49 trampoline7 = wasmtime.Func(store, lowering7_ty, lowering7_callee, access_caller = True) 

50 def lowering8_callee(caller: wasmtime.Caller, arg0: float) -> float: 

51 ret = import_object.host.roundtrip_float32(arg0) 

52 return ret 

53 lowering8_ty = wasmtime.FuncType([wasmtime.ValType.f32(), ], [wasmtime.ValType.f32(), ]) 

54 trampoline8 = wasmtime.Func(store, lowering8_ty, lowering8_callee, access_caller = True) 

55 def lowering9_callee(caller: wasmtime.Caller, arg0: float) -> float: 

56 ret = import_object.host.roundtrip_float64(arg0) 

57 return ret 

58 lowering9_ty = wasmtime.FuncType([wasmtime.ValType.f64(), ], [wasmtime.ValType.f64(), ]) 

59 trampoline9 = wasmtime.Func(store, lowering9_ty, lowering9_callee, access_caller = True) 

60 def lowering10_callee(caller: wasmtime.Caller, arg0: int) -> int: 

61 ret = import_object.host.roundtrip_char(_validate_guest_char(arg0)) 

62 return ord(ret) 

63 lowering10_ty = wasmtime.FuncType([wasmtime.ValType.i32(), ], [wasmtime.ValType.i32(), ]) 

64 trampoline10 = wasmtime.Func(store, lowering10_ty, lowering10_callee, access_caller = True) 

65 def lowering11_callee(caller: wasmtime.Caller, arg0: int) -> int: 

66 operand = arg0 

67 if operand == 0: 

68 boolean = False 

69 elif operand == 1: 

70 boolean = True 

71 else: 

72 raise TypeError("invalid variant discriminant for bool") 

73 ret = import_object.host.roundtrip_bool(boolean) 

74 return int(ret) 

75 lowering11_ty = wasmtime.FuncType([wasmtime.ValType.i32(), ], [wasmtime.ValType.i32(), ]) 

76 trampoline11 = wasmtime.Func(store, lowering11_ty, lowering11_callee, access_caller = True) 

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

78 if isinstance(file, pathlib.Path): 

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

80 else: 

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

82 instance0 = wasmtime.Instance(store, module, [ 

83 trampoline0, 

84 trampoline1, 

85 trampoline2, 

86 trampoline3, 

87 trampoline4, 

88 trampoline5, 

89 trampoline6, 

90 trampoline7, 

91 trampoline8, 

92 trampoline9, 

93 trampoline10, 

94 trampoline11, 

95 ]).exports(store) 

96 lift_callee0 = instance0["roundtrip-u8"] 

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

98 self.lift_callee0 = lift_callee0 

99 lift_callee1 = instance0["roundtrip-s8"] 

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

101 self.lift_callee1 = lift_callee1 

102 lift_callee2 = instance0["roundtrip-u16"] 

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

104 self.lift_callee2 = lift_callee2 

105 lift_callee3 = instance0["roundtrip-s16"] 

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

107 self.lift_callee3 = lift_callee3 

108 lift_callee4 = instance0["roundtrip-u32"] 

109 assert(isinstance(lift_callee4, wasmtime.Func)) 

110 self.lift_callee4 = lift_callee4 

111 lift_callee5 = instance0["roundtrip-s32"] 

112 assert(isinstance(lift_callee5, wasmtime.Func)) 

113 self.lift_callee5 = lift_callee5 

114 lift_callee6 = instance0["roundtrip-u64"] 

115 assert(isinstance(lift_callee6, wasmtime.Func)) 

116 self.lift_callee6 = lift_callee6 

117 lift_callee7 = instance0["roundtrip-s64"] 

118 assert(isinstance(lift_callee7, wasmtime.Func)) 

119 self.lift_callee7 = lift_callee7 

120 lift_callee8 = instance0["roundtrip-float32"] 

121 assert(isinstance(lift_callee8, wasmtime.Func)) 

122 self.lift_callee8 = lift_callee8 

123 lift_callee9 = instance0["roundtrip-float64"] 

124 assert(isinstance(lift_callee9, wasmtime.Func)) 

125 self.lift_callee9 = lift_callee9 

126 lift_callee10 = instance0["roundtrip-char"] 

127 assert(isinstance(lift_callee10, wasmtime.Func)) 

128 self.lift_callee10 = lift_callee10 

129 lift_callee11 = instance0["roundtrip-bool"] 

130 assert(isinstance(lift_callee11, wasmtime.Func)) 

131 self.lift_callee11 = lift_callee11 

132 def roundtrip_u8(self, caller: wasmtime.Store, a: int) -> int: 

133 ret = self.lift_callee0(caller, _clamp(a, 0, 255)) 

134 assert(isinstance(ret, int)) 

135 return _clamp(ret, 0, 255) 

136 def roundtrip_s8(self, caller: wasmtime.Store, a: int) -> int: 

137 ret = self.lift_callee1(caller, _clamp(a, -128, 127)) 

138 assert(isinstance(ret, int)) 

139 return _clamp(ret, -128, 127) 

140 def roundtrip_u16(self, caller: wasmtime.Store, a: int) -> int: 

141 ret = self.lift_callee2(caller, _clamp(a, 0, 65535)) 

142 assert(isinstance(ret, int)) 

143 return _clamp(ret, 0, 65535) 

144 def roundtrip_s16(self, caller: wasmtime.Store, a: int) -> int: 

145 ret = self.lift_callee3(caller, _clamp(a, -32768, 32767)) 

146 assert(isinstance(ret, int)) 

147 return _clamp(ret, -32768, 32767) 

148 def roundtrip_u32(self, caller: wasmtime.Store, a: int) -> int: 

149 ret = self.lift_callee4(caller, _clamp(a, 0, 4294967295)) 

150 assert(isinstance(ret, int)) 

151 return ret & 0xffffffff 

152 def roundtrip_s32(self, caller: wasmtime.Store, a: int) -> int: 

153 ret = self.lift_callee5(caller, _clamp(a, -2147483648, 2147483647)) 

154 assert(isinstance(ret, int)) 

155 return ret 

156 def roundtrip_u64(self, caller: wasmtime.Store, a: int) -> int: 

157 ret = self.lift_callee6(caller, _clamp(a, 0, 18446744073709551615)) 

158 assert(isinstance(ret, int)) 

159 return ret & 0xffffffffffffffff 

160 def roundtrip_s64(self, caller: wasmtime.Store, a: int) -> int: 

161 ret = self.lift_callee7(caller, _clamp(a, -9223372036854775808, 9223372036854775807)) 

162 assert(isinstance(ret, int)) 

163 return ret 

164 def roundtrip_float32(self, caller: wasmtime.Store, a: float) -> float: 

165 ret = self.lift_callee8(caller, a) 

166 assert(isinstance(ret, float)) 

167 return ret 

168 def roundtrip_float64(self, caller: wasmtime.Store, a: float) -> float: 

169 ret = self.lift_callee9(caller, a) 

170 assert(isinstance(ret, float)) 

171 return ret 

172 def roundtrip_char(self, caller: wasmtime.Store, a: str) -> str: 

173 ret = self.lift_callee10(caller, ord(a)) 

174 assert(isinstance(ret, int)) 

175 return _validate_guest_char(ret) 

176 def roundtrip_bool(self, caller: wasmtime.Store, a: bool) -> bool: 

177 ret = self.lift_callee11(caller, int(a)) 

178 assert(isinstance(ret, int)) 

179 operand = ret 

180 if operand == 0: 

181 boolean = False 

182 elif operand == 1: 

183 boolean = True 

184 else: 

185 raise TypeError("invalid variant discriminant for bool") 

186 return boolean