├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── lint.yaml │ ├── doc.yaml │ ├── nightly.yaml │ └── main.yaml ├── ext ├── lib │ ├── libwasmer.so │ └── libwasmer.dylib ├── examples │ ├── hello.wasm │ ├── hello.wat │ ├── callback.wat │ ├── memory.wat │ ├── hello.php │ ├── global.wat │ ├── memory.php │ └── callback.php ├── tests │ ├── extension.phpt │ ├── api │ │ ├── wasmer │ │ │ ├── wasmer_version.phpt │ │ │ ├── wasmer_version_major.phpt │ │ │ ├── wasmer_version_minor.phpt │ │ │ ├── wasmer_version_patch.phpt │ │ │ └── wasmer_version_pre.phpt │ │ ├── types │ │ │ ├── limits │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_limits_max.phpt │ │ │ │ ├── 02-wasm_limits_min.phpt │ │ │ │ ├── 02-wasm_limits_new.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── valtype │ │ │ │ ├── 00-classes.phpt │ │ │ │ ├── 02-wasm_valtype_new.phpt │ │ │ │ ├── 02-wasm_valtype_kind.phpt │ │ │ │ ├── 02-wasm_valtype_is_ref.phpt │ │ │ │ ├── 02-wasm_valtype_copy.phpt │ │ │ │ ├── 02-wasm_valtype_delete.phpt │ │ │ │ ├── 02-wasm_valtype_is_num.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_vec_valtype_offsetGet.phpt │ │ │ │ ├── 02-wasm_vec_valtype_offsetSet.phpt │ │ │ │ ├── 02-wasm_vec_valtype___construct.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── valkind │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_valtype_is_num.phpt │ │ │ │ ├── 02-wasm_valtype_is_ref.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── functype │ │ │ │ ├── 02-wasm_functype_new.phpt │ │ │ │ ├── 02-wasm_functype_params.phpt │ │ │ │ ├── 02-wasm_functype_results.phpt │ │ │ │ ├── 02-wasm_functype_copy.phpt │ │ │ │ ├── 02-wasm_functype_delete.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_vec_functype_offsetGet.phpt │ │ │ │ ├── 02-wasm_vec_functype_offsetSet.phpt │ │ │ │ ├── 02-wasm_vec_functype___construct.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── memorytype │ │ │ │ ├── 02-wasm_memorytype_new.phpt │ │ │ │ ├── 02-wasm_memorytype_as_externtype.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_memorytype_limits.phpt │ │ │ │ ├── 02-wasm_memorytype_copy.phpt │ │ │ │ ├── 02-wasm_memorytype_delete.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── globaltype │ │ │ │ ├── 02-wasm_globaltype_new.phpt │ │ │ │ ├── 02-wasm_globaltype_content.phpt │ │ │ │ ├── 02-wasm_globaltype_mutability.phpt │ │ │ │ ├── 02-wasm_globaltype_as_externtype.phpt │ │ │ │ ├── 02-wasm_globaltype_copy.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_globaltype_delete.phpt │ │ │ │ ├── 02-wasm_vec_globaltype_offsetGet.phpt │ │ │ │ ├── 02-wasm_vec_globaltype_offsetSet.phpt │ │ │ │ ├── 02-wasm_vec_globaltype___construct.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── tabletype │ │ │ │ ├── 02-wasm_tabletype_new.phpt │ │ │ │ ├── 02-wasm_tabletype_limits.phpt │ │ │ │ ├── 02-wasm_tabletype_element.phpt │ │ │ │ ├── 02-wasm_tabletype_as_externtype.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_tabletype_copy.phpt │ │ │ │ ├── 02-wasm_tabletype_delete.phpt │ │ │ │ ├── 02-wasm_vec_tabletype_offsetSet.phpt │ │ │ │ ├── 02-wasm_vec_tabletype_offsetGet.phpt │ │ │ │ ├── 02-wasm_vec_tabletype___construct.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── exporttype │ │ │ │ ├── 02-wasm_exporttype_new.phpt │ │ │ │ ├── 02-wasm_exporttype_name.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_exporttype_type.phpt │ │ │ │ ├── 02-wasm_exporttype_copy.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── importtype │ │ │ │ ├── 02-wasm_importtype_new.phpt │ │ │ │ ├── 02-wasm_importtype_name.phpt │ │ │ │ ├── 02-wasm_importtype_module.phpt │ │ │ │ ├── 02-wasm_importtype_type.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_importtype_copy.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ └── externtype │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_externtype_delete.phpt │ │ │ │ └── 01-arginfo.phpt │ │ ├── config │ │ │ ├── 02-wasm_config_new.phpt │ │ │ ├── 00-functions.phpt │ │ │ ├── 01-arginfo.phpt │ │ │ ├── 02-wasm_config_set_engine.phpt │ │ │ ├── 02-wasm_config_delete.phpt │ │ │ └── 02-wasm_config_set_compiler.phpt │ │ ├── engine │ │ │ ├── 02-wasm_engine_new.phpt │ │ │ ├── 02-wasm_engine_new_with_config.phpt │ │ │ ├── 00-functions.phpt │ │ │ ├── 02-wasm_engine_new_with_config_engine_JIT.phpt │ │ │ ├── 02-wasm_engine_new_with_config_engine_native.phpt │ │ │ ├── 02-wasm_engine_new_with_config_compiler_cranelift.phpt │ │ │ ├── 02-wasm_engine_new_with_config_engine_object_file.phpt │ │ │ ├── 02-wasm_engine_delete.phpt │ │ │ ├── 02-wasm_engine_new_with_config_compiler_cranelift_JIT.phpt │ │ │ ├── 02-wasm_engine_new_with_config_compiler_cranelift_native.phpt │ │ │ ├── 02-wasm_engine_new_with_config_compiler_LLVM.phpt │ │ │ ├── 02-wasm_engine_new_with_config_compiler_cranelift_object_file.phpt │ │ │ ├── 02-wasm_engine_new_with_config_compiler_singlepass.phpt │ │ │ └── 01-arginfo.phpt │ │ ├── objects │ │ │ ├── val │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_val_delete.phpt │ │ │ │ ├── 01-arginfo.phpt │ │ │ │ ├── 02-wasm_val.phpt │ │ │ │ ├── 02-wasm_val_kind.phpt │ │ │ │ ├── 02-wasm_vec_val_offsetGet.phpt │ │ │ │ ├── 02-wasm_vec_val_offsetSet.phpt │ │ │ │ ├── 02-wasm_val_value.phpt │ │ │ │ └── 02-wasm_vec_val___construct.phpt │ │ │ ├── func │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_func_type.phpt │ │ │ │ ├── 01-arginfo.phpt │ │ │ │ ├── 02-wasm_func_as_extern.phpt │ │ │ │ ├── 02-wasm_func_delete.phpt │ │ │ │ ├── 02-wasm_func_call_with_trap.phpt │ │ │ │ ├── 02-wasm_func_call_host.phpt │ │ │ │ ├── 02-wasm_func_call_guest.phpt │ │ │ │ └── 02-wasm_func_new.phpt │ │ │ ├── trap │ │ │ │ ├── 02-wasm_trap_new.phpt │ │ │ │ ├── 02-wasm_trap_origin.phpt │ │ │ │ ├── 02-wasm_trap_message.phpt │ │ │ │ ├── 02-wasm_trap_trace.phpt │ │ │ │ ├── 02-wasm_trap_copy.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_trap_delete.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── module │ │ │ │ ├── 02-wasm_module_new.phpt │ │ │ │ ├── 02-wasm_module_name.phpt │ │ │ │ ├── 02-wasm_module_set_name.phpt │ │ │ │ ├── 02-wasm_module_imports.phpt │ │ │ │ ├── 02-wasm_module_copy.phpt │ │ │ │ ├── 02-wasm_module_exports.phpt │ │ │ │ ├── 02-wasm_module_validate.phpt │ │ │ │ ├── 02-wasm_module_new_cranelift_JIT.phpt │ │ │ │ ├── 02-wasm_module_ser_deser.phpt │ │ │ │ ├── 02-wasm_module_delete.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_module_new_cranelift_native.phpt │ │ │ │ ├── 02-wasm_module_new_cranelift_object_file.phpt │ │ │ │ └── 01-arginfo.phpt │ │ │ ├── extern │ │ │ │ ├── 02-wasm_vec_extern___clone.phpt │ │ │ │ ├── 02-wasm_extern_type.phpt │ │ │ │ ├── 00-functions.phpt │ │ │ │ ├── 02-wasm_extern_delete.phpt │ │ │ │ ├── 02-wasm_vec_extern_offsetExists.phpt │ │ │ │ ├── 02-wasm_extern_kind.phpt │ │ │ │ ├── 02-wasm_extern_as_global.phpt │ │ │ │ ├── 02-wasm_extern_as_func.phpt │ │ │ │ ├── 02-wasm_vec_extern_offsetGet.phpt │ │ │ │ ├── 01-arginfo.phpt │ │ │ │ ├── 02-wasm_vec_extern_offsetSet.phpt │ │ │ │ └── 02-wasm_vec_extern___construct.phpt │ │ │ ├── memory │ │ │ │ ├── 02-wasm_memory_new.phpt │ │ │ │ ├── 02-wasm_memory_size.phpt │ │ │ │ ├── 02-wasm_memory_data.phpt │ │ │ │ ├── 02-wasm_memory_data_size.phpt │ │ │ │ ├── 02-wasm_memory_as_extern.phpt │ │ │ │ ├── 02-wasm_memory_same.phpt │ │ │ │ ├── 02-wasm_memory_grow.phpt │ │ │ │ ├── 02-wasm_memory_type.phpt │ │ │ │ ├── 02-wasm_memory_delete.phpt │ │ │ │ └── 00-functions.phpt │ │ │ ├── global │ │ │ │ ├── 02-wasm_global_new.phpt │ │ │ │ ├── 02-wasm_global_copy.phpt │ │ │ │ ├── 02-wasm_global_as_extern.phpt │ │ │ │ ├── 02-wasm_global_same.phpt │ │ │ │ ├── 02-wasm_global_get_host.phpt │ │ │ │ ├── 02-wasm_global_delete.phpt │ │ │ │ ├── 02-wasm_global_type.phpt │ │ │ │ ├── 02-wasm_global_get_guest.phpt │ │ │ │ ├── 02-wasm_global_set_host.phpt │ │ │ │ └── 02-wasm_global_set_guest.phpt │ │ │ └── instance │ │ │ │ ├── 02-wasm_instance_copy.phpt │ │ │ │ ├── 02-wasm_instance_exports.phpt │ │ │ │ ├── 02-wasm_instance_new_with_trap.phpt │ │ │ │ ├── 02-wasm_instance_delete.phpt │ │ │ │ └── 02-wasm_instance_new.phpt │ │ ├── store │ │ │ ├── 00-functions.phpt │ │ │ ├── 02-wasm_store_new.phpt │ │ │ ├── 02-wasm_store_delete.phpt │ │ │ └── 01-arginfo.phpt │ │ └── wat │ │ │ ├── 02-wat2wasm_error.phpt │ │ │ └── 02-wat2wasm.phpt │ └── exceptions.phpt ├── src │ ├── php_wasm.h │ ├── wasmer_exception.stub.php │ ├── api │ │ ├── objects │ │ │ ├── foreign.c │ │ │ ├── table.c │ │ │ ├── frame.c │ │ │ └── instance.c │ │ ├── wasmer.c │ │ ├── types │ │ │ ├── valkind.c │ │ │ ├── limits.c │ │ │ ├── valtype.c │ │ │ ├── exporttype.c │ │ │ └── memorytype.c │ │ ├── store.c │ │ ├── wat.c │ │ ├── engine.c │ │ └── config.c │ ├── wasmer_exception_arginfo.h │ ├── wasmer_class.stub.php │ └── wasmer_class_arginfo.h ├── config.m4 └── Makefile.frag ├── tests ├── examples │ ├── hello.wasm │ ├── hello.wat │ ├── callback.wat │ ├── Example.php │ ├── Hello.php │ ├── globl.wat │ └── Callback.php └── unit │ ├── Wat.php │ ├── Store.php │ ├── Engine.php │ └── Config.php ├── .atoum.php ├── src ├── Exception │ └── InvalidArgumentException.php ├── Wat.php ├── Engine.php ├── Store.php ├── Instance.php ├── Extern.php └── Func.php ├── .php-cs-fixer.php ├── .gitignore ├── phpdoc.dist.xml ├── phpunit.xml ├── LICENSE ├── composer.json ├── examples ├── instance.php ├── exports-function.php ├── errors.php ├── imports-function-early-exit.php └── exports-global.php └── CMakeLists.txt /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @wasmerio/langint 2 | -------------------------------------------------------------------------------- /ext/lib/libwasmer.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasmerio/wasmer-php/HEAD/ext/lib/libwasmer.so -------------------------------------------------------------------------------- /ext/examples/hello.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasmerio/wasmer-php/HEAD/ext/examples/hello.wasm -------------------------------------------------------------------------------- /ext/lib/libwasmer.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasmerio/wasmer-php/HEAD/ext/lib/libwasmer.dylib -------------------------------------------------------------------------------- /tests/examples/hello.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasmerio/wasmer-php/HEAD/tests/examples/hello.wasm -------------------------------------------------------------------------------- /ext/examples/hello.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $hello (import "" "hello")) 3 | (func (export "run") (call $hello)) 4 | ) -------------------------------------------------------------------------------- /tests/examples/hello.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $hello (import "" "hello")) 3 | (func (export "run") (call $hello)) 4 | ) -------------------------------------------------------------------------------- /ext/tests/extension.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wasmer PHP 3 | 4 | --FILE-- 5 | 10 | --EXPECTF-- 11 | bool(true) 12 | -------------------------------------------------------------------------------- /.atoum.php: -------------------------------------------------------------------------------- 1 | setPhpPath($php.' -dextension='.__DIR__.'/ext/modules/wasm.so'); 6 | $runner->addTestsFromDirectory('tests'); 7 | -------------------------------------------------------------------------------- /src/Exception/InvalidArgumentException.php: -------------------------------------------------------------------------------- 1 | 10 | --EXPECTF-- 11 | string(5) "%d.%d.%d" 12 | -------------------------------------------------------------------------------- /ext/tests/api/wasmer/wasmer_version_major.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wasmer: wasmer_version_major 3 | 4 | --FILE-- 5 | 10 | --EXPECTF-- 11 | int(%d) 12 | -------------------------------------------------------------------------------- /ext/tests/api/wasmer/wasmer_version_minor.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wasmer: wasmer_version_minor 3 | 4 | --FILE-- 5 | 10 | --EXPECTF-- 11 | int(%d) 12 | -------------------------------------------------------------------------------- /ext/tests/api/wasmer/wasmer_version_patch.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wasmer: wasmer_version_patch 3 | 4 | --FILE-- 5 | 10 | --EXPECTF-- 11 | int(%d) 12 | -------------------------------------------------------------------------------- /ext/tests/api/wasmer/wasmer_version_pre.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wasmer: wasmer_version_pre 3 | 4 | --FILE-- 5 | 10 | --EXPECTF-- 11 | string(0) "" 12 | -------------------------------------------------------------------------------- /ext/tests/api/types/limits/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Limits API functions 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | bool(true) 14 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/00-classes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API classes 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | bool(true) 14 | -------------------------------------------------------------------------------- /ext/tests/api/types/limits/02-wasm_limits_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Limits API: wasm_limits_max 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | int(2) 13 | -------------------------------------------------------------------------------- /ext/tests/api/types/limits/02-wasm_limits_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Limits API: wasm_limits_min 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | int(1) 13 | -------------------------------------------------------------------------------- /ext/tests/api/config/02-wasm_config_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Config API: wasm_config_new 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | resource(%d) of type (wasm_config_t) 13 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | resource(%d) of type (wasm_engine_t) 13 | -------------------------------------------------------------------------------- /ext/tests/api/types/limits/02-wasm_limits_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Limits API: wasm_limits_new 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | resource(%d) of type (wasm_limits_t) 13 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_valtype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: wasm_valtype_new 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | resource(%d) of type (wasm_valtype_t) 13 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API functions 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | -------------------------------------------------------------------------------- /ext/tests/api/store/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Store API functions 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | -------------------------------------------------------------------------------- /ext/tests/api/store/02-wasm_store_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Store API: wasm_store_new 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | resource(%d) of type (wasm_store_t) 14 | -------------------------------------------------------------------------------- /ext/tests/api/config/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Config API functions 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API functions 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/valkind/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValKind API functions 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_valtype_kind.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: wasm_valtype_kind 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | bool(true) 14 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: "composer" 5 | directory: "/" 6 | allow: 7 | - dependency-type: "all" 8 | rebase-strategy: "auto" 9 | schedule: 10 | interval: "weekly" 11 | day: "sunday" 12 | versioning-strategy: "auto" 13 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/02-wasm_trap_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API: wasm_trap_new 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | resource(%d) of type (wasm_trap_t) 14 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_functype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: wasm_functype_new 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | resource(%d) of type (wasm_functype_t) 13 | -------------------------------------------------------------------------------- /src/Wat.php: -------------------------------------------------------------------------------- 1 | 12 | --EXPECTF-- 13 | resource(%d) of type (wasm_engine_t) 14 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/02-wasm_trap_origin.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API: wasm_trap_origin 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | NULL 15 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/02-wasm_memorytype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API: wasm_memorytype_new 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | resource(%d) of type (wasm_memorytype_t) 14 | -------------------------------------------------------------------------------- /ext/src/php_wasm.h: -------------------------------------------------------------------------------- 1 | #ifndef PHP_WASM_H 2 | #define PHP_WASM_H 3 | 4 | extern zend_module_entry wasm_module_entry; 5 | #define phpext_wasm_ptr &wasm_module_entry 6 | 7 | #define PHP_WASM_VERSION "1.1.0" 8 | 9 | #if defined(ZTS) && defined(COMPILE_DL_WASMER) 10 | ZEND_TSRMLS_CACHE_EXTERN() 11 | #endif 12 | 13 | #endif /* PHP_WASM_H */ -------------------------------------------------------------------------------- /ext/tests/api/config/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Config API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | ?> 12 | --EXPECTF-- 13 | int(0) 14 | NULL 15 | -------------------------------------------------------------------------------- /ext/src/wasmer_exception.stub.php: -------------------------------------------------------------------------------- 1 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | ?> 12 | --EXPECTF-- 13 | int(2) 14 | NULL 15 | -------------------------------------------------------------------------------- /ext/tests/api/types/valkind/02-wasm_valtype_is_num.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValKind API: wasm_valkind_is_num 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | bool(true) 16 | bool(false) 17 | -------------------------------------------------------------------------------- /ext/tests/api/types/valkind/02-wasm_valtype_is_ref.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValKind API: wasm_valkind_is_ref 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | bool(true) 16 | bool(false) 17 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_functype_params.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: wasm_functype_params 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | object(Wasm\Vec\ValType)#%d (%d) { 13 | } 14 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_functype_results.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: wasm_functype_results 3 | 4 | --FILE-- 5 | 11 | --EXPECTF-- 12 | object(Wasm\Vec\ValType)#%d (%d) { 13 | } 14 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_globaltype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: wasm_globaltype_new 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | resource(%d) of type (wasm_globaltype_t) 14 | -------------------------------------------------------------------------------- /ext/examples/callback.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $print (import "" "print") (param i32) (result i32)) 3 | (func $closure (import "" "closure") (result i32)) 4 | (func (export "run") (param $x i32) (param $y i32) (result i32) 5 | (i32.add 6 | (call $print (i32.add (local.get $x) (local.get $y))) 7 | (call $closure) 8 | ) 9 | ) 10 | ) -------------------------------------------------------------------------------- /ext/tests/api/engine/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API functions 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | bool(true) 16 | bool(true) 17 | bool(true) 18 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/02-wasm_trap_message.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API: wasm_trap_message 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | string(12) "Trap message" 15 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/02-wasm_trap_trace.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API: wasm_trap_trace 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | object(Wasm\Vec\Frame)#%d (0) { 15 | } 16 | -------------------------------------------------------------------------------- /tests/examples/callback.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (func $print (import "" "print") (param i32) (result i32)) 3 | (func $closure (import "" "closure") (result i32)) 4 | (func (export "run") (param $x i32) (param $y i32) (result i32) 5 | (i32.add 6 | (call $print (i32.add (local.get $x) (local.get $y))) 7 | (call $closure) 8 | ) 9 | ) 10 | ) 11 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_functype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: wasm_functype_copy 3 | 4 | --FILE-- 5 | 12 | --EXPECTF-- 13 | resource(%d) of type (wasm_functype_t) 14 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_new 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_module_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_tabletype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: wasm_tabletype_new 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_tabletype_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/wat/02-wat2wasm_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | WAT: wat2wasm (error) 3 | 4 | --FILE-- 5 | getMessage()); 13 | } 14 | 15 | ?> 16 | --EXPECTF-- 17 | string(62) "expected `(` 18 | --> :1:1 19 | | 20 | 1 | foo 21 | | ^" -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_name.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_name 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | string(4) "test" 16 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_engine_JIT.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (JIT) 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_engine_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_engine_native.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (Native) 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_engine_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_vec_extern___clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: Wasm\Vec\Extern (clone) 3 | 4 | --FILE-- 5 | getMessage()); 13 | } 14 | 15 | ?> 16 | --EXPECTF-- 17 | string(62) "Trying to clone an uncloneable object of class Wasm\Vec\Extern" 18 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_globaltype_content.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: wasm_globaltype_content 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_tabletype_limits.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: wasm_tabletype_limits 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_limits_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_new 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_memory_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_globaltype_mutability.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: wasm_globaltype_mutability 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/02-wasm_memorytype_as_externtype.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API: wasm_memorytype_as_externtype 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_externtype_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (Cranelift) 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_engine_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_engine_object_file.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (Object File) 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_engine_t) 15 | -------------------------------------------------------------------------------- /ext/src/api/objects/foreign.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasm.h" 4 | 5 | #include "../macros.h" 6 | 7 | WASMER_IMPORT_RESOURCE(foreign) 8 | 9 | PHP_FUNCTION (wasm_foreign_new) { 10 | ZEND_PARSE_PARAMETERS_NONE(); 11 | 12 | // TODO(jubianchi): Implement 13 | zend_throw_error(NULL, "Not yet implemented"); 14 | } 15 | 16 | WASMER_DELETE_RESOURCE(foreign) 17 | 18 | // TODO(jubianchi): Implement copy 19 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_new 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_global_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_tabletype_element.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: wasm_tabletype_element 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | bool(true) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_valtype_is_ref.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: wasm_valtype_is_ref 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | bool(true) 18 | bool(false) 19 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_globaltype_as_externtype.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: wasm_globaltype_as_externtype 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | resource(%d) of type (wasm_externtype_t) 15 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_valtype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: wasm_valtype_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 18 | --EXPECTF-- 19 | resource(%d) of type (wasm_valtype_t) 20 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API functions 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | bool(true) 17 | bool(true) 18 | bool(true) 19 | bool(true) 20 | -------------------------------------------------------------------------------- /ext/tests/api/wat/02-wat2wasm.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | WAT: wat2wasm 3 | 4 | --FILE-- 5 | 19 | --EXPECTF-- 20 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_size.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_size 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | int(1) 18 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_val_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API: wasm_val_delete 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | bool(true) 19 | string(71) "wasm_val_delete(): supplied resource is not a valid wasm_val_t resource" 20 | -------------------------------------------------------------------------------- /ext/tests/api/config/02-wasm_config_set_engine.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Config API: wasm_config_set_engine 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | bool(true) 17 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_type 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_functype_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_data.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_data 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | object(Wasm\MemoryView)#%d (0) { 17 | } 18 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/02-wasm_trap_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API: wasm_trap_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 19 | --EXPECTF-- 20 | resource(%d) of type (wasm_trap_t) 21 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_tabletype_as_externtype.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: wasm_tabletype_as_externtype 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_externtype_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_data_size.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_data_size 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | int(65536) 18 | -------------------------------------------------------------------------------- /ext/tests/api/config/02-wasm_config_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Config API: wasm_config_delete 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | bool(true) 19 | string(77) "wasm_config_delete(): supplied resource is not a valid wasm_config_t resource" 20 | -------------------------------------------------------------------------------- /ext/tests/api/config/02-wasm_config_set_compiler.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Config API: wasm_config_set_compiler 3 | 4 | --FILE-- 5 | 13 | --EXPECTF-- 14 | bool(true) 15 | bool(true) 16 | bool(true) 17 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_delete 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | bool(true) 19 | string(77) "wasm_engine_delete(): supplied resource is not a valid wasm_engine_t resource" 20 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API functions 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | bool(true) 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_as_extern.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_as_extern 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | resource(%d) of type (wasm_extern_t) 18 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_copy 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | resource(%d) of type (wasm_global_t) 18 | -------------------------------------------------------------------------------- /tests/examples/Example.php: -------------------------------------------------------------------------------- 1 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_engine_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_as_extern.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_as_extern 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | resource(%d) of type (wasm_extern_t) 17 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_same.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_same 3 | 4 | --FILE-- 5 | 18 | --EXPECTF-- 19 | bool(true) 20 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/02-wasm_memorytype_limits.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API: wasm_memorytype_limits 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | resource(%d) of type (wasm_limits_t) 17 | int(1) 18 | int(2) 19 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift_native.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (Cranelift, Native) 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_engine_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/types/exporttype/02-wasm_exporttype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExportType API: wasm_exporttype_new 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | resource(%d) of type (wasm_exporttype_t) 17 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_valtype_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: wasm_valtype_delete 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | bool(true) 19 | string(79) "wasm_valtype_delete(): supplied resource is not a valid wasm_valtype_t resource" 20 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_same.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_same 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | -------------------------------------------------------------------------------- /ext/tests/api/store/02-wasm_store_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Store API: wasm_store_delete 3 | 4 | --FILE-- 5 | getMessage()); 15 | } 16 | 17 | ?> 18 | --EXPECTF-- 19 | bool(true) 20 | string(75) "wasm_store_delete(): supplied resource is not a valid wasm_store_t resource" 21 | -------------------------------------------------------------------------------- /ext/tests/api/types/exporttype/02-wasm_exporttype_name.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExportType API: wasm_exporttype_module 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | bool(true) 17 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API functions 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | bool(true) 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | -------------------------------------------------------------------------------- /ext/tests/api/types/exporttype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExportType API functions 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | bool(true) 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/02-wasm_memorytype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API: wasm_memorytype_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 19 | --EXPECTF-- 20 | resource(%d) of type (wasm_memorytype_t) 21 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_valtype_is_num.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: wasm_valtype_is_num 3 | 4 | --FILE-- 5 | 18 | --EXPECTF-- 19 | bool(true) 20 | bool(false) 21 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_compiler_LLVM.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (LLVM) 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | string(53) "Wasmer has not been compiled with the `llvm` feature." 19 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_compiler_cranelift_object_file.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (Cranelift, Object File) 3 | 4 | --FILE-- 5 | 14 | --EXPECTF-- 15 | resource(%d) of type (wasm_engine_t) 16 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_set_name.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_set_name 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | string(4) "test" 18 | string(8) "new_name" 19 | -------------------------------------------------------------------------------- /ext/tests/api/types/exporttype/02-wasm_exporttype_type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExportType API: wasm_exporttype_new 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | resource(%d) of type (wasm_externtype_t) 17 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_grow.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_grow 3 | 4 | --FILE-- 5 | 20 | --EXPECTF-- 21 | bool(true) 22 | int(2) 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_imports.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_imports 3 | 4 | --FILE-- 5 | count()); 14 | 15 | ?> 16 | --EXPECTF-- 17 | object(Wasm\Vec\ImportType)#%d (0) { 18 | } 19 | int(1) 20 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_globaltype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: wasm_globaltype_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 19 | --EXPECTF-- 20 | resource(%d) of type (wasm_globaltype_t) 21 | -------------------------------------------------------------------------------- /ext/tests/api/engine/02-wasm_engine_new_with_config_compiler_singlepass.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API: wasm_engine_new_with_config (Singlepass) 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | string(59) "Wasmer has not been compiled with the `singlepass` feature." 19 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_extern_type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: wasm_extern_type 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | resource(%d) of type (wasm_externtype_t) 19 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_func_as_extern'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()); 14 | 15 | ?> 16 | --EXPECTF-- 17 | int(3) 18 | NULL 19 | int(1) 20 | NULL 21 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_as_extern.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_as_extern 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | resource(%d) of type (wasm_extern_t) 18 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/02-wasm_importtype_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API: wasm_importtype_new 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | resource(%d) of type (wasm_importtype_t) 18 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 21 | --EXPECTF-- 22 | resource(%d) of type (wasm_module_t) 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_exports.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_exports 3 | 4 | --FILE-- 5 | count()); 14 | 15 | ?> 16 | --EXPECTF-- 17 | object(Wasm\Vec\ExportType)#%d (0) { 18 | } 19 | int(1) 20 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/02-wasm_importtype_name.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API: wasm_importtype_module 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | bool(true) 18 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/02-wasm_importtype_module.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API: wasm_importtype_module 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | bool(true) 18 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_functype_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: wasm_functype_delete 3 | 4 | --FILE-- 5 | getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | bool(true) 19 | string(81) "wasm_functype_delete(): supplied resource is not a valid wasm_functype_t resource" 20 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/02-wasm_trap_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API: wasm_trap_delete 3 | 4 | --FILE-- 5 | getMessage()); 16 | } 17 | 18 | ?> 19 | --EXPECTF-- 20 | bool(true) 21 | string(73) "wasm_trap_delete(): supplied resource is not a valid wasm_trap_t resource" 22 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()->getName()); 10 | 11 | $reflection = new ReflectionFunction('wasm_val_copy'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()); 14 | 15 | ?> 16 | --EXPECTF-- 17 | int(1) 18 | string(4) "bool" 19 | int(1) 20 | NULL 21 | -------------------------------------------------------------------------------- /ext/tests/api/store/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Store API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_store_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | ?> 16 | --EXPECTF-- 17 | int(1) 18 | NULL 19 | int(1) 20 | string(4) "bool" 21 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/02-wasm_importtype_type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API: wasm_importtype_new 3 | 4 | --FILE-- 5 | 16 | --EXPECTF-- 17 | resource(%d) of type (wasm_externtype_t) 18 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_tabletype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: wasm_tabletype_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 20 | --EXPECTF-- 21 | resource(%d) of type (wasm_tabletype_t) 22 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API functions 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API functions 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_get_host.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_get (host) 3 | 4 | --FILE-- 5 | 18 | --EXPECTF-- 19 | resource(%d) of type (wasm_val_t) 20 | int(1) 21 | -------------------------------------------------------------------------------- /ext/src/wasmer_exception_arginfo.h: -------------------------------------------------------------------------------- 1 | /* This is a generated file, edit the .stub.php file instead. 2 | * Stub hash: 5b4828f5f0360be441df82f85d9608dccd12cae3 */ 3 | 4 | 5 | 6 | 7 | static const zend_function_entry class_Wasm_Exception_RuntimeException_methods[] = { 8 | ZEND_FE_END 9 | }; 10 | 11 | 12 | static const zend_function_entry class_Wasm_Exception_InstantiationException_methods[] = { 13 | ZEND_FE_END 14 | }; 15 | 16 | 17 | static const zend_function_entry class_Wasm_Exception_OutOfBoundsException_methods[] = { 18 | ZEND_FE_END 19 | }; 20 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API functions 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API functions 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/02-wasm_memorytype_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API: wasm_memorytype_delete 3 | 4 | --FILE-- 5 | getMessage()); 15 | } 16 | 17 | ?> 18 | --EXPECTF-- 19 | bool(true) 20 | string(85) "wasm_memorytype_delete(): supplied resource is not a valid wasm_memorytype_t resource" 21 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_validate.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_validate 3 | 4 | --FILE-- 5 | getMessage()); 16 | } 17 | 18 | ?> 19 | --EXPECTF-- 20 | bool(true) 21 | string(48) "Validation error: Bad magic number (at offset 0)" 22 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_new_cranelift_JIT.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_new (Cranelift, JIT) 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | resource(%d) of type (wasm_module_t) 19 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_val.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API: wasm_val_i*/wasm_val_f* 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | resource(%d) of type (wasm_val_t) 17 | resource(%d) of type (wasm_val_t) 18 | resource(%d) of type (wasm_val_t) 19 | resource(%d) of type (wasm_val_t) 20 | resource(%d) of type (wasm_val_t) 21 | resource(%d) of type (wasm_val_t) 22 | -------------------------------------------------------------------------------- /tests/unit/Wat.php: -------------------------------------------------------------------------------- 1 | notName('wasmer_vec.stub.php') 5 | ->in('examples') 6 | ->in('ext/examples') 7 | ->in('ext/src') 8 | ->in('src') 9 | ->in('tests') 10 | ; 11 | 12 | $config = new PhpCsFixer\Config(); 13 | 14 | return $config->setRules([ 15 | '@PSR2' => true, 16 | '@Symfony' => true, 17 | 'strict_param' => true, 18 | 'phpdoc_align' => true, 19 | ]) 20 | ->setFinder($finder) 21 | ->setCacheFile(__DIR__.'/target/cache/php-cs-fixer/cs.cache') 22 | ; 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_ser_deser.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_serialize and wasm_module_deserialize 3 | 4 | --FILE-- 5 | 18 | --EXPECTF-- 19 | resource(%d) of type (wasm_module_t) 20 | resource(%d) of type (wasm_module_t) 21 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_type 3 | 4 | --FILE-- 5 | 18 | --EXPECTF-- 19 | resource(%d) of type (wasm_memorytype_t) 20 | resource(%d) of type (wasm_limits_t) 21 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API functions 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_globaltype_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: wasm_globaltype_delete 3 | 4 | --FILE-- 5 | getMessage()); 15 | } 16 | 17 | ?> 18 | --EXPECTF-- 19 | bool(true) 20 | string(85) "wasm_globaltype_delete(): supplied resource is not a valid wasm_globaltype_t resource" 21 | -------------------------------------------------------------------------------- /ext/tests/api/objects/instance/02-wasm_instance_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Instance API: wasm_instance_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 21 | --EXPECTF-- 22 | resource(%d) of type (wasm_instance_t) 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_delete 3 | 4 | --FILE-- 5 | getMessage()); 17 | } 18 | 19 | ?> 20 | --EXPECTF-- 21 | bool(true) 22 | string(77) "wasm_module_delete(): supplied resource is not a valid wasm_module_t resource" 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_val_kind.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API: wasm_val_kind 3 | 4 | --FILE-- 5 | 15 | --EXPECTF-- 16 | bool(true) 17 | bool(true) 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | -------------------------------------------------------------------------------- /ext/tests/api/types/externtype/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExternType API functions 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | bool(true) 19 | bool(true) 20 | bool(true) 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_tabletype_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: wasm_tabletype_delete 3 | 4 | --FILE-- 5 | getMessage()); 16 | } 17 | 18 | ?> 19 | --EXPECTF-- 20 | bool(true) 21 | string(83) "wasm_tabletype_delete(): supplied resource is not a valid wasm_tabletype_t resource" 22 | -------------------------------------------------------------------------------- /ext/tests/api/objects/instance/02-wasm_instance_exports.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Instance API: wasm_instance_exports 3 | 4 | --FILE-- 5 | count()); 15 | 16 | ?> 17 | --EXPECTF-- 18 | object(Wasm\Vec\Extern)#%d (0) { 19 | } 20 | int(1) 21 | -------------------------------------------------------------------------------- /ext/tests/api/types/externtype/02-wasm_externtype_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExternType API: wasm_externtype_delete 3 | 4 | --FILE-- 5 | getMessage()); 15 | } 16 | 17 | ?> 18 | --EXPECTF-- 19 | bool(true) 20 | string(85) "wasm_externtype_delete(): supplied resource is not a valid wasm_externtype_t resource" 21 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_vec_val_offsetGet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API: Wasm\Vec\Val::offsetGet() 3 | 4 | --FILE-- 5 | getMessage()); 17 | } 18 | 19 | ?> 20 | --EXPECTF-- 21 | resource(%d) of type (wasm_val_t) 22 | resource(%d) of type (wasm_val_t) 23 | string(52) "Wasm\Vec\Val::offsetGet($offset) index out of bounds" 24 | -------------------------------------------------------------------------------- /ext/tests/api/objects/instance/02-wasm_instance_new_with_trap.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Instance API: wasm_instance_new (trap) 3 | 4 | --FILE-- 5 | getMessage()); 23 | } 24 | 25 | ?> 26 | --EXPECTF-- 27 | string(11) "unreachable" 28 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_vec_val_offsetSet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API: Wasm\Vec\Val::offsetSet() 3 | 4 | --FILE-- 5 | getMessage()); 18 | } 19 | 20 | ?> 21 | --EXPECTF-- 22 | resource(%d) of type (wasm_val_t) 23 | resource(%d) of type (wasm_val_t) 24 | string(52) "Wasm\Vec\Val::offsetSet($offset) index out of bounds" 25 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_delete 3 | 4 | --FILE-- 5 | getMessage()); 17 | } 18 | 19 | ?> 20 | --EXPECTF-- 21 | bool(true) 22 | string(73) "wasm_func_delete(): supplied resource is not a valid wasm_func_t resource" 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/02-wasm_memory_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API: wasm_memory_delete 3 | 4 | --FILE-- 5 | getMessage()); 19 | } 20 | 21 | ?> 22 | --EXPECTF-- 23 | bool(true) 24 | string(77) "wasm_memory_delete(): supplied resource is not a valid wasm_memory_t resource" 25 | -------------------------------------------------------------------------------- /ext/tests/api/types/exporttype/02-wasm_exporttype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExportType API: wasm_exporttype_copy 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 22 | --EXPECTF-- 23 | resource(%d) of type (wasm_exporttype_t) 24 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_delete 3 | 4 | --FILE-- 5 | getMessage()); 18 | } 19 | 20 | ?> 21 | --EXPECTF-- 22 | bool(true) 23 | string(77) "wasm_global_delete(): supplied resource is not a valid wasm_global_t resource" 24 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_type.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_type 3 | 4 | --FILE-- 5 | 17 | --EXPECTF-- 18 | resource(%d) of type (wasm_globaltype_t) 19 | resource(%d) of type (wasm_valtype_t) 20 | int(0) 21 | -------------------------------------------------------------------------------- /ext/examples/memory.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type $mem_size_t (func (result i32))) 3 | (type $get_at_t (func (param i32) (result i32))) 4 | (type $set_at_t (func (param i32) (param i32))) 5 | (memory $mem 1) 6 | (func $get_at (type $get_at_t) (param $idx i32) (result i32) 7 | (i32.load (local.get $idx))) 8 | (func $set_at (type $set_at_t) (param $idx i32) (param $val i32) 9 | (i32.store (local.get $idx) (local.get $val))) 10 | (func $mem_size (type $mem_size_t) (result i32) 11 | (memory.size)) 12 | (export "get_at" (func $get_at)) 13 | (export "set_at" (func $set_at)) 14 | (export "mem_size" (func $mem_size)) 15 | (export "memory" (memory $mem)) 16 | ) 17 | -------------------------------------------------------------------------------- /ext/tests/api/objects/instance/02-wasm_instance_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Instance API: wasm_instance_delete 3 | 4 | --FILE-- 5 | getMessage()); 18 | } 19 | 20 | ?> 21 | --EXPECTF-- 22 | bool(true) 23 | string(81) "wasm_instance_delete(): supplied resource is not a valid wasm_instance_t resource" 24 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_vec_valtype_offsetGet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: Wasm\Vec\ValType::offsetGet() 3 | 4 | --FILE-- 5 | getMessage()); 16 | } 17 | 18 | ?> 19 | --EXPECTF-- 20 | resource(%d) of type (wasm_valtype_t) 21 | resource(%d) of type (wasm_valtype_t) 22 | string(56) "Wasm\Vec\ValType::offsetGet($offset) index out of bounds" 23 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/02-wasm_importtype_copy.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API: wasm_importtype_new 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 23 | --EXPECTF-- 24 | resource(%d) of type (wasm_importtype_t) 25 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_extern_delete.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: wasm_extern_delete 3 | 4 | --FILE-- 5 | getMessage()); 20 | } 21 | 22 | ?> 23 | --EXPECTF-- 24 | bool(true) 25 | string(77) "wasm_extern_delete(): supplied resource is not a valid wasm_extern_t resource" 26 | -------------------------------------------------------------------------------- /ext/tests/api/objects/memory/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Memory API functions 3 | 4 | --FILE-- 5 | 20 | --EXPECTF-- 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_val_value.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API 3 | 4 | --FILE-- 5 | 28 | --EXPECTF-- 29 | int(1) 30 | float(2) 31 | float(2) 32 | int(3) 33 | float(4) 34 | float(4) 35 | int(5) 36 | -------------------------------------------------------------------------------- /ext/tests/api/engine/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Engine API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_engine_new_with_config'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()); 14 | 15 | $reflection = new ReflectionFunction('wasm_engine_delete'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | ?> 20 | --EXPECTF-- 21 | int(0) 22 | NULL 23 | int(1) 24 | NULL 25 | int(1) 26 | string(4) "bool" 27 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/00-functions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API functions 3 | 4 | --FILE-- 5 | 20 | --EXPECTF-- 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | bool(true) 28 | bool(true) 29 | bool(true) 30 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_new_cranelift_native.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_new (Cranelift, Native) 3 | 4 | --SKIPIF-- 5 | = 8100) print 'skip wasm_module_new (Cranelift, Native) does not work yet on PHP 8.1+'; 8 | 9 | ?> 10 | --FILE-- 11 | 23 | --EXPECTF-- 24 | resource(%d) of type (wasm_module_t) 25 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_vec_extern_offsetExists.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: Wasm\Vec\Extern::offsetExists() 3 | 4 | --FILE-- 5 | offsetExists(0)); 18 | var_dump(isset($vec[1])); 19 | var_dump($vec->offsetExists(1)); 20 | 21 | ?> 22 | --EXPECTF-- 23 | bool(true) 24 | bool(true) 25 | bool(false) 26 | bool(false) 27 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_vec_valtype_offsetSet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: Wasm\Vec\ValType::offsetSet() 3 | 4 | --FILE-- 5 | getMessage()); 19 | } 20 | 21 | ?> 22 | 23 | --EXPECTF-- 24 | resource(%d) of type (wasm_valtype_t) 25 | resource(%d) of type (wasm_valtype_t) 26 | string(56) "Wasm\Vec\ValType::offsetSet($offset) index out of bounds" 27 | -------------------------------------------------------------------------------- /ext/src/api/wasmer.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasmer_wasm.h" 4 | 5 | PHP_FUNCTION(wasmer_version) { 6 | ZEND_PARSE_PARAMETERS_NONE(); 7 | 8 | RETURN_STRING(wasmer_version()); 9 | } 10 | 11 | PHP_FUNCTION(wasmer_version_major) { 12 | ZEND_PARSE_PARAMETERS_NONE(); 13 | 14 | RETURN_LONG(wasmer_version_major()); 15 | } 16 | 17 | PHP_FUNCTION(wasmer_version_minor) { 18 | ZEND_PARSE_PARAMETERS_NONE(); 19 | 20 | RETURN_LONG(wasmer_version_minor()); 21 | } 22 | 23 | PHP_FUNCTION(wasmer_version_patch) { 24 | ZEND_PARSE_PARAMETERS_NONE(); 25 | 26 | RETURN_LONG(wasmer_version_patch()); 27 | } 28 | 29 | PHP_FUNCTION(wasmer_version_pre) { 30 | ZEND_PARSE_PARAMETERS_NONE(); 31 | 32 | RETURN_STRING(wasmer_version_pre()); 33 | } 34 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_call_with_trap.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_call (trap) 3 | 4 | --FILE-- 5 | getMessage()); 25 | } 26 | 27 | ?> 28 | --EXPECTF-- 29 | string(11) "unreachable" 30 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_get_guest.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_get (guest) 3 | 4 | --FILE-- 5 | 26 | --EXPECTF-- 27 | resource(%d) of type (wasm_val_t) 28 | int(42) 29 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/02-wasm_module_new_cranelift_object_file.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API: wasm_module_new (Cranelift, Object File) 3 | 4 | --FILE-- 5 | getMessage()); 18 | } 19 | 20 | ?> 21 | --EXPECTF-- 22 | string(121) "Compilation error: The `ObjectFileEngine` is operating in headless mode, so it can only execute already compiled Modules." 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.lo 2 | *.loT 3 | *.la 4 | .libs 5 | acinclude.m4 6 | aclocal.m4 7 | autom4te.cache 8 | build 9 | cmake-build-debug 10 | config.guess 11 | config.h 12 | config.h.in 13 | config.h.in~ 14 | config.log 15 | config.nice 16 | config.status 17 | config.sub 18 | configure 19 | configure.ac 20 | configure.in 21 | fixes.yml 22 | install-sh 23 | libtool 24 | ltmain.sh 25 | ext/Makefile 26 | Makefile.fragments 27 | Makefile.global 28 | Makefile.objects 29 | missing 30 | mkinstalldirs 31 | modules 32 | replacements.xml 33 | run-tests.php 34 | ext/tests/**/*.diff 35 | ext/tests/**/*.out 36 | ext/tests/**/*.php 37 | ext/tests/**/*.exp 38 | ext/tests/**/*.log 39 | ext/tests/**/*.sh 40 | /vendor 41 | /target 42 | /.php_cs.cache 43 | /.phpunit.result.cache 44 | composer.lock 45 | -------------------------------------------------------------------------------- /ext/src/api/types/valkind.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasm.h" 4 | 5 | PHP_FUNCTION (wasm_valkind_is_num) { 6 | zval *valkind_val; 7 | 8 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 9 | Z_PARAM_NUMBER(valkind_val) 10 | ZEND_PARSE_PARAMETERS_END(); 11 | 12 | int valkind = zval_get_long(valkind_val); 13 | 14 | RETURN_BOOL(wasm_valkind_is_num(valkind)); 15 | } 16 | 17 | PHP_FUNCTION (wasm_valkind_is_ref) { 18 | zval *valkind_val; 19 | 20 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 21 | Z_PARAM_NUMBER(valkind_val) 22 | ZEND_PARSE_PARAMETERS_END(); 23 | 24 | int valkind = zval_get_long(valkind_val); 25 | 26 | RETURN_BOOL(wasm_valkind_is_ref(valkind)); 27 | } 28 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/02-wasm_vec_valtype___construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API: Wasm\Vec\ValType::construct() 3 | 4 | --FILE-- 5 | 23 | --EXPECTF-- 24 | object(Wasm\Vec\ValType)#%d (%d) { 25 | } 26 | int(0) 27 | object(Wasm\Vec\ValType)#%d (%d) { 28 | } 29 | int(2) 30 | object(Wasm\Vec\ValType)#%d (%d) { 31 | } 32 | int(3) 33 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_vec_functype_offsetGet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: Wasm\Vec\FuncType::offsetGet() 3 | 4 | --FILE-- 5 | getMessage()); 17 | } 18 | 19 | ?> 20 | --EXPECTF-- 21 | resource(%d) of type (wasm_functype_t) 22 | resource(%d) of type (wasm_functype_t) 23 | string(57) "Wasm\Vec\FuncType::offsetGet($offset) index out of bounds" 24 | -------------------------------------------------------------------------------- /ext/src/api/store.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasm.h" 4 | 5 | #include "./macros.h" 6 | #include "../wasm.h" 7 | 8 | WASMER_DECLARE_OWN(store) 9 | 10 | WASMER_IMPORT_RESOURCE(engine) 11 | 12 | PHP_FUNCTION (wasm_store_new) { 13 | zval *engine_val; 14 | 15 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 16 | Z_PARAM_RESOURCE(engine_val) 17 | ZEND_PARSE_PARAMETERS_END(); 18 | 19 | WASMER_FETCH_RESOURCE(engine) 20 | 21 | wasmer_res *store = emalloc(sizeof(wasmer_res)); 22 | store->inner.store = wasm_store_new(WASMER_RES_P_INNER(engine_val, engine)); 23 | store->owned = true; 24 | 25 | zend_resource *store_res; 26 | store_res = zend_register_resource(store, le_wasm_store); 27 | 28 | RETURN_RES(store_res); 29 | } 30 | -------------------------------------------------------------------------------- /ext/tests/exceptions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Wasmer PHP - Exceptions 3 | 4 | --FILE-- 5 | 20 | --EXPECTF-- 21 | bool(true) 22 | bool(true) 23 | bool(true) 24 | bool(true) 25 | bool(true) 26 | bool(true) 27 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_vec_tabletype_offsetSet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: Wasm\Vec\TableType::offsetSet() 3 | 4 | --FILE-- 5 | getMessage()); 19 | } 20 | 21 | ?> 22 | --EXPECTF-- 23 | resource(%d) of type (wasm_tabletype_t) 24 | resource(%d) of type (wasm_tabletype_t) 25 | string(58) "Wasm\Vec\TableType::offsetSet($offset) index out of bounds" 26 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_set_host.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_set (host) 3 | 4 | --FILE-- 5 | getMessage()); 22 | } 23 | 24 | ?> 25 | --EXPECTF-- 26 | int(42) 27 | string(50) "RuntimeError: Attempted to set an immutable global" 28 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_vec_globaltype_offsetGet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: Wasm\Vec\GlobalType::offsetGet() 3 | 4 | --FILE-- 5 | getMessage()); 19 | } 20 | 21 | ?> 22 | --EXPECTF-- 23 | resource(%d) of type (wasm_globaltype_t) 24 | resource(%d) of type (wasm_globaltype_t) 25 | string(59) "Wasm\Vec\GlobalType::offsetGet($offset) index out of bounds" 26 | -------------------------------------------------------------------------------- /ext/src/wasmer_class.stub.php: -------------------------------------------------------------------------------- 1 | getMessage()); 20 | } 21 | 22 | ?> 23 | --EXPECTF-- 24 | resource(%d) of type (wasm_functype_t) 25 | resource(%d) of type (wasm_functype_t) 26 | string(57) "Wasm\Vec\FuncType::offsetSet($offset) index out of bounds" 27 | -------------------------------------------------------------------------------- /ext/tests/api/objects/val/02-wasm_vec_val___construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Val API: Wasm\Vec\Val::construct() 3 | 4 | --FILE-- 5 | 24 | --EXPECTF-- 25 | object(Wasm\Vec\Val)#%d (%d) { 26 | } 27 | int(0) 28 | object(Wasm\Vec\Val)#%d (%d) { 29 | } 30 | int(2) 31 | object(Wasm\Vec\Val)#%d (%d) { 32 | } 33 | int(3) 34 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_vec_globaltype_offsetSet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: Wasm\Vec\GlobalType::offsetSet() 3 | 4 | --FILE-- 5 | getMessage()); 22 | } 23 | 24 | ?> 25 | --EXPECTF-- 26 | resource(%d) of type (wasm_globaltype_t) 27 | resource(%d) of type (wasm_globaltype_t) 28 | string(59) "Wasm\Vec\GlobalType::offsetSet($offset) index out of bounds" 29 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_extern_kind.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: wasm_extern_kind 3 | 4 | --FILE-- 5 | 24 | --EXPECTF-- 25 | bool(true) 26 | bool(true) 27 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_vec_tabletype_offsetGet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: Wasm\Vec\TableType::offsetGet() 3 | 4 | --FILE-- 5 | getMessage()); 21 | } 22 | 23 | ?> 24 | --EXPECTF-- 25 | resource(%d) of type (wasm_tabletype_t) 26 | resource(%d) of type (wasm_tabletype_t) 27 | string(58) "Wasm\Vec\TableType::offsetGet($offset) index out of bounds" 28 | -------------------------------------------------------------------------------- /phpdoc.dist.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | Wasmer PHP 9 | 10 | target/doc 11 | target/cache/phpdocumentor 12 | 13 | 14 | 15 | 16 | ext/src 17 | src 18 | 19 | public 20 | 21 | TODO 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/02-wasm_vec_functype___construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API: Wasm\Vec\FuncType::construct() 3 | 4 | --FILE-- 5 | 24 | --EXPECTF-- 25 | object(Wasm\Vec\FuncType)#%d (%d) { 26 | } 27 | int(0) 28 | object(Wasm\Vec\FuncType)#%d (%d) { 29 | } 30 | int(2) 31 | object(Wasm\Vec\FuncType)#%d (%d) { 32 | } 33 | int(3) 34 | -------------------------------------------------------------------------------- /ext/tests/api/types/memorytype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | MemoryType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_memorytype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_memorytype_limits'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()); 18 | 19 | $reflection = new ReflectionFunction('wasm_memorytype_copy'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()); 22 | 23 | ?> 24 | --EXPECTF-- 25 | int(1) 26 | NULL 27 | int(1) 28 | string(4) "bool" 29 | int(1) 30 | NULL 31 | int(1) 32 | NULL 33 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/02-wasm_vec_globaltype___construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API: Wasm\Vec\GlobalType::construct() 3 | 4 | --FILE-- 5 | 24 | --EXPECTF-- 25 | object(Wasm\Vec\GlobalType)#%d (%d) { 26 | } 27 | int(0) 28 | object(Wasm\Vec\GlobalType)#%d (%d) { 29 | } 30 | int(2) 31 | object(Wasm\Vec\GlobalType)#%d (%d) { 32 | } 33 | int(3) 34 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - 'master' 8 | 9 | jobs: 10 | test: 11 | name: Lint 12 | runs-on: ubuntu-18.04 13 | steps: 14 | - name: Setup PHP 15 | uses: shivammathur/setup-php@v2 16 | with: 17 | php-version: 8.0 18 | - name: Checkout code 19 | uses: actions/checkout@v2 20 | - name: Get Composer Cache Directory 21 | id: composer-cache 22 | run: | 23 | echo "::set-output name=dir::$(composer config cache-files-dir)" 24 | - uses: actions/cache@v2 25 | with: 26 | path: ${{ steps.composer-cache.outputs.dir }} 27 | key: 8-composer-${{ hashFiles('**/composer.json') }} 28 | - name: Configure 29 | run: | 30 | cd ext 31 | phpize 32 | ./configure 33 | - name: Lint PHP 34 | run: | 35 | make lint 36 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_extern_as_global.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: wasm_extern_as_global 3 | 4 | --FILE-- 5 | getMessage()); 23 | } 24 | 25 | ?> 26 | --EXPECTF-- 27 | resource(%d) of type (wasm_global_t) 28 | string(34) "Unable to convert extern to global" 29 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/02-wasm_vec_tabletype___construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API: Wasm\Vec\TableType::construct() 3 | 4 | --FILE-- 5 | 24 | --EXPECTF-- 25 | object(Wasm\Vec\TableType)#%d (%d) { 26 | } 27 | int(0) 28 | object(Wasm\Vec\TableType)#%d (%d) { 29 | } 30 | int(2) 31 | object(Wasm\Vec\TableType)#%d (%d) { 32 | } 33 | int(3) 34 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_extern_as_func.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: wasm_extern_as_func 3 | 4 | --FILE-- 5 | getMessage()); 24 | } 25 | 26 | ?> 27 | --EXPECTF-- 28 | resource(%d) of type (wasm_func_t) 29 | string(32) "Unable to convert extern to func" 30 | -------------------------------------------------------------------------------- /ext/tests/api/objects/instance/02-wasm_instance_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Instance API: wasm_instance_new 3 | 4 | --FILE-- 5 | getMessage()); 26 | } 27 | 28 | 29 | ?> 30 | --EXPECTF-- 31 | resource(%d) of type (wasm_instance_t) 32 | string(115) "Error while importing ""."print": unknown import. Expected Function(FunctionType { params: [I32], results: [I32] })" 33 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | src 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | tests/unit 16 | 17 | 18 | tests/examples/Callback.php 19 | tests/examples/Globl.php 20 | tests/examples/Hello.php 21 | 22 | 23 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_call_host.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_call (host) 3 | 4 | --SKIPIF-- 5 | 10 | --FILE-- 11 | 35 | --EXPECTF-- 36 | string(22) "Hello from PHP closure" 37 | -------------------------------------------------------------------------------- /ext/src/api/wat.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasmer_wasm.h" 5 | 6 | #include "macros.h" 7 | 8 | extern zend_class_entry *wasm_exception_runtime_ce; 9 | 10 | PHP_FUNCTION (wat2wasm) { 11 | char *wat; 12 | size_t wat_len; 13 | 14 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 15 | Z_PARAM_STRING(wat, wat_len) 16 | ZEND_PARSE_PARAMETERS_END(); 17 | 18 | wasm_byte_vec_t *wat_vec = emalloc(sizeof(wasm_byte_vec_t)); 19 | wat_vec->size = wat_len; 20 | wat_vec->data = wat; 21 | 22 | wasm_byte_vec_t *wasm_vec = emalloc(sizeof(wasm_byte_vec_t));; 23 | wat2wasm(wat_vec, wasm_vec); 24 | 25 | WASMER_HANDLE_ERROR_START 26 | efree(wat_vec); 27 | efree(wasm_vec); 28 | WASMER_HANDLE_ERROR_END(wasm_exception_runtime_ce) 29 | 30 | char *wasm = wasm_vec->data; 31 | int length = wasm_vec->size; 32 | 33 | efree(wat_vec); 34 | efree(wasm_vec); 35 | 36 | RETURN_STRINGL(wasm, length); 37 | } 38 | -------------------------------------------------------------------------------- /ext/tests/api/objects/global/02-wasm_global_set_guest.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Global API: wasm_global_set (guest) 3 | 4 | --FILE-- 5 | getMessage()); 30 | } 31 | 32 | ?> 33 | --EXPECTF-- 34 | int(42) 35 | string(50) "RuntimeError: Attempted to set an immutable global" 36 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_vec_extern_offsetGet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: Wasm\Vec\Extern::offsetGet() 3 | 4 | --FILE-- 5 | getMessage()); 24 | } 25 | 26 | ?> 27 | --EXPECTF-- 28 | resource(%d) of type (wasm_extern_t) 29 | resource(%d) of type (wasm_extern_t) 30 | string(55) "Wasm\Vec\Extern::offsetGet($offset) index out of bounds" 31 | -------------------------------------------------------------------------------- /ext/tests/api/types/tabletype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | TableType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_tabletype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_tabletype_element'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()); 18 | 19 | $reflection = new ReflectionFunction('wasm_tabletype_limits'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()); 22 | 23 | $reflection = new ReflectionFunction('wasm_tabletype_copy'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | ?> 28 | --EXPECTF-- 29 | int(2) 30 | NULL 31 | int(1) 32 | string(4) "bool" 33 | int(1) 34 | NULL 35 | int(1) 36 | NULL 37 | int(1) 38 | NULL 39 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_call_guest.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_call (guest) 3 | 4 | --FILE-- 5 | getMessage()); 32 | } 33 | 34 | ?> 35 | --EXPECTF-- 36 | object(Wasm\Vec\Val)#%d (0) { 37 | } 38 | int(1) 39 | resource(%d) of type (wasm_val_t) 40 | int(42) 41 | string(11) "unreachable" 42 | -------------------------------------------------------------------------------- /ext/tests/api/objects/trap/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Trap API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_trap_copy'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()); 14 | 15 | $reflection = new ReflectionFunction('wasm_trap_message'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_trap_origin'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()); 22 | 23 | $reflection = new ReflectionFunction('wasm_trap_trace'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()->getName()); 26 | 27 | ?> 28 | --EXPECTF-- 29 | int(2) 30 | NULL 31 | int(1) 32 | NULL 33 | int(1) 34 | string(6) "string" 35 | int(1) 36 | NULL 37 | int(1) 38 | string(14) "Wasm\Vec\Frame" 39 | -------------------------------------------------------------------------------- /ext/tests/api/types/exporttype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExportType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_exporttype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_exporttype_name'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_exporttype_type'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()); 22 | 23 | $reflection = new ReflectionFunction('wasm_exporttype_copy'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | ?> 28 | --EXPECTF-- 29 | int(2) 30 | NULL 31 | int(1) 32 | string(4) "bool" 33 | int(1) 34 | string(6) "string" 35 | int(1) 36 | NULL 37 | int(1) 38 | NULL 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-present Wasmer, Inc. and its affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ext/tests/api/types/valkind/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValKind API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_valtype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_valtype_kind'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_valtype_is_num'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()->getName()); 22 | 23 | $reflection = new ReflectionFunction('wasm_valtype_is_ref'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()->getName()); 26 | 27 | ?> 28 | --EXPECTF-- 29 | int(1) 30 | NULL 31 | int(1) 32 | string(4) "bool" 33 | int(1) 34 | string(3) "int" 35 | int(1) 36 | string(4) "bool" 37 | int(1) 38 | string(4) "bool" 39 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wasm/wasm", 3 | "description": "A complete and mature WebAssembly runtime for PHP based on Wasmer", 4 | "type": "library", 5 | "require": { 6 | "ext-wasm": "^1.0.0" 7 | }, 8 | "require-dev": { 9 | "phpdocumentor/phpdocumentor": "@dev", 10 | "phpdocumentor/flyfinder": "@dev", 11 | "friendsofphp/php-cs-fixer": "@dev", 12 | "phpunit/phpunit": "@dev" 13 | }, 14 | "minimum-stability": "dev", 15 | "license": "MIT", 16 | "authors": [ 17 | { 18 | "name": "Wasmer Engineering Team", 19 | "email": "engineering@wasmer.io" 20 | } 21 | ], 22 | "config": { 23 | "platform": { 24 | "ext-wasm": "1.0.0" 25 | }, 26 | "cache-dir": "target/cache/composer" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "Wasm\\": "src" 31 | } 32 | }, 33 | "replace": { 34 | "php-wasm/php-wasm": "*" 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Wasm\\Tests\\": "tests/unit", 39 | "Wasm\\Examples\\": "tests/examples" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/instance.php: -------------------------------------------------------------------------------- 1 | exports(); 34 | $addOne = (new Wasm\Extern($exports[0]))->asFunc(); 35 | 36 | $arg = Wasm\Val::newI32(1); 37 | $args = new Wasm\Vec\Val([$arg->inner()]); 38 | 39 | echo 'Calling `add_one` function...'.PHP_EOL; 40 | $result = $addOne($args); 41 | 42 | echo 'Results of `add_one`: '.((new Wasm\Val($result[0]))->value()).PHP_EOL; 43 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()->getName()); 10 | 11 | $reflection = new ReflectionFunction('wasm_extern_type'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()); 14 | 15 | $reflection = new ReflectionFunction('wasm_extern_as_func'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()); 18 | 19 | $reflection = new ReflectionFunction('wasm_extern_as_global'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()); 22 | 23 | $reflection = new ReflectionFunction('wasm_extern_as_table'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | $reflection = new ReflectionFunction('wasm_extern_as_memory'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()); 30 | 31 | ?> 32 | --EXPECTF-- 33 | int(1) 34 | string(3) "int" 35 | int(1) 36 | NULL 37 | int(1) 38 | NULL 39 | int(1) 40 | NULL 41 | int(1) 42 | NULL 43 | int(1) 44 | NULL 45 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_vec_extern_offsetSet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: Wasm\Vec\Extern::offsetSet() 3 | 4 | --FILE-- 5 | getMessage()); 29 | } 30 | 31 | ?> 32 | --EXPECTF-- 33 | resource(%d) of type (wasm_extern_t) 34 | resource(%d) of type (wasm_extern_t) 35 | string(55) "Wasm\Vec\Extern::offsetSet($offset) index out of bounds" 36 | -------------------------------------------------------------------------------- /ext/config.m4: -------------------------------------------------------------------------------- 1 | dnl config.m4 for extension Wasm 2 | 3 | PHP_ARG_ENABLE(wasm, whether to enable Wasm support, 4 | AS_HELP_STRING(--enable-wasm, Enable Wasm support)) 5 | 6 | if test "$PHP_WASM" != "no"; then 7 | AC_DEFINE(HAVE_WASM, 1, [ Have Wasm support ]) 8 | 9 | PHP_SUBST(WASM_SHARED_LIBADD) 10 | PHP_ADD_LIBRARY_WITH_PATH(wasmer, ./lib, WASM_SHARED_LIBADD) 11 | 12 | WASMER_API="src/api/config.c src/api/engine.c src/api/store.c src/api/wasmer.c src/api/wat.c" 13 | WASMER_API_OBJECTS="src/api/objects/extern.c src/api/objects/foreign.c src/api/objects/func.c src/api/objects/frame.c src/api/objects/global.c src/api/objects/instance.c src/api/objects/memory.c src/api/objects/module.c src/api/objects/table.c src/api/objects/trap.c src/api/objects/val.c" 14 | WASMER_API_TYPES="src/api/types/exporttype.c src/api/types/externtype.c src/api/types/functype.c src/api/types/globaltype.c src/api/types/importtype.c src/api/types/limits.c src/api/types/memorytype.c src/api/types/tabletype.c src/api/types/valkind.c src/api/types/valtype.c" 15 | WASMER_SOURCES="src/wasm.c" 16 | WASMER_ALL_SOURCES="${WASMER_API} ${WASMER_API_OBJECTS} ${WASMER_API_TYPES} ${WASMER_SOURCES}" 17 | 18 | PHP_NEW_EXTENSION(wasm, $WASMER_ALL_SOURCES, $ext_shared,, $WASMER_CFLAGS) 19 | 20 | PHP_ADD_MAKEFILE_FRAGMENT 21 | fi 22 | -------------------------------------------------------------------------------- /examples/exports-function.php: -------------------------------------------------------------------------------- 1 | exports(); 34 | $sum = (new Wasm\Extern($exports[0]))->asFunc(); 35 | 36 | $firstArg = Wasm\Val::newI32(1); 37 | $secondArg = Wasm\Val::newI32(2); 38 | $args = new Wasm\Vec\Val([$firstArg->inner(), $secondArg->inner()]); 39 | 40 | echo 'Calling `sum` function...'.PHP_EOL; 41 | $result = $sum($args); 42 | 43 | echo 'Results of `sum`: '.((new Wasm\Val($result[0]))->value()).PHP_EOL; 44 | -------------------------------------------------------------------------------- /ext/tests/api/types/globaltype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | GlobalType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_globaltype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_globaltype_content'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()); 18 | 19 | $reflection = new ReflectionFunction('wasm_globaltype_mutability'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()->getName()); 22 | 23 | $reflection = new ReflectionFunction('wasm_globaltype_copy'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | $reflection = new ReflectionFunction('wasm_globaltype_as_externtype'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()); 30 | 31 | ?> 32 | --EXPECTF-- 33 | int(2) 34 | NULL 35 | int(1) 36 | string(4) "bool" 37 | int(1) 38 | NULL 39 | int(1) 40 | string(3) "int" 41 | int(1) 42 | NULL 43 | int(1) 44 | NULL 45 | -------------------------------------------------------------------------------- /ext/tests/api/types/valtype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ValType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_valtype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_valtype_kind'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_valtype_is_num'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()->getName()); 22 | 23 | $reflection = new ReflectionFunction('wasm_valtype_is_ref'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()->getName()); 26 | 27 | $reflection = new ReflectionFunction('wasm_valtype_copy'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()); 30 | 31 | ?> 32 | --EXPECTF-- 33 | int(1) 34 | NULL 35 | int(1) 36 | string(4) "bool" 37 | int(1) 38 | string(3) "int" 39 | int(1) 40 | string(4) "bool" 41 | int(1) 42 | string(4) "bool" 43 | int(1) 44 | NULL 45 | -------------------------------------------------------------------------------- /ext/tests/api/objects/extern/02-wasm_vec_extern___construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extern API: Wasm\Vec\Extern::construct() 3 | 4 | --FILE-- 5 | 33 | --EXPECTF-- 34 | object(Wasm\Vec\Extern)#%d (%d) { 35 | } 36 | int(0) 37 | object(Wasm\Vec\Extern)#%d (%d) { 38 | } 39 | int(2) 40 | object(Wasm\Vec\Extern)#%d (%d) { 41 | } 42 | int(3) 43 | -------------------------------------------------------------------------------- /ext/tests/api/types/externtype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ExternType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()->getName()); 10 | 11 | $reflection = new ReflectionFunction('wasm_externtype_kind'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_externtype_as_functype'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()); 18 | 19 | $reflection = new ReflectionFunction('wasm_externtype_as_globaltype'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()); 22 | 23 | $reflection = new ReflectionFunction('wasm_externtype_as_memorytype'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | $reflection = new ReflectionFunction('wasm_externtype_as_tabletype'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()); 30 | 31 | ?> 32 | --EXPECTF-- 33 | int(1) 34 | string(4) "bool" 35 | int(1) 36 | string(3) "int" 37 | int(1) 38 | NULL 39 | int(1) 40 | NULL 41 | int(1) 42 | NULL 43 | int(1) 44 | NULL 45 | -------------------------------------------------------------------------------- /ext/tests/api/types/importtype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ImportType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_importtype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_importtype_module'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_importtype_name'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()->getName()); 22 | 23 | $reflection = new ReflectionFunction('wasm_importtype_type'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | $reflection = new ReflectionFunction('wasm_importtype_copy'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()); 30 | 31 | ?> 32 | --EXPECTF-- 33 | int(3) 34 | NULL 35 | int(1) 36 | string(4) "bool" 37 | int(1) 38 | string(6) "string" 39 | int(1) 40 | string(6) "string" 41 | int(1) 42 | NULL 43 | int(1) 44 | NULL 45 | -------------------------------------------------------------------------------- /ext/tests/api/types/functype/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FuncType API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_functype_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_functype_params'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_functype_results'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()->getName()); 22 | 23 | $reflection = new ReflectionFunction('wasm_functype_copy'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()); 26 | 27 | $reflection = new ReflectionFunction('wasm_functype_as_externtype'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()); 30 | 31 | ?> 32 | --EXPECTF-- 33 | int(2) 34 | NULL 35 | int(1) 36 | string(4) "bool" 37 | int(1) 38 | string(16) "Wasm\Vec\ValType" 39 | int(1) 40 | string(16) "Wasm\Vec\ValType" 41 | int(1) 42 | NULL 43 | int(1) 44 | NULL 45 | -------------------------------------------------------------------------------- /ext/Makefile.frag: -------------------------------------------------------------------------------- 1 | ## Targets from this Makefile are available from the top-level Makefile using the `ext/` prefix. 2 | 3 | .PHONY: examples 4 | .SILENT: examples 5 | examples: ## Run PHP module examples 6 | examples: all 7 | FAILURES=(); \ 8 | for EXAMPLE in examples/*.php; \ 9 | do \ 10 | echo "====================================================================="; \ 11 | echo "> Running $$EXAMPLE"; \ 12 | echo "---------------------------------------------------------------------"; \ 13 | if ! $(PHP_EXECUTABLE) $(PHP_TEST_SETTINGS) -d extension_dir=$(top_builddir)/modules/ $(PHP_TEST_SHARED_EXTENSIONS) $$EXAMPLE; \ 14 | then \ 15 | FAILURES+=($$EXAMPLE); \ 16 | fi; \ 17 | echo; \ 18 | done; \ 19 | if [ $${#FAILURES[@]} -gt 0 ]; \ 20 | then \ 21 | echo "====================================================================="; \ 22 | echo "> Failed examples summary"; \ 23 | echo "---------------------------------------------------------------------"; \ 24 | for FAILURE in $${FAILURES[@]}; \ 25 | do \ 26 | echo "* $$FAILURE"; \ 27 | done; \ 28 | echo; \ 29 | exit $${#FAILURES[@]}; \ 30 | fi; 31 | 32 | all: ## Build PHP module 33 | all: src/wasmer_root_arginfo.h src/wasmer_vec_arginfo.h src/wasmer_exception_arginfo.h src/wasmer_class_arginfo.h 34 | 35 | test: ## Run PHP module tests 36 | 37 | configure: ## Configure PHP module build system (use PHP_HOME to change the PHP binaries to use) 38 | -------------------------------------------------------------------------------- /src/Engine.php: -------------------------------------------------------------------------------- 1 | inner = $engine; 29 | } 30 | 31 | public function __destruct() 32 | { 33 | try { 34 | \wasm_engine_delete($this->inner); 35 | } catch (\TypeError $error) { 36 | if (is_resource($this->inner)) { 37 | throw $error; 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * @return resource 44 | */ 45 | public function inner() 46 | { 47 | return $this->inner; 48 | } 49 | 50 | /** 51 | * @api 52 | * 53 | * @throw Exception\InvalidArgumentException If the `$kind` is not a valid value kind 54 | */ 55 | public static function new(?Config $config = null): self 56 | { 57 | return new self($config ? \wasm_engine_new_with_config($config->inner()) : \wasm_engine_new()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ext/examples/hello.php: -------------------------------------------------------------------------------- 1 | Hello World!'.PHP_EOL; 20 | 21 | return null; 22 | } 23 | 24 | $functype = wasm_functype_new(new Wasm\Vec\ValType(), new Wasm\Vec\ValType()); 25 | $func = wasm_func_new($store, $functype, 'hello_callback'); 26 | wasm_functype_delete($functype); 27 | 28 | echo 'Instantiating module...'.PHP_EOL; 29 | $extern = wasm_func_as_extern($func); 30 | $externs = new Wasm\Vec\Extern([$extern]); 31 | $instance = wasm_instance_new($store, $module, $externs); 32 | 33 | wasm_func_delete($func); 34 | 35 | echo 'Extracting export...'.PHP_EOL; 36 | $exports = wasm_instance_exports($instance); 37 | $run = wasm_extern_as_func($exports[0]); 38 | 39 | wasm_module_delete($module); 40 | wasm_instance_delete($instance); 41 | 42 | echo 'Calling export...'.PHP_EOL; 43 | $args = new Wasm\Vec\Val(); 44 | $results = wasm_func_call($run, $args); 45 | 46 | echo 'Shutting down...'.PHP_EOL; 47 | wasm_store_delete($store); 48 | wasm_engine_delete($engine); 49 | -------------------------------------------------------------------------------- /src/Store.php: -------------------------------------------------------------------------------- 1 | inner = $store; 31 | } 32 | 33 | public function __destruct() 34 | { 35 | try { 36 | \wasm_store_delete($this->inner); 37 | } catch (\TypeError $error) { 38 | if (is_resource($this->inner)) { 39 | throw $error; 40 | } 41 | } 42 | } 43 | 44 | /** 45 | * @return resource 46 | */ 47 | public function inner() 48 | { 49 | return $this->inner; 50 | } 51 | 52 | /** 53 | * @api 54 | */ 55 | public static function new(Engine $engine): self 56 | { 57 | return new self(\wasm_store_new($engine->inner())); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ext/src/api/engine.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasmer_wasm.h" 5 | 6 | #include "./macros.h" 7 | #include "../wasm.h" 8 | 9 | WASMER_DECLARE_OWN(engine) 10 | 11 | WASMER_IMPORT_RESOURCE(config) 12 | 13 | extern zend_class_entry *wasm_exception_runtime_ce; 14 | 15 | PHP_FUNCTION (wasm_engine_new) { 16 | ZEND_PARSE_PARAMETERS_NONE(); 17 | 18 | wasmer_res *engine = emalloc(sizeof(wasmer_res)); 19 | engine->inner.engine = wasm_engine_new(); 20 | engine->owned = true; 21 | 22 | zend_resource *engine_res = zend_register_resource(engine, le_wasm_engine); 23 | 24 | RETURN_RES(engine_res); 25 | } 26 | 27 | PHP_FUNCTION (wasm_engine_new_with_config) { 28 | zval *config_val; 29 | 30 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 31 | Z_PARAM_RESOURCE(config_val) 32 | ZEND_PARSE_PARAMETERS_END(); 33 | 34 | WASMER_FETCH_RESOURCE(config) 35 | 36 | wasmer_res *engine = emalloc(sizeof(wasmer_res)); 37 | engine->inner.engine = wasm_engine_new_with_config(WASMER_RES_P_INNER(config_val, config)); 38 | engine->owned = true; 39 | 40 | WASMER_RES_P(config_val)->owned = false; 41 | 42 | WASMER_HANDLE_ERROR_START 43 | efree(engine); 44 | WASMER_HANDLE_ERROR_END(wasm_exception_runtime_ce) 45 | 46 | zend_resource *engine_res; 47 | engine_res = zend_register_resource(engine, le_wasm_engine); 48 | 49 | RETURN_RES(engine_res); 50 | } 51 | -------------------------------------------------------------------------------- /examples/errors.php: -------------------------------------------------------------------------------- 1 | exports(); 37 | $divByZero = (new Wasm\Extern($exports[0]))->asFunc(); 38 | 39 | echo 'Calling `div_by_zero` function...'.PHP_EOL; 40 | 41 | try { 42 | $result = $divByZero(); 43 | 44 | echo '`div_by_zero` did not error'.PHP_EOL; 45 | 46 | exit(1); 47 | } catch (Exception $exception) { 48 | echo 'Error caught from `div_by_zero`: '.$exception->getMessage().PHP_EOL; 49 | } 50 | -------------------------------------------------------------------------------- /ext/src/api/objects/table.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasm.h" 4 | 5 | #include "../macros.h" 6 | 7 | WASMER_IMPORT_RESOURCE(table) 8 | 9 | PHP_FUNCTION (wasm_table_new) { 10 | ZEND_PARSE_PARAMETERS_NONE(); 11 | 12 | // TODO(jubianchi): Implement 13 | zend_throw_error(NULL, "Not yet implemented"); 14 | } 15 | 16 | WASMER_DELETE_RESOURCE(table) 17 | 18 | PHP_FUNCTION (wasm_table_type) { 19 | ZEND_PARSE_PARAMETERS_NONE(); 20 | 21 | // TODO(jubianchi): Implement 22 | zend_throw_error(NULL, "Not yet implemented"); 23 | } 24 | 25 | PHP_FUNCTION (wasm_table_get) { 26 | ZEND_PARSE_PARAMETERS_NONE(); 27 | 28 | // TODO(jubianchi): Implement 29 | zend_throw_error(NULL, "Not yet implemented"); 30 | } 31 | 32 | PHP_FUNCTION (wasm_table_set) { 33 | ZEND_PARSE_PARAMETERS_NONE(); 34 | 35 | // TODO(jubianchi): Implement 36 | zend_throw_error(NULL, "Not yet implemented"); 37 | } 38 | 39 | PHP_FUNCTION (wasm_table_size) { 40 | ZEND_PARSE_PARAMETERS_NONE(); 41 | 42 | // TODO(jubianchi): Implement 43 | zend_throw_error(NULL, "Not yet implemented"); 44 | } 45 | 46 | PHP_FUNCTION (wasm_table_grow) { 47 | ZEND_PARSE_PARAMETERS_NONE(); 48 | 49 | // TODO(jubianchi): Implement 50 | zend_throw_error(NULL, "Not yet implemented"); 51 | } 52 | 53 | // TODO(jubianchi): Implement copy 54 | 55 | PHP_FUNCTION (wasm_table_as_extern) { 56 | ZEND_PARSE_PARAMETERS_NONE(); 57 | 58 | // TODO(jubianchi): Implement 59 | zend_throw_error(NULL, "Not yet implemented"); 60 | } 61 | -------------------------------------------------------------------------------- /tests/examples/Hello.php: -------------------------------------------------------------------------------- 1 | module('wasm')); 28 | 29 | // Compiling module... 30 | $module = Wasm\Module::new($store, $wasm); 31 | 32 | $functype = Wasm\Type\FuncType::new(new Wasm\Vec\ValType(), new Wasm\Vec\ValType()); 33 | $func = Wasm\Func::new($store, $functype, [self::class, 'hello_callback']); 34 | 35 | // Instantiating module... 36 | $extern = $func->asExtern(); 37 | $externs = new Wasm\Vec\Extern([$extern->inner()]); 38 | $instance = Wasm\Instance::new($store, $module, $externs); 39 | 40 | // Extracting export... 41 | $exports = $instance->exports(); 42 | $run = (new Wasm\Extern($exports[0]))->asFunc(); 43 | 44 | // Calling export... 45 | $args = new Wasm\Vec\Val(); 46 | $run($args); 47 | 48 | self::assertTrue(self::$called, 'Callback was not called'); 49 | } 50 | 51 | public static function hello_callback(): void 52 | { 53 | self::$called = true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /.github/workflows/doc.yaml: -------------------------------------------------------------------------------- 1 | name: Documentation 2 | 3 | on: 4 | pull_request: 5 | branches-ignore: 6 | - '**' 7 | push: 8 | branches-ignore: 9 | - '**' 10 | tags-ignore: 11 | - '**' 12 | 13 | jobs: 14 | test: 15 | name: Documentation 16 | runs-on: ubuntu-18.04 17 | steps: 18 | - name: Setup PHP 19 | uses: shivammathur/setup-php@v2 20 | with: 21 | php-version: 8.0 22 | - name: Checkout code 23 | uses: actions/checkout@v2 24 | - name: Get Composer Cache Directory 25 | id: composer-cache 26 | run: | 27 | echo "::set-output name=dir::$(composer config cache-files-dir)" 28 | - uses: actions/cache@v2 29 | with: 30 | path: ${{ steps.composer-cache.outputs.dir }} 31 | key: 7.4-composer-${{ hashFiles('**/composer.json') }} 32 | - name: Configure 33 | run: | 34 | cd ext 35 | phpize 36 | ./configure 37 | - name: Build 38 | run: | 39 | make documentation 40 | - name: Publish 41 | if: github.ref == 'refs/heads/master' 42 | uses: peaceiris/actions-gh-pages@v3 43 | with: 44 | github_token: ${{ secrets.GITHUB_TOKEN }} 45 | publish_dir: ./target/doc 46 | - name: Archive 47 | if: github.ref != 'refs/heads/master' 48 | uses: actions/upload-artifact@v2 49 | with: 50 | name: documentation 51 | retention-days: 3 52 | path: | 53 | ./target/doc 54 | -------------------------------------------------------------------------------- /ext/src/api/config.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasmer_wasm.h" 4 | 5 | #include "./macros.h" 6 | #include "../wasm.h" 7 | 8 | WASMER_DECLARE_OWN(config) 9 | 10 | PHP_FUNCTION (wasm_config_new) { 11 | ZEND_PARSE_PARAMETERS_NONE(); 12 | 13 | wasmer_res *config = emalloc(sizeof(wasmer_res)); 14 | config->inner.config = wasm_config_new(); 15 | config->owned = true; 16 | 17 | zend_resource *config_res = zend_register_resource(config, le_wasm_config); 18 | 19 | RETURN_RES(config_res); 20 | } 21 | 22 | PHP_FUNCTION (wasm_config_set_compiler) { 23 | zval *config_val; 24 | zval *compiler_val; 25 | 26 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 2, 2) 27 | Z_PARAM_RESOURCE(config_val) 28 | Z_PARAM_NUMBER(compiler_val) 29 | ZEND_PARSE_PARAMETERS_END(); 30 | 31 | WASMER_FETCH_RESOURCE(config) 32 | 33 | int compiler = zval_get_long(compiler_val); 34 | wasm_config_set_compiler(WASMER_RES_P_INNER(config_val, config), compiler); 35 | 36 | RETURN_TRUE; 37 | } 38 | 39 | PHP_FUNCTION (wasm_config_set_engine) { 40 | zval *config_val; 41 | zval *engine_val; 42 | 43 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 2, 2) 44 | Z_PARAM_RESOURCE(config_val) 45 | Z_PARAM_NUMBER(engine_val) 46 | ZEND_PARSE_PARAMETERS_END(); 47 | 48 | WASMER_FETCH_RESOURCE(config) 49 | 50 | int engine = zval_get_long(engine_val); 51 | wasm_config_set_engine(WASMER_RES_P_INNER(config_val, config), engine); 52 | 53 | RETURN_TRUE; 54 | } 55 | -------------------------------------------------------------------------------- /ext/src/api/types/limits.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "wasm.h" 4 | 5 | #include "../macros.h" 6 | #include "../../wasm.h" 7 | 8 | WASMER_IMPORT_RESOURCE(limits) 9 | 10 | PHP_FUNCTION (wasm_limits_new) { 11 | zval *min_val; 12 | zval *max_val; 13 | 14 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 2, 2) 15 | Z_PARAM_LONG(min_val) 16 | Z_PARAM_LONG(max_val) 17 | ZEND_PARSE_PARAMETERS_END(); 18 | 19 | wasm_limits_t limits = {.min = min_val, .max = max_val}; 20 | wasmer_res *wasm_limits = emalloc(sizeof(wasmer_res)); 21 | wasm_limits->inner.limits = limits; 22 | wasm_limits->owned = false; 23 | 24 | zend_resource *limits_res = zend_register_resource(wasm_limits, le_wasm_limits); 25 | 26 | RETURN_RES(limits_res); 27 | } 28 | 29 | PHP_FUNCTION (wasm_limits_min) { 30 | zval *limits_val; 31 | 32 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 33 | Z_PARAM_RESOURCE(limits_val) 34 | ZEND_PARSE_PARAMETERS_END(); 35 | 36 | WASMER_FETCH_RESOURCE(limits) 37 | 38 | wasm_limits_t limits = WASMER_RES_P_INNER(limits_val, limits); 39 | 40 | RETURN_LONG(limits.min); 41 | } 42 | 43 | PHP_FUNCTION (wasm_limits_max) { 44 | zval *limits_val; 45 | 46 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 47 | Z_PARAM_RESOURCE(limits_val) 48 | ZEND_PARSE_PARAMETERS_END(); 49 | 50 | WASMER_FETCH_RESOURCE(limits) 51 | 52 | wasm_limits_t limits = WASMER_RES_P_INNER(limits_val, limits); 53 | 54 | RETURN_LONG(limits.max); 55 | } -------------------------------------------------------------------------------- /ext/examples/global.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $f32_import (import "" "const f32") f32) 3 | (global $i64_import (import "" "const i64") i64) 4 | (global $mut_f32_import (import "" "var f32") (mut f32)) 5 | (global $mut_i64_import (import "" "var i64") (mut i64)) 6 | 7 | (global $f32_export (export "const f32") f32 (f32.const 5)) 8 | (global $i64_export (export "const i64") i64 (i64.const 6)) 9 | (global $mut_f32_export (export "var f32") (mut f32) (f32.const 7)) 10 | (global $mut_i64_export (export "var i64") (mut i64) (i64.const 8)) 11 | 12 | (func (export "get const f32 import") (result f32) (global.get $f32_import)) 13 | (func (export "get const i64 import") (result i64) (global.get $i64_import)) 14 | (func (export "get var f32 import") (result f32) (global.get $mut_f32_import)) 15 | (func (export "get var i64 import") (result i64) (global.get $mut_i64_import)) 16 | 17 | (func (export "get const f32 export") (result f32) (global.get $f32_export)) 18 | (func (export "get const i64 export") (result i64) (global.get $i64_export)) 19 | (func (export "get var f32 export") (result f32) (global.get $mut_f32_export)) 20 | (func (export "get var i64 export") (result i64) (global.get $mut_i64_export)) 21 | 22 | (func (export "set var f32 import") (param f32) (global.set $mut_f32_import (local.get 0))) 23 | (func (export "set var i64 import") (param i64) (global.set $mut_i64_import (local.get 0))) 24 | 25 | (func (export "set var f32 export") (param f32) (global.set $mut_f32_export (local.get 0))) 26 | (func (export "set var f64 export") (param i64) (global.set $mut_i64_export (local.get 0))) 27 | ) -------------------------------------------------------------------------------- /tests/examples/globl.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (global $f32_import (import "" "const f32") f32) 3 | (global $i64_import (import "" "const i64") i64) 4 | (global $mut_f32_import (import "" "var f32") (mut f32)) 5 | (global $mut_i64_import (import "" "var i64") (mut i64)) 6 | 7 | (global $f32_export (export "const f32") f32 (f32.const 5)) 8 | (global $i64_export (export "const i64") i64 (i64.const 6)) 9 | (global $mut_f32_export (export "var f32") (mut f32) (f32.const 7)) 10 | (global $mut_i64_export (export "var i64") (mut i64) (i64.const 8)) 11 | 12 | (func (export "get const f32 import") (result f32) (global.get $f32_import)) 13 | (func (export "get const i64 import") (result i64) (global.get $i64_import)) 14 | (func (export "get var f32 import") (result f32) (global.get $mut_f32_import)) 15 | (func (export "get var i64 import") (result i64) (global.get $mut_i64_import)) 16 | 17 | (func (export "get const f32 export") (result f32) (global.get $f32_export)) 18 | (func (export "get const i64 export") (result i64) (global.get $i64_export)) 19 | (func (export "get var f32 export") (result f32) (global.get $mut_f32_export)) 20 | (func (export "get var i64 export") (result i64) (global.get $mut_i64_export)) 21 | 22 | (func (export "set var f32 import") (param f32) (global.set $mut_f32_import (local.get 0))) 23 | (func (export "set var i64 import") (param i64) (global.set $mut_i64_import (local.get 0))) 24 | 25 | (func (export "set var f32 export") (param f32) (global.set $mut_f32_export (local.get 0))) 26 | (func (export "set var f64 export") (param i64) (global.set $mut_i64_export (local.get 0))) 27 | ) -------------------------------------------------------------------------------- /tests/unit/Store.php: -------------------------------------------------------------------------------- 1 | __destruct()); 60 | self::assertNull($store->__destruct()); 61 | } 62 | 63 | /** 64 | * @test 65 | */ 66 | public function inner(): void 67 | { 68 | $engine = \wasm_engine_new(); 69 | $store = \wasm_store_new($engine); 70 | 71 | self::assertSame((new Wasm\Store($store))->inner(), $store); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Instance.php: -------------------------------------------------------------------------------- 1 | inner = $instance; 31 | } 32 | 33 | /** 34 | * @ignore 35 | */ 36 | public function __destruct() 37 | { 38 | if (null !== $this->inner) { 39 | \wasm_instance_delete($this->inner); 40 | 41 | $this->inner = null; 42 | } 43 | } 44 | 45 | /** 46 | * Return the inner extern resource. 47 | * 48 | * @return resource A `wasm_instance_t` resource 49 | */ 50 | public function inner() 51 | { 52 | return $this->inner; 53 | } 54 | 55 | /** 56 | * @api 57 | */ 58 | public function exports(): Vec\Extern 59 | { 60 | return \wasm_instance_exports($this->inner); 61 | } 62 | 63 | /** 64 | * @api 65 | */ 66 | public static function new(Store $store, Module $module, ?Vec\Extern $externs = null): self 67 | { 68 | return new self(\wasm_instance_new($store->inner(), $module->inner(), $externs ?? new Vec\Extern())); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ext/src/api/objects/frame.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasm.h" 5 | 6 | #include "../macros.h" 7 | #include "../../wasm.h" 8 | 9 | WASMER_DECLARE_TYPE(Frame, FRAME, frame) 10 | 11 | WASMER_IMPORT_RESOURCE(instance) 12 | 13 | PHP_FUNCTION (wasm_frame_instance) { 14 | zval *frame_val; 15 | 16 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 17 | Z_PARAM_RESOURCE(frame_val) 18 | ZEND_PARSE_PARAMETERS_END(); 19 | 20 | WASMER_FETCH_RESOURCE(frame) 21 | 22 | wasmer_res *func = emalloc(sizeof(wasmer_res)); 23 | func->inner.instance = wasm_frame_instance(WASMER_RES_P_INNER(frame_val, frame)); 24 | func->owned = false; 25 | 26 | RETURN_RES(zend_register_resource(func, le_wasm_instance)); 27 | } 28 | 29 | PHP_FUNCTION (wasm_frame_func_index) { 30 | zval *frame_val; 31 | 32 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 33 | Z_PARAM_RESOURCE(frame_val) 34 | ZEND_PARSE_PARAMETERS_END(); 35 | 36 | WASMER_FETCH_RESOURCE(frame) 37 | 38 | RETURN_LONG(wasm_frame_func_index(WASMER_RES_P_INNER(frame_val, frame))); 39 | } 40 | 41 | PHP_FUNCTION (wasm_frame_func_offset) { 42 | zval *frame_val; 43 | 44 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 45 | Z_PARAM_RESOURCE(frame_val) 46 | ZEND_PARSE_PARAMETERS_END(); 47 | 48 | WASMER_FETCH_RESOURCE(frame) 49 | 50 | RETURN_LONG(wasm_frame_func_offset(WASMER_RES_P_INNER(frame_val, frame))); 51 | } 52 | 53 | PHP_FUNCTION (wasm_frame_module_offset) { 54 | zval *frame_val; 55 | 56 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 57 | Z_PARAM_RESOURCE(frame_val) 58 | ZEND_PARSE_PARAMETERS_END(); 59 | 60 | WASMER_FETCH_RESOURCE(frame) 61 | 62 | RETURN_LONG(wasm_frame_module_offset(WASMER_RES_P_INNER(frame_val, frame))); 63 | } 64 | -------------------------------------------------------------------------------- /ext/examples/memory.php: -------------------------------------------------------------------------------- 1 | getI32($memAddr) == wasm_val_value($result[0])); 56 | 57 | echo 'Shutting down...'.PHP_EOL; 58 | wasm_store_delete($store); 59 | wasm_engine_delete($engine); 60 | -------------------------------------------------------------------------------- /ext/src/api/types/valtype.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasm.h" 5 | 6 | #include "../macros.h" 7 | #include "../../wasm.h" 8 | 9 | WASMER_DECLARE_TYPE(ValType, VALTYPE, valtype) 10 | 11 | PHP_FUNCTION (wasm_valtype_new) { 12 | zval *valkind_val; 13 | 14 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 15 | Z_PARAM_NUMBER(valkind_val) 16 | ZEND_PARSE_PARAMETERS_END(); 17 | 18 | int valkind = zval_get_long(valkind_val); 19 | 20 | wasmer_res *valtype = emalloc(sizeof(wasmer_res)); 21 | valtype->inner.valtype = wasm_valtype_new(valkind); 22 | valtype->owned = true; 23 | 24 | zend_resource *valtype_res = zend_register_resource(valtype, le_wasm_valtype); 25 | 26 | RETURN_RES(valtype_res); 27 | } 28 | 29 | PHP_FUNCTION (wasm_valtype_kind) { 30 | zval *valtype_val; 31 | 32 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 33 | Z_PARAM_RESOURCE(valtype_val) 34 | ZEND_PARSE_PARAMETERS_END(); 35 | 36 | WASMER_FETCH_RESOURCE(valtype) 37 | 38 | int kind = wasm_valtype_kind(WASMER_RES_P_INNER(valtype_val, valtype)); 39 | 40 | RETURN_LONG(kind); 41 | } 42 | 43 | PHP_FUNCTION (wasm_valtype_is_num) { 44 | zval *valtype_val; 45 | 46 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 47 | Z_PARAM_RESOURCE(valtype_val) 48 | ZEND_PARSE_PARAMETERS_END(); 49 | 50 | WASMER_FETCH_RESOURCE(valtype) 51 | 52 | bool is_num = wasm_valtype_is_num(WASMER_RES_P_INNER(valtype_val, valtype)); 53 | 54 | RETURN_BOOL(is_num); 55 | } 56 | 57 | PHP_FUNCTION (wasm_valtype_is_ref) { 58 | zval *valtype_val; 59 | 60 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 61 | Z_PARAM_RESOURCE(valtype_val) 62 | ZEND_PARSE_PARAMETERS_END(); 63 | 64 | WASMER_FETCH_RESOURCE(valtype) 65 | 66 | bool is_ref = wasm_valtype_is_ref(WASMER_RES_P_INNER(valtype_val, valtype)); 67 | 68 | RETURN_BOOL(is_ref); 69 | } 70 | -------------------------------------------------------------------------------- /ext/tests/api/objects/module/01-arginfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Module API functions arguments information 3 | 4 | --FILE-- 5 | getNumberOfParameters()); 9 | var_dump($reflection->getReturnType()); 10 | 11 | $reflection = new ReflectionFunction('wasm_module_delete'); 12 | var_dump($reflection->getNumberOfParameters()); 13 | var_dump($reflection->getReturnType()->getName()); 14 | 15 | $reflection = new ReflectionFunction('wasm_module_validate'); 16 | var_dump($reflection->getNumberOfParameters()); 17 | var_dump($reflection->getReturnType()->getName()); 18 | 19 | $reflection = new ReflectionFunction('wasm_module_imports'); 20 | var_dump($reflection->getNumberOfParameters()); 21 | var_dump($reflection->getReturnType()->getName()); 22 | 23 | $reflection = new ReflectionFunction('wasm_module_exports'); 24 | var_dump($reflection->getNumberOfParameters()); 25 | var_dump($reflection->getReturnType()->getName()); 26 | 27 | $reflection = new ReflectionFunction('wasm_module_serialize'); 28 | var_dump($reflection->getNumberOfParameters()); 29 | var_dump($reflection->getReturnType()->getName()); 30 | 31 | $reflection = new ReflectionFunction('wasm_module_deserialize'); 32 | var_dump($reflection->getNumberOfParameters()); 33 | var_dump($reflection->getReturnType()); 34 | 35 | $reflection = new ReflectionFunction('wasm_module_name'); 36 | var_dump($reflection->getNumberOfParameters()); 37 | var_dump($reflection->getReturnType()->getName()); 38 | 39 | $reflection = new ReflectionFunction('wasm_module_set_name'); 40 | var_dump($reflection->getNumberOfParameters()); 41 | var_dump($reflection->getReturnType()->getName()); 42 | 43 | ?> 44 | --EXPECTF-- 45 | int(2) 46 | NULL 47 | int(1) 48 | string(4) "bool" 49 | int(2) 50 | string(4) "bool" 51 | int(1) 52 | string(19) "Wasm\Vec\ImportType" 53 | int(1) 54 | string(19) "Wasm\Vec\ExportType" 55 | int(1) 56 | string(6) "string" 57 | int(2) 58 | NULL 59 | int(1) 60 | string(6) "string" 61 | int(2) 62 | string(4) "bool" 63 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.17) 2 | project(wasmer-php 3 | VERSION 1.0.0 4 | DESCRIPTION "A complete and mature WebAssembly runtime for PHP based on Wasmer." 5 | LANGUAGES C) 6 | 7 | add_compile_definitions(HAVE_WASM) 8 | 9 | set(WASMER_API ext/src/api/config.c ext/src/api/engine.c ext/src/api/store.c ext/src/api/wasmer.c ext/src/api/wat.c) 10 | set(WASMER_API_OBJECTS ext/src/api/objects/extern.c ext/src/api/objects/foreign.c ext/src/api/objects/func.c ext/src/api/objects/frame.c ext/src/api/objects/global.c ext/src/api/objects/instance.c ext/src/api/objects/memory.c ext/src/api/objects/module.c ext/src/api/objects/table.c ext/src/api/objects/trap.c ext/src/api/objects/val.c) 11 | set(WASMER_API_TYPES ext/src/api/types/exporttype.c ext/src/api/types/externtype.c ext/src/api/types/functype.c ext/src/api/types/globaltype.c ext/src/api/types/importtype.c ext/src/api/types/limits.c ext/src/api/types/memorytype.c ext/src/api/types/tabletype.c ext/src/api/types/valkind.c ext/src/api/types/valtype.c) 12 | set(WASMER_SOURCES ext/src/php_wasm.h ext/src/wasm.c ext/src/wasmer_class_arginfo.h ext/src/wasmer_exception_arginfo.h ext/src/wasmer_root_arginfo.h ext/src/wasmer_vec_arginfo.h) 13 | set(WASMER_ALL_SOURCES ${WASMER_API} ${WASMER_API_OBJECTS} ${WASMER_API_TYPES} ${WASMER_SOURCES}) 14 | 15 | execute_process ( 16 | COMMAND php-config --include-dir 17 | OUTPUT_VARIABLE PHP_SOURCE 18 | ) 19 | string(REGEX REPLACE "\n$" "" PHP_SOURCE "${PHP_SOURCE}") 20 | 21 | message("Using PHP include directory: ${PHP_SOURCE}") 22 | 23 | include_directories(${PHP_SOURCE}) 24 | include_directories(${PHP_SOURCE}/main) 25 | include_directories(${PHP_SOURCE}/Zend) 26 | include_directories(${PHP_SOURCE}/TSRM) 27 | include_directories(${PROJECT_SOURCE_DIR}) 28 | include_directories(ext/include) 29 | 30 | add_custom_target(configure 31 | COMMAND phpize && ./configure 32 | DEPENDS ${WASMER_ALL_SOURCES} 33 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) 34 | 35 | add_library(___ EXCLUDE_FROM_ALL ${WASMER_ALL_SOURCES}) 36 | -------------------------------------------------------------------------------- /src/Extern.php: -------------------------------------------------------------------------------- 1 | inner = $extern; 33 | } 34 | 35 | /** 36 | * @ignore 37 | */ 38 | public function __destruct() 39 | { 40 | if (null !== $this->inner) { 41 | \wasm_extern_delete($this->inner); 42 | 43 | $this->inner = null; 44 | } 45 | } 46 | 47 | /** 48 | * Return the inner extern resource. 49 | * 50 | * @return resource A `wasm_extern_t` resource 51 | */ 52 | public function inner() 53 | { 54 | return $this->inner; 55 | } 56 | 57 | /** 58 | * @api 59 | */ 60 | public function asFunc(): Func 61 | { 62 | return new Func(\wasm_extern_as_func($this->inner)); 63 | } 64 | 65 | /** 66 | * @api 67 | */ 68 | public function asGlobal(): Globl 69 | { 70 | return new Globl(\wasm_extern_as_global($this->inner)); 71 | } 72 | 73 | /** 74 | * @api 75 | */ 76 | public function kind(): int 77 | { 78 | return \wasm_extern_kind($this->inner); 79 | } 80 | 81 | /** 82 | * @api 83 | */ 84 | public function type(): ExternType 85 | { 86 | return new ExternType(\wasm_extern_type($this->inner)); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /examples/imports-function-early-exit.php: -------------------------------------------------------------------------------- 1 | asExtern(); 49 | $externs = new Wasm\Vec\Extern([$extern->inner()]); 50 | 51 | echo 'Instantiating module...'.PHP_EOL; 52 | $instance = Wasm\Instance::new($store, $module, $externs); 53 | 54 | // Extracting export... 55 | $exports = $instance->exports(); 56 | $run = (new Wasm\Extern($exports[0]))->asFunc(); 57 | 58 | $firstArg = Wasm\Val::newI32(1); 59 | $secondArg = Wasm\Val::newI32(7); 60 | $args = new Wasm\Vec\Val([$firstArg->inner(), $secondArg->inner()]); 61 | 62 | echo 'Calling `run` function...'.PHP_EOL; 63 | try { 64 | $run($args); 65 | 66 | echo '`run` did not error'.PHP_EOL; 67 | 68 | exit(1); 69 | } catch (ExitCode $exception) { 70 | echo 'Exited early with: '.$exception->getMessage().' '.$exception->getCode().PHP_EOL; 71 | } 72 | -------------------------------------------------------------------------------- /tests/unit/Engine.php: -------------------------------------------------------------------------------- 1 | setCompiler($compiler); 35 | $config->setEngine($engine); 36 | 37 | self::assertIsObject(Wasm\Engine::new($config)); 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * @test 44 | */ 45 | public function construct(): void 46 | { 47 | $engine = \wasm_engine_new(); 48 | 49 | self::assertIsObject(new Wasm\Engine($engine)); 50 | 51 | try { 52 | new Wasm\Engine(42); 53 | 54 | self::fail(); 55 | } catch (Exception\InvalidArgumentException) { 56 | } 57 | 58 | try { 59 | new Wasm\Engine(\wasm_config_new()); 60 | 61 | self::fail(); 62 | } catch (Exception\InvalidArgumentException) { 63 | } 64 | } 65 | 66 | /** 67 | * @test 68 | */ 69 | public function destruct(): void 70 | { 71 | $engine = Wasm\Engine::new(); 72 | 73 | self::assertNull($engine->__destruct()); 74 | self::assertNull($engine->__destruct()); 75 | } 76 | 77 | /** 78 | * @test 79 | */ 80 | public function inner(): void 81 | { 82 | $engine = \wasm_engine_new(); 83 | 84 | self::assertSame((new Wasm\Engine($engine))->inner(), $engine); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /ext/examples/callback.php: -------------------------------------------------------------------------------- 1 | '.$i32.PHP_EOL; 22 | 23 | assert(7 === $i32); 24 | 25 | return $i32; 26 | } 27 | 28 | function closure(): int 29 | { 30 | echo 'Calling back closure...'.PHP_EOL; 31 | 32 | return 42; 33 | } 34 | 35 | $printType = wasm_functype_new( 36 | new Wasm\Vec\ValType([wasm_valtype_new(WASM_I32)]), 37 | new Wasm\Vec\ValType([wasm_valtype_new(WASM_I32)]) 38 | ); 39 | $print = wasm_func_new($store, $printType, 'print_callback'); 40 | wasm_functype_delete($printType); 41 | 42 | $closureType = wasm_functype_new( 43 | new Wasm\Vec\ValType(), 44 | new Wasm\Vec\ValType([wasm_valtype_new(WASM_I32)]) 45 | ); 46 | $closure = wasm_func_new($store, $closureType, 'closure'); 47 | wasm_functype_delete($closureType); 48 | 49 | echo 'Instantiating module...'.PHP_EOL; 50 | $externs = new Wasm\Vec\Extern([wasm_func_as_extern($print), wasm_func_as_extern($closure)]); 51 | $instance = wasm_instance_new($store, $module, $externs); 52 | 53 | wasm_func_delete($print); 54 | wasm_func_delete($closure); 55 | 56 | echo 'Extracting export...'.PHP_EOL; 57 | $exports = wasm_instance_exports($instance); 58 | $run = wasm_extern_as_func($exports[0]); 59 | 60 | wasm_module_delete($module); 61 | wasm_instance_delete($instance); 62 | 63 | echo 'Calling export...'.PHP_EOL; 64 | $args = new Wasm\Vec\Val([ 65 | wasm_val_i32(3), 66 | wasm_val_i32(4), 67 | ]); 68 | 69 | $results = wasm_func_call($run, $args); 70 | 71 | echo 'Printing result...'.PHP_EOL; 72 | $result = wasm_val_value($results[0]); 73 | echo '> '.$result.PHP_EOL; 74 | assert(49 === $result); 75 | 76 | echo 'Shutting down...'.PHP_EOL; 77 | wasm_store_delete($store); 78 | wasm_engine_delete($engine); 79 | -------------------------------------------------------------------------------- /ext/src/api/types/exporttype.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasm.h" 5 | 6 | #include "../macros.h" 7 | #include "../../wasm.h" 8 | 9 | WASMER_DECLARE_TYPE(ExportType, EXPORTTYPE, exporttype) 10 | 11 | WASMER_IMPORT_RESOURCE(externtype) 12 | 13 | PHP_FUNCTION (wasm_exporttype_new) { 14 | char *name; 15 | size_t name_len; 16 | zval *externtype_val; 17 | 18 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 2, 2) 19 | Z_PARAM_STRING(name, name_len) 20 | Z_PARAM_RESOURCE(externtype_val) 21 | ZEND_PARSE_PARAMETERS_END(); 22 | 23 | WASMER_FETCH_RESOURCE(externtype) 24 | 25 | wasm_name_t *name_vec = malloc(sizeof(wasm_name_t)); 26 | name_vec->size = name_len; 27 | name_vec->data = name; 28 | 29 | wasmer_res *externtype_res = WASMER_RES_P(externtype_val); 30 | externtype_res->owned = false; 31 | 32 | wasmer_res *exporttype = emalloc(sizeof(wasmer_res)); 33 | exporttype->inner.exporttype = wasm_exporttype_new(name_vec, WASMER_RES_INNER(externtype_res, externtype)); 34 | exporttype->owned = true; 35 | 36 | zend_resource *exporttype_res; 37 | exporttype_res = zend_register_resource(exporttype, le_wasm_exporttype); 38 | 39 | RETURN_RES(exporttype_res); 40 | } 41 | 42 | PHP_FUNCTION (wasm_exporttype_name) { 43 | zval *exporttype_val; 44 | 45 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 46 | Z_PARAM_RESOURCE(exporttype_val) 47 | ZEND_PARSE_PARAMETERS_END(); 48 | 49 | WASMER_FETCH_RESOURCE(exporttype) 50 | 51 | const wasm_name_t *name = wasm_exporttype_name(WASMER_RES_P_INNER(exporttype_val, exporttype)); 52 | 53 | RETURN_STRINGL(name->data, name->size); 54 | } 55 | 56 | PHP_FUNCTION (wasm_exporttype_type) { 57 | zval *exporttype_val; 58 | 59 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 60 | Z_PARAM_RESOURCE(exporttype_val) 61 | ZEND_PARSE_PARAMETERS_END(); 62 | 63 | WASMER_FETCH_RESOURCE(exporttype) 64 | 65 | wasmer_res *externtype = emalloc(sizeof(wasmer_res)); 66 | externtype->inner.externtype = wasm_exporttype_type(WASMER_RES_P_INNER(exporttype_val, exporttype)); 67 | externtype->owned = false; 68 | 69 | zend_resource *externtype_res = zend_register_resource(externtype, le_wasm_externtype); 70 | 71 | RETURN_RES(externtype_res); 72 | } 73 | -------------------------------------------------------------------------------- /ext/src/wasmer_class_arginfo.h: -------------------------------------------------------------------------------- 1 | /* This is a generated file, edit the .stub.php file instead. 2 | * Stub hash: 70154f1e75bf065443f1d7110d5c89b6bc02aca0 */ 3 | 4 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Wasm_MemoryView_getI32, 0, 1, IS_LONG, 0) 5 | ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) 6 | ZEND_END_ARG_INFO() 7 | 8 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Wasm_MemoryView_setI32, 0, 2, IS_VOID, 0) 9 | ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) 10 | ZEND_ARG_TYPE_INFO(0, value, IS_LONG, 0) 11 | ZEND_END_ARG_INFO() 12 | 13 | #define arginfo_class_Wasm_MemoryView_getI64 arginfo_class_Wasm_MemoryView_getI32 14 | 15 | #define arginfo_class_Wasm_MemoryView_setI64 arginfo_class_Wasm_MemoryView_setI32 16 | 17 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Wasm_MemoryView_getF32, 0, 1, IS_DOUBLE, 0) 18 | ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) 19 | ZEND_END_ARG_INFO() 20 | 21 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Wasm_MemoryView_setF32, 0, 2, IS_VOID, 0) 22 | ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0) 23 | ZEND_ARG_TYPE_INFO(0, value, IS_DOUBLE, 0) 24 | ZEND_END_ARG_INFO() 25 | 26 | #define arginfo_class_Wasm_MemoryView_getF64 arginfo_class_Wasm_MemoryView_getF32 27 | 28 | #define arginfo_class_Wasm_MemoryView_setF64 arginfo_class_Wasm_MemoryView_setF32 29 | 30 | 31 | ZEND_METHOD(Wasm_MemoryView, getI32); 32 | ZEND_METHOD(Wasm_MemoryView, setI32); 33 | ZEND_METHOD(Wasm_MemoryView, getI64); 34 | ZEND_METHOD(Wasm_MemoryView, setI64); 35 | ZEND_METHOD(Wasm_MemoryView, getF32); 36 | ZEND_METHOD(Wasm_MemoryView, setF32); 37 | ZEND_METHOD(Wasm_MemoryView, getF64); 38 | ZEND_METHOD(Wasm_MemoryView, setF64); 39 | 40 | 41 | static const zend_function_entry class_Wasm_MemoryView_methods[] = { 42 | ZEND_ME(Wasm_MemoryView, getI32, arginfo_class_Wasm_MemoryView_getI32, ZEND_ACC_PUBLIC) 43 | ZEND_ME(Wasm_MemoryView, setI32, arginfo_class_Wasm_MemoryView_setI32, ZEND_ACC_PUBLIC) 44 | ZEND_ME(Wasm_MemoryView, getI64, arginfo_class_Wasm_MemoryView_getI64, ZEND_ACC_PUBLIC) 45 | ZEND_ME(Wasm_MemoryView, setI64, arginfo_class_Wasm_MemoryView_setI64, ZEND_ACC_PUBLIC) 46 | ZEND_ME(Wasm_MemoryView, getF32, arginfo_class_Wasm_MemoryView_getF32, ZEND_ACC_PUBLIC) 47 | ZEND_ME(Wasm_MemoryView, setF32, arginfo_class_Wasm_MemoryView_setF32, ZEND_ACC_PUBLIC) 48 | ZEND_ME(Wasm_MemoryView, getF64, arginfo_class_Wasm_MemoryView_getF64, ZEND_ACC_PUBLIC) 49 | ZEND_ME(Wasm_MemoryView, setF64, arginfo_class_Wasm_MemoryView_setF64, ZEND_ACC_PUBLIC) 50 | ZEND_FE_END 51 | }; 52 | -------------------------------------------------------------------------------- /ext/tests/api/objects/func/02-wasm_func_new.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Func API: wasm_func_new 3 | 4 | --FILE-- 5 | run($store, $module, $functype); 66 | 67 | ?> 68 | --EXPECTF-- 69 | string(23) "Hello from PHP function" 70 | string(28) "Hello from PHP user function" 71 | string(28) "Hello from PHP named closure" 72 | string(22) "Hello from PHP closure" 73 | string(26) "Hello from invokable class" 74 | string(28) "Hello from PHP bound closure" 75 | -------------------------------------------------------------------------------- /src/Func.php: -------------------------------------------------------------------------------- 1 | inner = $func; 34 | } 35 | 36 | /** 37 | * @ignore 38 | */ 39 | public function __destruct() 40 | { 41 | if (null !== $this->inner) { 42 | \wasm_func_delete($this->inner); 43 | 44 | $this->inner = null; 45 | } 46 | } 47 | 48 | /** 49 | * @api 50 | */ 51 | public function __invoke(?Val $args = null): Val 52 | { 53 | return \wasm_func_call($this->inner, $args ?? new Val()); 54 | } 55 | 56 | /** 57 | * Return the inner func resource. 58 | * 59 | * @return resource A `wasm_func_t` resource 60 | */ 61 | public function inner() 62 | { 63 | return $this->inner; 64 | } 65 | 66 | /** 67 | * @api 68 | */ 69 | public function asExtern(): Extern 70 | { 71 | return new Extern(\wasm_func_as_extern($this->inner)); 72 | } 73 | 74 | /** 75 | * @api 76 | */ 77 | public function paramArity(): int 78 | { 79 | return \wasm_func_param_arity($this->inner); 80 | } 81 | 82 | /** 83 | * @api 84 | */ 85 | public function resultArity(): int 86 | { 87 | return \wasm_func_result_arity($this->inner); 88 | } 89 | 90 | /** 91 | * @api 92 | */ 93 | public function type(): FuncType 94 | { 95 | return new FuncType(\wasm_func_type($this->inner)); 96 | } 97 | 98 | /** 99 | * @api 100 | */ 101 | public static function new(Store $store, FuncType $functype, callable $func): self 102 | { 103 | return new self(\wasm_func_new($store->inner(), $functype->inner(), $func)); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /ext/src/api/types/memorytype.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasm.h" 5 | 6 | #include "../macros.h" 7 | #include "../../wasm.h" 8 | 9 | WASMER_DECLARE_TYPE(MemoryType, MEMORYTYPE, memorytype) 10 | 11 | WASMER_IMPORT_RESOURCE(externtype) 12 | WASMER_IMPORT_RESOURCE(limits) 13 | WASMER_IMPORT_RESOURCE(valtype) 14 | 15 | PHP_FUNCTION (wasm_memorytype_new) { 16 | zval *limits_val; 17 | 18 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 19 | Z_PARAM_RESOURCE(limits_val) 20 | ZEND_PARSE_PARAMETERS_END(); 21 | 22 | WASMER_FETCH_RESOURCE(limits) 23 | 24 | wasmer_res *limits_res = WASMER_RES_P(limits_val); 25 | limits_res->owned = false; 26 | 27 | wasmer_res *memorytype = emalloc(sizeof(wasmer_res)); 28 | memorytype->inner.memorytype = wasm_memorytype_new(&WASMER_RES_INNER(limits_res, limits)); 29 | memorytype->owned = true; 30 | 31 | zend_resource *memorytype_res = zend_register_resource(memorytype, le_wasm_memorytype); 32 | 33 | RETURN_RES(memorytype_res); 34 | } 35 | 36 | PHP_FUNCTION (wasm_memorytype_limits) { 37 | zval *memorytype_val; 38 | 39 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 40 | Z_PARAM_RESOURCE(memorytype_val) 41 | ZEND_PARSE_PARAMETERS_END(); 42 | 43 | WASMER_FETCH_RESOURCE(memorytype) 44 | 45 | wasm_limits_t *limits = wasm_memorytype_limits(WASMER_RES_P_INNER(memorytype_val, memorytype)); 46 | 47 | wasmer_res *wasm_limits = ecalloc(1, sizeof(wasmer_res)); 48 | wasm_limits->inner.limits = (wasm_limits_t) {.min = limits->min, .max = limits->max}; 49 | wasm_limits->owned = false; 50 | 51 | zend_resource *limits_res = zend_register_resource(wasm_limits, le_wasm_limits); 52 | 53 | RETURN_RES(limits_res); 54 | } 55 | 56 | PHP_FUNCTION (wasm_memorytype_as_externtype) { 57 | zval *memorytype_val; 58 | 59 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 60 | Z_PARAM_RESOURCE(memorytype_val) 61 | ZEND_PARSE_PARAMETERS_END(); 62 | 63 | WASMER_FETCH_RESOURCE(memorytype) 64 | 65 | wasmer_res *memorytype_res = WASMER_RES_P(memorytype_val); 66 | memorytype_res->owned = false; 67 | 68 | wasmer_res *externtype = emalloc(sizeof(wasmer_res)); 69 | externtype->inner.externtype = wasm_memorytype_as_externtype(WASMER_RES_INNER(memorytype_res, memorytype)); 70 | externtype->owned = false; 71 | 72 | zend_resource *externtype_res; 73 | externtype_res = zend_register_resource(externtype, le_wasm_externtype); 74 | 75 | RETURN_RES(externtype_res); 76 | } 77 | -------------------------------------------------------------------------------- /.github/workflows/nightly.yaml: -------------------------------------------------------------------------------- 1 | name: Nightly 2 | 3 | on: 4 | schedule: 5 | - cron: '0 2 * * *' 6 | workflow_dispatch: 7 | 8 | jobs: 9 | test: 10 | name: Test on ${{ matrix.id }} with ${{ matrix.php }} 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | include: 16 | - id: linux-x64 17 | os: ubuntu-18.04 18 | php: '8.0' 19 | allow_failure: false 20 | nightly: wasmer-linux-amd64.tar.gz 21 | - id: linux-x64 22 | os: ubuntu-18.04 23 | php: '8.1' 24 | allow_failure: false 25 | nightly: wasmer-linux-amd64.tar.gz 26 | - id: macos-x64 27 | os: macos-latest 28 | php: '8.0' 29 | allow_failure: false 30 | nightly: wasmer-darwin-amd64.tar.gz 31 | - id: macos-x64 32 | os: macos-latest 33 | php: '8.1' 34 | allow_failure: false 35 | nightly: wasmer-darwin-amd64.tar.gz 36 | steps: 37 | - name: Setup PHP 38 | uses: shivammathur/setup-php@v2 39 | with: 40 | php-version: ${{ matrix.php }} 41 | - name: Checkout code 42 | uses: actions/checkout@v2 43 | - name: Install Wasmer nightly 44 | run: | 45 | GH_URL="https://github.com" 46 | LATEST_URL="${GH_URL}/wasmerio/wasmer-nightly/releases/latest/" 47 | ASSET_PATTERN="/wasmerio/wasmer-nightly/.*/${{ matrix.nightly }}" 48 | ASSET_URL=$(curl -Ls ${LATEST_URL} | grep -wo ${ASSET_PATTERN}) 49 | 50 | curl -Ls ${GH_URL}${ASSET_URL} --output ${{ matrix.nightly }} 51 | mkdir -p /tmp/wasmer 52 | tar xzf ${{ matrix.nightly }} -C /tmp/wasmer 53 | cp -f /tmp/wasmer/include/{wasm,wasmer_wasm}.h ./include 54 | cp -f /tmp/wasmer/lib/libwasmer.* ./lib 55 | - name: Configure 56 | run: | 57 | phpize 58 | ./configure 59 | - name: Build 60 | run: | 61 | make || ${{ matrix.allow_failure }} 62 | - name: Run tests (phpt) 63 | run: | 64 | make test || ${{ matrix.allow_failure }} 65 | - name: Run examples 66 | run: | 67 | make examples || ${{ matrix.allow_failure }} 68 | - name: Archive test results 69 | if: ${{ failure() }} 70 | uses: actions/upload-artifact@v2 71 | with: 72 | name: results-${{ matrix.id }}-${{ matrix.php }} 73 | retention-days: 3 74 | path: | 75 | tests/**/*.diff 76 | tests/**/*.exp 77 | tests/**/*.out 78 | -------------------------------------------------------------------------------- /tests/examples/Callback.php: -------------------------------------------------------------------------------- 1 | module()); 26 | 27 | // Loading binary... 28 | $wasm = Wat::wasm($wat); 29 | 30 | // Compiling module... 31 | $module = Wasm\Module::new($store, $wasm); 32 | 33 | $arg = Wasm\Type\ValType::new(Wasm\Type\ValType::KIND_I32); 34 | $result = Wasm\Type\ValType::new(Wasm\Type\ValType::KIND_I32); 35 | $printType = Wasm\Type\FuncType::new( 36 | new Wasm\Vec\ValType([$arg->inner()]), 37 | new Wasm\Vec\ValType([$result->inner()]) 38 | ); 39 | $print = Wasm\Func::new($store, $printType, [self::class, 'print_callback']); 40 | 41 | $result = Wasm\Type\ValType::new(Wasm\Type\ValType::KIND_I32); 42 | $closureType = Wasm\Type\FuncType::new( 43 | new Wasm\Vec\ValType(), 44 | new Wasm\Vec\ValType([$result->inner()]) 45 | ); 46 | $closure = Wasm\Func::new($store, $closureType, [self::class, 'closure']); 47 | 48 | // Instantiating module... 49 | $printExtern = $print->asExtern(); 50 | $closureExtern = $closure->asExtern(); 51 | $externs = new Wasm\Vec\Extern([$printExtern->inner(), $closureExtern->inner()]); 52 | $instance = Wasm\Instance::new($store, $module, $externs); 53 | 54 | // Extracting export... 55 | $exports = $instance->exports(); 56 | $run = (new Wasm\Extern($exports[0]))->asFunc(); 57 | 58 | // Calling export... 59 | $first = Wasm\Val::newI32(3); 60 | $second = Wasm\Val::newI32(4); 61 | $args = new Wasm\Vec\Val([ 62 | $first->inner(), 63 | $second->inner(), 64 | ]); 65 | 66 | $results = $run($args); 67 | 68 | // Printing result... 69 | $result = new Wasm\Val($results[0]); 70 | 71 | self::assertEquals(49, $result->value()); 72 | } 73 | 74 | public static function print_callback(int $i32): int 75 | { 76 | // Calling back... 77 | self::assertEquals(7, $i32); 78 | 79 | return $i32; 80 | } 81 | 82 | public static function closure(): int 83 | { 84 | // Calling back closure... 85 | return 42; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /ext/src/api/objects/instance.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | #include "Zend/zend_exceptions.h" 3 | 4 | #include "wasmer_wasm.h" 5 | 6 | #include "../macros.h" 7 | #include "../../wasm.h" 8 | 9 | WASMER_DECLARE_OWN(instance) 10 | WASMER_COPY(instance) 11 | 12 | WASMER_IMPORT_RESOURCE(store) 13 | WASMER_IMPORT_RESOURCE(module) 14 | 15 | extern zend_class_entry *wasm_vec_extern_ce; 16 | extern zend_class_entry *wasm_exception_instantiation_ce; 17 | 18 | PHP_FUNCTION (wasm_instance_new) { 19 | zval *store_val; 20 | zval *module_val; 21 | zval *externs_val; 22 | 23 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 3, 3) 24 | Z_PARAM_RESOURCE(store_val) 25 | Z_PARAM_RESOURCE(module_val) 26 | Z_PARAM_OBJECT(externs_val) 27 | ZEND_PARSE_PARAMETERS_END(); 28 | 29 | WASMER_FETCH_RESOURCE(store) 30 | WASMER_FETCH_RESOURCE(module) 31 | 32 | wasm_store_t *store = WASMER_RES_P_INNER(store_val, store); 33 | wasm_module_t *module = WASMER_RES_P_INNER(module_val, module); 34 | wasm_extern_vec_c *externs = WASMER_EXTERN_VEC_P(externs_val); 35 | 36 | wasm_trap_t *trap; 37 | memset(&trap, 0, sizeof(wasm_trap_t*)); 38 | wasm_instance_t *wasm_instance = wasm_instance_new(store, module, externs->vec.inner.xtern, &trap); 39 | 40 | WASMER_HANDLE_ERROR(wasm_exception_instantiation_ce) 41 | 42 | if (trap != NULL) { 43 | wasm_byte_vec_t *message_vec = emalloc(sizeof(wasm_byte_vec_t)); 44 | wasm_trap_message(trap, message_vec); 45 | 46 | zend_throw_exception_ex(zend_ce_exception, 0, "%s", message_vec->data); 47 | 48 | efree(message_vec); 49 | 50 | return; 51 | } 52 | 53 | wasmer_res *instance = emalloc(sizeof(wasmer_res)); 54 | instance->inner.instance = wasm_instance; 55 | instance->owned = true; 56 | 57 | zend_resource *instance_res = zend_register_resource(instance, le_wasm_instance); 58 | 59 | RETURN_RES(instance_res); 60 | } 61 | 62 | PHP_FUNCTION (wasm_instance_exports) { 63 | zval *instance_val; 64 | 65 | ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1) 66 | Z_PARAM_RESOURCE(instance_val) 67 | ZEND_PARSE_PARAMETERS_END(); 68 | 69 | WASMER_FETCH_RESOURCE(instance) 70 | 71 | wasm_instance_t *instance = WASMER_RES_P_INNER(instance_val, instance); 72 | 73 | wasm_extern_vec_t *externs = emalloc(sizeof(wasm_extern_vec_t)); 74 | wasm_instance_exports(instance, externs); 75 | 76 | zval obj; 77 | object_init_ex(&obj, wasm_vec_extern_ce); 78 | wasm_extern_vec_c *ce = WASMER_EXTERN_VEC_P(&obj); 79 | ce->vec.inner.xtern = externs; 80 | ce->vec.owned = true; 81 | 82 | RETURN_OBJ(Z_OBJ(obj)); 83 | } 84 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | # TODO(jubianchi): Remove this once bors is available 5 | pull_request: 6 | push: 7 | branches: 8 | - 'master' 9 | # TODO(jubianchi): Uncomment this once bors is available 10 | # - 'staging' 11 | # - 'trying' 12 | tags: 13 | 14 | jobs: 15 | test: 16 | name: Test on ${{ matrix.id }} with ${{ matrix.php }} 17 | runs-on: ${{ matrix.os }} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | include: 22 | - id: linux-x64 23 | os: ubuntu-18.04 24 | php: 8.0 25 | allow_failure: false 26 | - id: linux-x64 27 | os: ubuntu-18.04 28 | php: 8.1 29 | allow_failure: false 30 | - id: macos-x64 31 | os: macos-latest 32 | php: 8.0 33 | allow_failure: false 34 | - id: macos-x64 35 | os: macos-latest 36 | php: 8.1 37 | allow_failure: false 38 | steps: 39 | - name: Setup PHP 40 | uses: shivammathur/setup-php@v2 41 | with: 42 | php-version: ${{ matrix.php }} 43 | - name: Checkout code 44 | uses: actions/checkout@v2 45 | - name: Get Composer Cache Directory 46 | id: composer-cache 47 | run: | 48 | echo "::set-output name=dir::$(composer config cache-files-dir)" 49 | - uses: actions/cache@v2 50 | with: 51 | path: ${{ steps.composer-cache.outputs.dir }} 52 | key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} 53 | - name: Configure 54 | run: | 55 | make ext/configure 56 | - name: Build 57 | run: | 58 | make ext/all || ${{ matrix.allow_failure }} 59 | - name: Run tests (phpt) 60 | run: | 61 | make ext/test || ${{ matrix.allow_failure }} 62 | - name: Run examples 63 | run: | 64 | make ext/examples || ${{ matrix.allow_failure }} 65 | - name: Run tests (unit) 66 | run: | 67 | make test-unit || ${{ matrix.allow_failure }} 68 | - name: Run examples (OO interface) 69 | run: | 70 | make test-examples || ${{ matrix.allow_failure }} 71 | - name: Run documentation examples (OO interface) 72 | run: | 73 | make test-doc-examples || ${{ matrix.allow_failure }} 74 | - name: Archive test results 75 | if: ${{ failure() }} 76 | uses: actions/upload-artifact@v2 77 | with: 78 | name: results-${{ matrix.id }}-${{ matrix.php }} 79 | retention-days: 3 80 | path: | 81 | ext/tests/**/*.diff 82 | ext/tests/**/*.exp 83 | ext/tests/**/*.out 84 | -------------------------------------------------------------------------------- /examples/exports-global.php: -------------------------------------------------------------------------------- 1 | exports(); 37 | $one = (new Wasm\Extern($exports[0]))->asGlobal(); 38 | $some = (new Wasm\Extern($exports[1]))->asGlobal(); 39 | 40 | echo 'Getting globals types information...'.PHP_EOL; 41 | $oneType = $one->type(); 42 | $someType = $some->type(); 43 | 44 | echo '`one` type: '.(GlobalType::MUTABILITY_CONST === $oneType->mutability() ? 'CONST' : 'VAR').' '.$oneType->content()->kind().PHP_EOL; 45 | echo '`some` type: '.(GlobalType::MUTABILITY_CONST === $someType->mutability() ? 'CONST' : 'VAR').' '.$someType->content()->kind().PHP_EOL; 46 | 47 | echo 'Getting global values...'.PHP_EOL; 48 | $getOne = (new Wasm\Extern($exports[2]))->asFunc(); 49 | 50 | $results = $getOne(); 51 | $oneValue = (new Wasm\Val($results[0]))->value(); 52 | 53 | $someValue = $some->get()->value(); 54 | 55 | echo '`one` value: '.$oneValue.PHP_EOL; 56 | echo '`some` value: '.$someValue.PHP_EOL; 57 | 58 | echo 'Setting global values...'.PHP_EOL; 59 | 60 | try { 61 | $one->set(42.0); 62 | 63 | echo 'Setting value to `one` did not error'.PHP_EOL; 64 | 65 | exit(1); 66 | } catch (\Wasm\Exception\RuntimeException $exception) { 67 | assert('RuntimeError: Attempted to set an immutable global' === $exception->getMessage()); 68 | } 69 | 70 | $results = $getOne(); 71 | $oneValue = (new Wasm\Val($results[0]))->value(); 72 | 73 | echo '`one` value: '.$oneValue.PHP_EOL; 74 | 75 | $setSome = (new Wasm\Extern($exports[4]))->asFunc(); 76 | 77 | $arg = Wasm\Val::newF32(21.0); 78 | $args = new Wasm\Vec\Val([$arg->inner()]); 79 | $setSome($args); 80 | 81 | $someValue = $some->get()->value(); 82 | 83 | echo '`some` value after `set_some`: '.$someValue.PHP_EOL; 84 | 85 | $some->set(42.0); 86 | $someValue = $some->get()->value(); 87 | 88 | echo '`some` value after `set`: '.$someValue.PHP_EOL; 89 | -------------------------------------------------------------------------------- /tests/unit/Config.php: -------------------------------------------------------------------------------- 1 | __destruct()); 59 | self::assertNull($config->__destruct()); 60 | } 61 | 62 | /** 63 | * @test 64 | */ 65 | public function inner(): void 66 | { 67 | $config = \wasm_config_new(); 68 | 69 | self::assertSame((new Wasm\Config($config))->inner(), $config); 70 | } 71 | 72 | /** 73 | * @test 74 | */ 75 | public function setCompiler(): void 76 | { 77 | $config = Wasm\Config::new(); 78 | 79 | self::assertTrue($config->setCompiler(Wasm\Config::COMPILER_CRANELIFT)); 80 | self::assertTrue($config->setCompiler(Wasm\Config::COMPILER_LLVM)); 81 | self::assertTrue($config->setCompiler(Wasm\Config::COMPILER_SINGLEPASS)); 82 | 83 | try { 84 | $config->setCompiler(99); 85 | } catch (Exception\InvalidArgumentException) { 86 | } 87 | } 88 | 89 | /** 90 | * @test 91 | */ 92 | public function setEngine(): void 93 | { 94 | $config = Wasm\Config::new(); 95 | 96 | self::assertTrue($config->setEngine(Wasm\Config::ENGINE_JIT)); 97 | self::assertTrue($config->setEngine(Wasm\Config::ENGINE_NATIVE)); 98 | self::assertTrue($config->setEngine(Wasm\Config::ENGINE_OBJECT_FILE)); 99 | 100 | try { 101 | $config->setEngine(99); 102 | } catch (Exception\InvalidArgumentException) { 103 | } 104 | } 105 | } 106 | --------------------------------------------------------------------------------