github.com/taubyte/vm-wasm-utils@v1.0.2/callBridge/methods.go (about) 1 package callbridge 2 3 import ( 4 "context" 5 6 "github.com/taubyte/go-interfaces/vm" 7 ) 8 9 func (c *callContext) Name() string { 10 return c.wazero.Name() 11 } 12 13 func (c *callContext) Close(ctx context.Context) error { 14 return c.wazero.Close(ctx) 15 } 16 17 func (c *callContext) CloseWithExitCode(exitCode uint32) error { 18 return c.wazero.CloseWithExitCode(context.TODO(), exitCode) 19 } 20 21 func (c *callContext) Memory() vm.Memory { 22 return &memory{wazero: c.wazero.Memory()} 23 } 24 25 func (c *callContext) ExportedFunction(name string) vm.Function { 26 return &importedFn{wazero: c.wazero.ExportedFunction(name)} 27 } 28 29 func (c *callContext) ExportedMemory(name string) vm.Memory { 30 return &memory{wazero: c.wazero.ExportedMemory(name)} 31 } 32 33 func (c *callContext) ExportedGlobal(name string) vm.Global { 34 return &global{wazero: c.wazero.ExportedGlobal(name)} 35 } 36 37 func (m *memory) Size() uint32 { 38 return m.wazero.Size() 39 } 40 41 func (m *memory) Grow(deltaPages uint32) (previousPages uint32, ok bool) { 42 return m.wazero.Grow(deltaPages) 43 } 44 45 func (m *memory) ReadByte(offset uint32) (byte, bool) { 46 return m.wazero.ReadByte(offset) 47 } 48 49 func (m *memory) ReadUint16Le(offset uint32) (uint16, bool) { 50 return m.wazero.ReadUint16Le(offset) 51 } 52 53 func (m *memory) ReadUint32Le(offset uint32) (uint32, bool) { 54 return m.wazero.ReadUint32Le(offset) 55 } 56 57 func (m *memory) ReadFloat32Le(offset uint32) (float32, bool) { 58 return m.wazero.ReadFloat32Le(offset) 59 } 60 61 func (m *memory) ReadUint64Le(offset uint32) (uint64, bool) { 62 return m.wazero.ReadUint64Le(offset) 63 } 64 65 func (m *memory) ReadFloat64Le(offset uint32) (float64, bool) { 66 return m.wazero.ReadFloat64Le(offset) 67 } 68 69 func (m *memory) Read(offset, byteCount uint32) ([]byte, bool) { 70 return m.wazero.Read(offset, byteCount) 71 } 72 73 func (m *memory) ReadString(offset, byteCount uint32) (string, bool) { 74 v, ok := m.wazero.Read(offset, byteCount) 75 if !ok { 76 return "", false 77 } 78 return string(v), true 79 } 80 81 func (m *memory) WriteByte(offset uint32, v byte) bool { 82 return m.wazero.WriteByte(offset, v) 83 } 84 85 func (m *memory) WriteUint16Le(offset uint32, v uint16) bool { 86 return m.wazero.WriteUint16Le(offset, v) 87 } 88 89 func (m *memory) WriteUint32Le(offset, v uint32) bool { 90 return m.wazero.WriteUint32Le(offset, v) 91 } 92 93 func (m *memory) WriteFloat32Le(offset uint32, v float32) bool { 94 return m.wazero.WriteFloat32Le(offset, v) 95 } 96 97 func (m *memory) WriteUint64Le(offset uint32, v uint64) bool { 98 return m.wazero.WriteUint64Le(offset, v) 99 } 100 101 func (m *memory) WriteFloat64Le(offset uint32, v float64) bool { 102 return m.wazero.WriteFloat64Le(offset, v) 103 } 104 105 func (m *memory) Write(offset uint32, v []byte) bool { 106 return m.wazero.Write(offset, v) 107 } 108 109 func (f *importedFn) Definition() vm.FunctionDefinition { 110 return &importedFnDef{f.wazero.Definition()} 111 } 112 113 func (f *importedFn) Call(ctx context.Context, params ...uint64) ([]uint64, error) { 114 return f.wazero.Call(ctx, params...) 115 } 116 117 func (f *importedFnDef) Name() string { 118 return f.wazero.Name() 119 } 120 121 func (f *importedFnDef) ParamTypes() []vm.ValueType { 122 _vt := f.wazero.ParamTypes() 123 count := len(_vt) 124 vt := make([]vm.ValueType, count) 125 for i := 0; i < count; i++ { 126 vt[i] = vm.ValueType(_vt[i]) 127 } 128 return vt 129 } 130 131 func (f *importedFnDef) ResultTypes() []vm.ValueType { 132 _vt := f.wazero.ResultTypes() 133 count := len(_vt) 134 vt := make([]vm.ValueType, count) 135 for i := 0; i < count; i++ { 136 vt[i] = vm.ValueType(_vt[i]) 137 } 138 return vt 139 } 140 141 func (f *importedFnDef) ParamNames() []string { 142 return f.wazero.ParamNames() 143 } 144 145 func (g *global) Type() vm.ValueType { 146 return vm.ValueType(g.wazero.Type()) 147 } 148 149 func (g *global) Get() uint64 { 150 return g.wazero.Get() 151 } 152 153 func (g *global) String() string { 154 return g.wazero.String() 155 }