github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/internal/util/func.go (about) 1 package util 2 3 import ( 4 "context" 5 6 "github.com/tetratelabs/wazero" 7 "github.com/tetratelabs/wazero/api" 8 ) 9 10 type i32 interface{ ~int32 | ~uint32 } 11 type i64 interface{ ~int64 | ~uint64 } 12 13 type funcVI[T0 i32] func(context.Context, api.Module, T0) 14 15 func (fn funcVI[T0]) Call(ctx context.Context, mod api.Module, stack []uint64) { 16 fn(ctx, mod, T0(stack[0])) 17 } 18 19 func ExportFuncVI[T0 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0)) { 20 mod.NewFunctionBuilder(). 21 WithGoModuleFunction(funcVI[T0](fn), 22 []api.ValueType{api.ValueTypeI32}, nil). 23 Export(name) 24 } 25 26 type funcVII[T0, T1 i32] func(context.Context, api.Module, T0, T1) 27 28 func (fn funcVII[T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) { 29 fn(ctx, mod, T0(stack[0]), T1(stack[1])) 30 } 31 32 func ExportFuncVII[T0, T1 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1)) { 33 mod.NewFunctionBuilder(). 34 WithGoModuleFunction(funcVII[T0, T1](fn), 35 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, nil). 36 Export(name) 37 } 38 39 type funcVIII[T0, T1, T2 i32] func(context.Context, api.Module, T0, T1, T2) 40 41 func (fn funcVIII[T0, T1, T2]) Call(ctx context.Context, mod api.Module, stack []uint64) { 42 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2])) 43 } 44 45 func ExportFuncVIII[T0, T1, T2 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2)) { 46 mod.NewFunctionBuilder(). 47 WithGoModuleFunction(funcVIII[T0, T1, T2](fn), 48 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, nil). 49 Export(name) 50 } 51 52 type funcVIIII[T0, T1, T2, T3 i32] func(context.Context, api.Module, T0, T1, T2, T3) 53 54 func (fn funcVIIII[T0, T1, T2, T3]) Call(ctx context.Context, mod api.Module, stack []uint64) { 55 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3])) 56 } 57 58 func ExportFuncVIIII[T0, T1, T2, T3 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3)) { 59 mod.NewFunctionBuilder(). 60 WithGoModuleFunction(funcVIIII[T0, T1, T2, T3](fn), 61 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, nil). 62 Export(name) 63 } 64 65 type funcVIIIII[T0, T1, T2, T3, T4 i32] func(context.Context, api.Module, T0, T1, T2, T3, T4) 66 67 func (fn funcVIIIII[T0, T1, T2, T3, T4]) Call(ctx context.Context, mod api.Module, stack []uint64) { 68 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4])) 69 } 70 71 func ExportFuncVIIIII[T0, T1, T2, T3, T4 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4)) { 72 mod.NewFunctionBuilder(). 73 WithGoModuleFunction(funcVIIIII[T0, T1, T2, T3, T4](fn), 74 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, nil). 75 Export(name) 76 } 77 78 type funcVIIIIJ[T0, T1, T2, T3 i32, T4 i64] func(context.Context, api.Module, T0, T1, T2, T3, T4) 79 80 func (fn funcVIIIIJ[T0, T1, T2, T3, T4]) Call(ctx context.Context, mod api.Module, stack []uint64) { 81 fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4])) 82 } 83 84 func ExportFuncVIIIIJ[T0, T1, T2, T3 i32, T4 i64](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4)) { 85 mod.NewFunctionBuilder(). 86 WithGoModuleFunction(funcVIIIIJ[T0, T1, T2, T3, T4](fn), 87 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI64}, nil). 88 Export(name) 89 } 90 91 type funcII[TR, T0 i32] func(context.Context, api.Module, T0) TR 92 93 func (fn funcII[TR, T0]) Call(ctx context.Context, mod api.Module, stack []uint64) { 94 stack[0] = uint64(fn(ctx, mod, T0(stack[0]))) 95 } 96 97 func ExportFuncII[TR, T0 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0) TR) { 98 mod.NewFunctionBuilder(). 99 WithGoModuleFunction(funcII[TR, T0](fn), 100 []api.ValueType{api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}). 101 Export(name) 102 } 103 104 type funcIII[TR, T0, T1 i32] func(context.Context, api.Module, T0, T1) TR 105 106 func (fn funcIII[TR, T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) { 107 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]))) 108 } 109 110 func ExportFuncIII[TR, T0, T1 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1) TR) { 111 mod.NewFunctionBuilder(). 112 WithGoModuleFunction(funcIII[TR, T0, T1](fn), 113 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}). 114 Export(name) 115 } 116 117 type funcIIII[TR, T0, T1, T2 i32] func(context.Context, api.Module, T0, T1, T2) TR 118 119 func (fn funcIIII[TR, T0, T1, T2]) Call(ctx context.Context, mod api.Module, stack []uint64) { 120 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]))) 121 } 122 123 func ExportFuncIIII[TR, T0, T1, T2 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2) TR) { 124 mod.NewFunctionBuilder(). 125 WithGoModuleFunction(funcIIII[TR, T0, T1, T2](fn), 126 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}). 127 Export(name) 128 } 129 130 type funcIIIII[TR, T0, T1, T2, T3 i32] func(context.Context, api.Module, T0, T1, T2, T3) TR 131 132 func (fn funcIIIII[TR, T0, T1, T2, T3]) Call(ctx context.Context, mod api.Module, stack []uint64) { 133 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]))) 134 } 135 136 func ExportFuncIIIII[TR, T0, T1, T2, T3 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3) TR) { 137 mod.NewFunctionBuilder(). 138 WithGoModuleFunction(funcIIIII[TR, T0, T1, T2, T3](fn), 139 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}). 140 Export(name) 141 } 142 143 type funcIIIIII[TR, T0, T1, T2, T3, T4 i32] func(context.Context, api.Module, T0, T1, T2, T3, T4) TR 144 145 func (fn funcIIIIII[TR, T0, T1, T2, T3, T4]) Call(ctx context.Context, mod api.Module, stack []uint64) { 146 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4]))) 147 } 148 149 func ExportFuncIIIIII[TR, T0, T1, T2, T3, T4 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4) TR) { 150 mod.NewFunctionBuilder(). 151 WithGoModuleFunction(funcIIIIII[TR, T0, T1, T2, T3, T4](fn), 152 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}). 153 Export(name) 154 } 155 156 type funcIIIIIII[TR, T0, T1, T2, T3, T4, T5 i32] func(context.Context, api.Module, T0, T1, T2, T3, T4, T5) TR 157 158 func (fn funcIIIIIII[TR, T0, T1, T2, T3, T4, T5]) Call(ctx context.Context, mod api.Module, stack []uint64) { 159 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]), T4(stack[4]), T5(stack[5]))) 160 } 161 162 func ExportFuncIIIIIII[TR, T0, T1, T2, T3, T4, T5 i32](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3, T4, T5) TR) { 163 mod.NewFunctionBuilder(). 164 WithGoModuleFunction(funcIIIIIII[TR, T0, T1, T2, T3, T4, T5](fn), 165 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32}). 166 Export(name) 167 } 168 169 type funcIIIIJ[TR, T0, T1, T2 i32, T3 i64] func(context.Context, api.Module, T0, T1, T2, T3) TR 170 171 func (fn funcIIIIJ[TR, T0, T1, T2, T3]) Call(ctx context.Context, mod api.Module, stack []uint64) { 172 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]), T2(stack[2]), T3(stack[3]))) 173 } 174 175 func ExportFuncIIIIJ[TR, T0, T1, T2 i32, T3 i64](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1, T2, T3) TR) { 176 mod.NewFunctionBuilder(). 177 WithGoModuleFunction(funcIIIIJ[TR, T0, T1, T2, T3](fn), 178 []api.ValueType{api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI32, api.ValueTypeI64}, []api.ValueType{api.ValueTypeI32}). 179 Export(name) 180 } 181 182 type funcIIJ[TR, T0 i32, T1 i64] func(context.Context, api.Module, T0, T1) TR 183 184 func (fn funcIIJ[TR, T0, T1]) Call(ctx context.Context, mod api.Module, stack []uint64) { 185 stack[0] = uint64(fn(ctx, mod, T0(stack[0]), T1(stack[1]))) 186 } 187 188 func ExportFuncIIJ[TR, T0 i32, T1 i64](mod wazero.HostModuleBuilder, name string, fn func(context.Context, api.Module, T0, T1) TR) { 189 mod.NewFunctionBuilder(). 190 WithGoModuleFunction(funcIIJ[TR, T0, T1](fn), 191 []api.ValueType{api.ValueTypeI32, api.ValueTypeI64}, []api.ValueType{api.ValueTypeI32}). 192 Export(name) 193 }