From f1f9b8307f29cb71fd2fff11bb82edc6a41e7b98 Mon Sep 17 00:00:00 2001 From: Eric Tu <6364934+ec2@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:37:45 -0400 Subject: [PATCH] feat(lib/runtime): remove runtime type reflection in host module function definitions (with Generics) (#3962) Co-authored-by: EclesioMeloJunior --- lib/runtime/wazero/imports.go | 6 +- lib/runtime/wazero/instance.go | 638 ++++++++++++++++----------------- lib/runtime/wazero/types.go | 100 ++++++ 3 files changed, 419 insertions(+), 325 deletions(-) create mode 100644 lib/runtime/wazero/types.go diff --git a/lib/runtime/wazero/imports.go b/lib/runtime/wazero/imports.go index 549a241197..71ef19928a 100644 --- a/lib/runtime/wazero/imports.go +++ b/lib/runtime/wazero/imports.go @@ -775,12 +775,12 @@ func ext_crypto_sr25519_verify_version_2(ctx context.Context, m api.Module, sig return 1 } -func ext_crypto_start_batch_verify_version_1(ctx context.Context, m api.Module) { +func ext_crypto_start_batch_verify_version_1(_ context.Context, _ api.Module) { // TODO: fix and re-enable signature verification (#1405) // beginBatchVerify(context) } -func ext_crypto_finish_batch_verify_version_1(_ context.Context) uint32 { +func ext_crypto_finish_batch_verify_version_1(_ context.Context, _ api.Module) uint32 { // TODO: fix and re-enable signature verification (#1405) // return finishBatchVerify(context) return 1 @@ -1831,7 +1831,7 @@ func ext_offchain_random_seed_version_1(ctx context.Context, m api.Module) uint3 } // TODO Investigate via https://github.com/ChainSafe/gossamer/issues/3986 -func ext_offchain_submit_transaction_version_1(ctx context.Context, m api.Module, data uint64) uint64 { //nolint +func ext_offchain_submit_transaction_version_1(ctx context.Context, m api.Module, data uint64) uint64 { rtCtx := ctx.Value(runtimeContextKey).(*runtime.Context) if rtCtx == nil { panic("nil runtime context") diff --git a/lib/runtime/wazero/instance.go b/lib/runtime/wazero/instance.go index 3336262ce7..c71d709b6e 100644 --- a/lib/runtime/wazero/instance.go +++ b/lib/runtime/wazero/instance.go @@ -119,9 +119,10 @@ func newRuntime(ctx context.Context, // values from newer kusama/polkadot runtimes ExportMemory("memory", 23). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_logging_log_version_1(ctx, m, api.DecodeI32(stack[0]), stack[1], stack[2]) - }), []api.ValueType{i32, i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + tripleArgFn(ext_logging_log_version_1), + []api.ValueType{i32, i64, i64}, []api.ValueType{}, + ). Export("ext_logging_log_version_1"). NewFunctionBuilder(). WithFunc(func() int32 { @@ -169,479 +170,472 @@ func newRuntime(ctx context.Context, }). Export("ext_sandbox_memory_teardown_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_crypto_ed25519_generate_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1])) - }), []api.ValueType{i32, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_ed25519_generate_version_1), + []api.ValueType{i32, i64}, []api.ValueType{i32}, + ). Export("ext_crypto_ed25519_generate_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_ed25519_public_keys_version_1(ctx, m, api.DecodeU32(stack[0])) - }), []api.ValueType{i32}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_crypto_ed25519_public_keys_version_1), + []api.ValueType{i32}, []api.ValueType{i64}, + ). Export("ext_crypto_ed25519_public_keys_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_ed25519_sign_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - api.DecodeU32(stack[1]), - stack[2], - ) - }), []api.ValueType{i32, i32, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_crypto_ed25519_sign_version_1), + []api.ValueType{i32, i32, i64}, []api.ValueType{i64}, + ). Export("ext_crypto_ed25519_sign_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_crypto_ed25519_verify_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1], api.DecodeU32(stack[2])), - ) - }), []api.ValueType{i32, i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_crypto_ed25519_verify_version_1), + []api.ValueType{i32, i64, i32}, []api.ValueType{i32}, + ). Export("ext_crypto_ed25519_verify_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_secp256k1_ecdsa_recover_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - api.DecodeU32(stack[1]), - ) - }), []api.ValueType{i32, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_secp256k1_ecdsa_recover_version_1), + []api.ValueType{i32, i32}, []api.ValueType{i64}, + ). Export("ext_crypto_secp256k1_ecdsa_recover_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_secp256k1_ecdsa_recover_version_2( - ctx, - m, - api.DecodeU32(stack[0]), - api.DecodeU32(stack[1]), - ) - }), []api.ValueType{i32, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_secp256k1_ecdsa_recover_version_2), + []api.ValueType{i32, i32}, []api.ValueType{i64}, + ). Export("ext_crypto_secp256k1_ecdsa_recover_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_crypto_ecdsa_verify_version_2(ctx, m, api.DecodeU32(stack[0]), stack[1], api.DecodeU32(stack[2])), - ) - }), []api.ValueType{i32, i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_crypto_ecdsa_verify_version_2), + []api.ValueType{i32, i64, i32}, []api.ValueType{i32}, + ). Export("ext_crypto_ecdsa_verify_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_secp256k1_ecdsa_recover_compressed_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - api.DecodeU32(stack[1]), - ) - }), []api.ValueType{i32, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_secp256k1_ecdsa_recover_compressed_version_1), + []api.ValueType{i32, i32}, []api.ValueType{i64}, + ). Export("ext_crypto_secp256k1_ecdsa_recover_compressed_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_secp256k1_ecdsa_recover_compressed_version_2( - ctx, - m, - api.DecodeU32(stack[0]), - api.DecodeU32(stack[1]), - ) - }), []api.ValueType{i32, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_secp256k1_ecdsa_recover_compressed_version_2), + []api.ValueType{i32, i32}, []api.ValueType{i64}, + ). Export("ext_crypto_secp256k1_ecdsa_recover_compressed_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_crypto_sr25519_generate_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1])) - }), []api.ValueType{i32, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_sr25519_generate_version_1), + []api.ValueType{i32, i64}, []api.ValueType{i32}, + ). Export("ext_crypto_sr25519_generate_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_sr25519_public_keys_version_1(ctx, m, api.DecodeU32(stack[0])) - }), []api.ValueType{i32}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_crypto_sr25519_public_keys_version_1), + []api.ValueType{i32}, []api.ValueType{i64}, + ). Export("ext_crypto_sr25519_public_keys_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_crypto_sr25519_sign_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - api.DecodeU32(stack[1]), - stack[2], - ) - }), []api.ValueType{i32, i32, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_crypto_sr25519_sign_version_1), + []api.ValueType{i32, i32, i64}, []api.ValueType{i64}, + ). Export("ext_crypto_sr25519_sign_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_crypto_sr25519_verify_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1], api.DecodeU32(stack[2])), - ) - }), []api.ValueType{i32, i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_crypto_sr25519_verify_version_1), + []api.ValueType{i32, i64, i32}, []api.ValueType{i32}, + ). Export("ext_crypto_sr25519_verify_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_crypto_sr25519_verify_version_2(ctx, m, api.DecodeU32(stack[0]), stack[1], api.DecodeU32(stack[2])), - ) - }), []api.ValueType{i32, i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_crypto_sr25519_verify_version_2), + []api.ValueType{i32, i64, i32}, []api.ValueType{i32}, + ). Export("ext_crypto_sr25519_verify_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_crypto_start_batch_verify_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{}). + WithGoModuleFunction( + noArgFn(ext_crypto_start_batch_verify_version_1), + []api.ValueType{}, []api.ValueType{}, + ). Export("ext_crypto_start_batch_verify_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_crypto_finish_batch_verify_version_1(ctx)) - }), []api.ValueType{}, []api.ValueType{i32}). + WithGoModuleFunction( + noArgWithReturn(ext_crypto_finish_batch_verify_version_1), + []api.ValueType{}, []api.ValueType{i32}, + ). Export("ext_crypto_finish_batch_verify_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_trie_blake2_256_root_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_trie_blake2_256_root_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_trie_blake2_256_root_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_trie_blake2_256_root_version_2(ctx, m, stack[0], api.DecodeU32(stack[1]))) - }), []api.ValueType{i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_trie_blake2_256_root_version_2), + []api.ValueType{i64, i32}, []api.ValueType{i32}, + ). Export("ext_trie_blake2_256_root_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_trie_blake2_256_ordered_root_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_trie_blake2_256_ordered_root_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_trie_blake2_256_ordered_root_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_trie_blake2_256_ordered_root_version_2(ctx, m, stack[0], api.DecodeU32(stack[1])), - ) - }), []api.ValueType{i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_trie_blake2_256_ordered_root_version_2), + []api.ValueType{i64, i32}, []api.ValueType{i32}, + ). Export("ext_trie_blake2_256_ordered_root_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_trie_blake2_256_verify_proof_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - stack[1], - stack[2], - stack[3], - ), - ) - }), []api.ValueType{i32, i64, i64, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + quadArgWithReturnFn(ext_trie_blake2_256_verify_proof_version_1), + []api.ValueType{i32, i64, i64, i64}, []api.ValueType{i32}, + ). Export("ext_trie_blake2_256_verify_proof_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_trie_blake2_256_verify_proof_version_2( - ctx, - m, - api.DecodeU32(stack[0]), - stack[1], - stack[2], - stack[3], - api.DecodeU32(stack[4]), - ), - ) - }), []api.ValueType{i32, i64, i64, i64, i32}, []api.ValueType{i32}). + WithGoModuleFunction( + quintArgWithReturnFn(ext_trie_blake2_256_verify_proof_version_2), + []api.ValueType{i32, i64, i64, i64, i32}, []api.ValueType{i32}, + ). Export("ext_trie_blake2_256_verify_proof_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_misc_print_hex_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_misc_print_hex_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_misc_print_hex_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_misc_print_num_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_misc_print_num_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_misc_print_num_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_misc_print_utf8_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_misc_print_utf8_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_misc_print_utf8_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_misc_runtime_version_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_misc_runtime_version_version_1), + []api.ValueType{i64}, []api.ValueType{i64}, + ). Export("ext_misc_runtime_version_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func( - ctx context.Context, m api.Module, stack []uint64) { - ext_default_child_storage_set_version_1(ctx, m, stack[0], stack[1], stack[2]) - }), []api.ValueType{i64, i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + tripleArgFn(ext_default_child_storage_set_version_1), + []api.ValueType{i64, i64, i64}, []api.ValueType{}, + ). Export("ext_default_child_storage_set_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func( - ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_read_version_1( - ctx, - m, - stack[0], - stack[1], - stack[2], - api.DecodeU32(stack[3]), - ) - }), []api.ValueType{i64, i64, i64, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + quadArgWithReturnFn(ext_default_child_storage_read_version_1), + []api.ValueType{i64, i64, i64, i32}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_read_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_default_child_storage_clear_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + doubleArgFn(ext_default_child_storage_clear_version_1), + []api.ValueType{i64, i64}, []api.ValueType{}, + ). Export("ext_default_child_storage_clear_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_default_child_storage_clear_prefix_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + doubleArgFn(ext_default_child_storage_clear_prefix_version_1), + []api.ValueType{i64, i64}, []api.ValueType{}, + ). Export("ext_default_child_storage_clear_prefix_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_clear_prefix_version_2(ctx, m, stack[0], stack[1], stack[2]) - }), []api.ValueType{i64, i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_default_child_storage_clear_prefix_version_2), + []api.ValueType{i64, i64, i64}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_clear_prefix_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_default_child_storage_exists_version_1(ctx, m, stack[0], stack[1])) - }), []api.ValueType{i64, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_default_child_storage_exists_version_1), + []api.ValueType{i64, i64}, []api.ValueType{i32}, + ). Export("ext_default_child_storage_exists_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_get_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_default_child_storage_get_version_1), + []api.ValueType{i64, i64}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_get_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_next_key_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_default_child_storage_next_key_version_1), + []api.ValueType{i64, i64}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_next_key_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_root_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_default_child_storage_root_version_1), + []api.ValueType{i64}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_root_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_root_version_2(ctx, m, stack[0], api.DecodeU32(stack[1])) - }), []api.ValueType{i64, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_default_child_storage_root_version_2), + []api.ValueType{i64, i32}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_root_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_default_child_storage_storage_kill_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_default_child_storage_storage_kill_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_default_child_storage_storage_kill_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_default_child_storage_storage_kill_version_2(ctx, m, stack[0], stack[1])) - }), []api.ValueType{i64, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_default_child_storage_storage_kill_version_2), + []api.ValueType{i64, i64}, []api.ValueType{i32}, + ). Export("ext_default_child_storage_storage_kill_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_default_child_storage_storage_kill_version_3(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_default_child_storage_storage_kill_version_3), + []api.ValueType{i64, i64}, []api.ValueType{i64}, + ). Export("ext_default_child_storage_storage_kill_version_3"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_allocator_free_version_1(ctx, m, api.DecodeU32(stack[0])) - }), []api.ValueType{i32}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_allocator_free_version_1), + []api.ValueType{i32}, []api.ValueType{}, + ). Export("ext_allocator_free_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_allocator_malloc_version_1(ctx, m, api.DecodeU32(stack[0]))) - }), []api.ValueType{i32}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_allocator_malloc_version_1), + []api.ValueType{i32}, []api.ValueType{i32}, + ). Export("ext_allocator_malloc_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_blake2_128_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_blake2_128_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_blake2_128_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_blake2_256_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_blake2_256_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_blake2_256_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_keccak_256_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_keccak_256_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_keccak_256_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_sha2_256_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_sha2_256_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_sha2_256_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_twox_256_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_twox_256_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_twox_256_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_twox_128_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_twox_128_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_twox_128_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_hashing_twox_64_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_hashing_twox_64_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_hashing_twox_64_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_offchain_index_set_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + doubleArgFn(ext_offchain_index_set_version_1), + []api.ValueType{i64, i64}, []api.ValueType{}, + ). Export("ext_offchain_index_set_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_offchain_index_clear_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_offchain_index_clear_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_offchain_index_clear_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_offchain_local_storage_clear_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1]) - }), []api.ValueType{i32, i64}, []api.ValueType{}). + WithGoModuleFunction( + doubleArgFn(ext_offchain_local_storage_clear_version_1), + []api.ValueType{i32, i64}, []api.ValueType{}, + ). Export("ext_offchain_local_storage_clear_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_offchain_is_validator_version_1(ctx, m)) - }), []api.ValueType{}, []api.ValueType{i32}). + WithGoModuleFunction( + noArgWithReturn(ext_offchain_is_validator_version_1), + []api.ValueType{}, []api.ValueType{i32}, + ). Export("ext_offchain_is_validator_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32( - ext_offchain_local_storage_compare_and_set_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - stack[1], - stack[2], - stack[3], - ), - ) - }), []api.ValueType{i32, i64, i64, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + quadArgWithReturnFn(ext_offchain_local_storage_compare_and_set_version_1), + []api.ValueType{i32, i64, i64, i64}, []api.ValueType{i32}, + ). Export("ext_offchain_local_storage_compare_and_set_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_offchain_local_storage_get_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1]) - }), []api.ValueType{i32, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_offchain_local_storage_get_version_1), + []api.ValueType{i32, i64}, []api.ValueType{i64}, + ). Export("ext_offchain_local_storage_get_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_offchain_local_storage_set_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1], stack[2]) - }), []api.ValueType{i32, i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + tripleArgFn(ext_offchain_local_storage_set_version_1), + []api.ValueType{i32, i64, i64}, []api.ValueType{}, + ). Export("ext_offchain_local_storage_set_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_offchain_network_state_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{i64}). + WithGoModuleFunction( + noArgWithReturn(ext_offchain_network_state_version_1), + []api.ValueType{}, []api.ValueType{i64}, + ). Export("ext_offchain_network_state_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_offchain_random_seed_version_1(ctx, m)) - }), []api.ValueType{}, []api.ValueType{i32}). + WithGoModuleFunction( + noArgWithReturn(ext_offchain_random_seed_version_1), + []api.ValueType{}, []api.ValueType{i32}, + ). Export("ext_offchain_random_seed_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_offchain_submit_transaction_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_offchain_submit_transaction_version_1), + []api.ValueType{i64}, []api.ValueType{i64}, + ). Export("ext_offchain_submit_transaction_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_offchain_timestamp_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{i64}). + WithGoModuleFunction( + noArgWithReturn(ext_offchain_timestamp_version_1), + []api.ValueType{}, []api.ValueType{i64}, + ). Export("ext_offchain_timestamp_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_offchain_sleep_until_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_offchain_sleep_until_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_offchain_sleep_until_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_offchain_http_request_start_version_1(ctx, m, stack[0], stack[1], stack[2]) - }), []api.ValueType{i64, i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_offchain_http_request_start_version_1), + []api.ValueType{i64, i64, i64}, []api.ValueType{i64}, + ). Export("ext_offchain_http_request_start_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_offchain_http_request_add_header_version_1( - ctx, - m, - api.DecodeU32(stack[0]), - stack[1], - stack[2], - ) - }), []api.ValueType{i32, i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_offchain_http_request_add_header_version_1), + []api.ValueType{i32, i64, i64}, []api.ValueType{i64}, + ). Export("ext_offchain_http_request_add_header_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_append_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + doubleArgFn(ext_storage_append_version_1), + []api.ValueType{i64, i64}, []api.ValueType{}, + ). Export("ext_storage_append_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_changes_root_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_storage_changes_root_version_1), + []api.ValueType{i64}, []api.ValueType{i64}, + ). Export("ext_storage_changes_root_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_clear_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_storage_clear_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_storage_clear_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_clear_prefix_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{}). + WithGoModuleFunction( + singleArgFn(ext_storage_clear_prefix_version_1), + []api.ValueType{i64}, []api.ValueType{}, + ). Export("ext_storage_clear_prefix_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_clear_prefix_version_2(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{i64}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_storage_clear_prefix_version_2), + []api.ValueType{i64, i64}, []api.ValueType{i64}, + ). Export("ext_storage_clear_prefix_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_storage_exists_version_1(ctx, m, stack[0])) - }), []api.ValueType{i64}, []api.ValueType{i32}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_storage_exists_version_1), + []api.ValueType{i64}, []api.ValueType{i32}, + ). Export("ext_storage_exists_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_get_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_storage_get_version_1), + []api.ValueType{i64}, []api.ValueType{i64}, + ). Export("ext_storage_get_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_next_key_version_1(ctx, m, stack[0]) - }), []api.ValueType{i64}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_storage_next_key_version_1), + []api.ValueType{i64}, []api.ValueType{i64}, + ). Export("ext_storage_next_key_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_read_version_1(ctx, m, stack[0], stack[1], api.DecodeU32(stack[2])) - }), []api.ValueType{i64, i64, i32}, []api.ValueType{i64}). + WithGoModuleFunction( + tripleArgWithReturnFn(ext_storage_read_version_1), + []api.ValueType{i64, i64, i32}, []api.ValueType{i64}, + ). Export("ext_storage_read_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_root_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{i64}). + WithGoModuleFunction( + noArgWithReturn(ext_storage_root_version_1), + []api.ValueType{}, []api.ValueType{i64}, + ). Export("ext_storage_root_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = ext_storage_root_version_2(ctx, m, api.DecodeU32(stack[0])) - }), []api.ValueType{i32}, []api.ValueType{i64}). + WithGoModuleFunction( + singleArgWithReturnFn(ext_storage_root_version_2), + []api.ValueType{i32}, []api.ValueType{i64}, + ). Export("ext_storage_root_version_2"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_set_version_1(ctx, m, stack[0], stack[1]) - }), []api.ValueType{i64, i64}, []api.ValueType{}). + WithGoModuleFunction( + doubleArgFn(ext_storage_set_version_1), + []api.ValueType{i64, i64}, []api.ValueType{}, + ). Export("ext_storage_set_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_start_transaction_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{}). + WithGoModuleFunction( + noArgFn(ext_storage_start_transaction_version_1), + []api.ValueType{}, []api.ValueType{}, + ). Export("ext_storage_start_transaction_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_rollback_transaction_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{}). + WithGoModuleFunction( + noArgFn(ext_storage_rollback_transaction_version_1), + []api.ValueType{}, []api.ValueType{}, + ). Export("ext_storage_rollback_transaction_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - ext_storage_commit_transaction_version_1(ctx, m) - }), []api.ValueType{}, []api.ValueType{}). + WithGoModuleFunction( + noArgFn(ext_storage_commit_transaction_version_1), + []api.ValueType{}, []api.ValueType{}, + ). Export("ext_storage_commit_transaction_version_1"). NewFunctionBuilder(). - WithGoModuleFunction(api.GoModuleFunc(func(ctx context.Context, m api.Module, stack []uint64) { - stack[0] = api.EncodeU32(ext_crypto_ecdsa_generate_version_1(ctx, m, api.DecodeU32(stack[0]), stack[1])) - }), []api.ValueType{i32, i64}, []api.ValueType{i32}). + WithGoModuleFunction( + doubleArgWithReturnFn(ext_crypto_ecdsa_generate_version_1), + []api.ValueType{i32, i64}, []api.ValueType{i32}, + ). Export("ext_crypto_ecdsa_generate_version_1"). Compile(ctx) diff --git a/lib/runtime/wazero/types.go b/lib/runtime/wazero/types.go new file mode 100644 index 0000000000..fdc6601bd2 --- /dev/null +++ b/lib/runtime/wazero/types.go @@ -0,0 +1,100 @@ +// Copyright 2024 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +package wazero_runtime + +import ( + "context" + + "github.com/tetratelabs/wazero/api" +) + +type FnParamResultType interface { + uint32 | uint64 | int32 +} + +type noArg func(ctx context.Context, m api.Module) +type noArgWithRet[R FnParamResultType] func(ctx context.Context, m api.Module) R + +type singleArg[T FnParamResultType] func(ctx context.Context, m api.Module, a T) +type singleArgWithRet[T FnParamResultType, R FnParamResultType] func(ctx context.Context, m api.Module, a T) R + +type doubleArg[T FnParamResultType, U FnParamResultType] func(ctx context.Context, m api.Module, a T, b U) +type doubleArgWithRet[T FnParamResultType, U FnParamResultType, + R FnParamResultType] func(ctx context.Context, m api.Module, a T, b U) R + +type tripleArg[T FnParamResultType, U FnParamResultType, V FnParamResultType] func(ctx context.Context, m api.Module, + a T, b U, c V) +type tripleArgWithRet[T FnParamResultType, U FnParamResultType, V FnParamResultType, + R FnParamResultType] func(ctx context.Context, m api.Module, a T, b U, c V) R + +type quadArgWithRet[T FnParamResultType, U FnParamResultType, V FnParamResultType, W FnParamResultType, + R FnParamResultType] func(ctx context.Context, m api.Module, a T, b U, c V, d W) R + +type quintArgWithRet[T FnParamResultType, U FnParamResultType, V FnParamResultType, W FnParamResultType, + X FnParamResultType, R FnParamResultType] func(ctx context.Context, m api.Module, a T, b U, c V, d W, e X) R + +func noArgFn(f noArg) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, _ []uint64) { + f(ctx, m) + } +} + +func singleArgFn[T FnParamResultType](f singleArg[T]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + f(ctx, m, T(stack[0])) + } +} + +func doubleArgFn[T FnParamResultType, U FnParamResultType](f doubleArg[T, U]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + f(ctx, m, T(stack[0]), U(stack[1])) + } +} + +func tripleArgFn[T FnParamResultType, U FnParamResultType, V FnParamResultType]( + f tripleArg[T, U, V]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + f(ctx, m, T(stack[0]), U(stack[1]), V(stack[2])) + } +} + +func noArgWithReturn[R FnParamResultType](f noArgWithRet[R]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + stack[0] = uint64(f(ctx, m)) + } +} + +func singleArgWithReturnFn[T FnParamResultType, R FnParamResultType](f singleArgWithRet[T, R]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + stack[0] = uint64(f(ctx, m, T(stack[0]))) + } +} + +func doubleArgWithReturnFn[T FnParamResultType, U FnParamResultType, R FnParamResultType]( + f doubleArgWithRet[T, U, R]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + stack[0] = uint64(f(ctx, m, T(stack[0]), U(stack[1]))) + } +} + +func tripleArgWithReturnFn[T FnParamResultType, U FnParamResultType, V FnParamResultType, R FnParamResultType]( + f tripleArgWithRet[T, U, V, R]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + stack[0] = uint64(f(ctx, m, T(stack[0]), U(stack[1]), V(stack[2]))) + } +} + +func quadArgWithReturnFn[T FnParamResultType, U FnParamResultType, V FnParamResultType, W FnParamResultType, + R FnParamResultType](f quadArgWithRet[T, U, V, W, R]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + stack[0] = uint64(f(ctx, m, T(stack[0]), U(stack[1]), V(stack[2]), W(stack[3]))) + } +} + +func quintArgWithReturnFn[T FnParamResultType, U FnParamResultType, V FnParamResultType, W FnParamResultType, + X FnParamResultType, R FnParamResultType](f quintArgWithRet[T, U, V, W, X, R]) api.GoModuleFunc { + return func(ctx context.Context, m api.Module, stack []uint64) { + stack[0] = uint64(f(ctx, m, T(stack[0]), U(stack[1]), V(stack[2]), W(stack[3]), X(stack[4]))) + } +}