Coverage for tests/codegen/generated/export_resources/__init__.py: 74%

57 statements  

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

1from .exports import my_interface_name 

2import importlib_resources 

3import pathlib 

4from typing import List, Optional, Tuple 

5import wasmtime 

6 

7class Root: 

8 

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

10 _handle_table_0: List[Optional[Tuple[int, bool]]] = [] 

11 _handle_table_free0: List[int] = [] 

12 

13 def _handle_add_0(entry): 

14 if _handle_table_free0: 

15 idx = _handle_table_free0.pop() 

16 _handle_table_0[idx] = entry 

17 return idx 

18 else: 

19 _handle_table_0.append(entry) 

20 return len(_handle_table_0) - 1 

21 self._handle_add_0 = _handle_add_0 

22 def _handle_remove_0(i): 

23 entry = _handle_table_0[i] 

24 _handle_table_0[i] = None 

25 _handle_table_free0.append(i) 

26 return entry 

27 self._handle_remove_0 = _handle_remove_0 

28 

29 def _handle_get_0(i): 

30 return _handle_table_0[i] 

31 self._handle_get_0 = _handle_get_0 

32 def _resource_drop_0(rep): 

33 _handle_remove_0(rep) 

34 _resource_drop_0_ty = wasmtime.FuncType([wasmtime.ValType.i32()], []) 

35 trampoline0 = wasmtime.Func(store, _resource_drop_0_ty, _resource_drop_0) 

36 def _resource_new_0(rep): 

37 return _handle_add_0((rep, True)) 

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

39 trampoline1 = wasmtime.Func(store, _resource_new_0_ty, _resource_new_0) 

40 def _resource_rep_0(handle): 

41 return _handle_get_0(handle)[0] 

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

43 trampoline2 = wasmtime.Func(store, _resource_rep_0_ty, _resource_rep_0) 

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

45 if isinstance(file, pathlib.Path): 

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

47 else: 

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

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

50 trampoline0, 

51 trampoline1, 

52 trampoline2, 

53 ]).exports(store) 

54 core_memory0 = instance0["memory"] 

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

56 self._core_memory0 = core_memory0 

57 realloc0 = instance0["cabi_realloc"] 

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

59 self._realloc0 = realloc0 

60 lift_callee0 = instance0["component:basicresource/my-interface-name#[constructor]demo-resource-class"] 

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

62 self.lift_callee0 = lift_callee0 

63 lift_callee1 = instance0["component:basicresource/my-interface-name#[method]demo-resource-class.greet"] 

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

65 self.lift_callee1 = lift_callee1 

66 def my_interface_name(self) -> my_interface_name.MyInterfaceName: 

67 return my_interface_name.MyInterfaceName(self)