Johan B.W. de Vries 2063a6ea9c Worker, run_once
2023-04-10 13:11:16 +02:00

18 lines
459 B
Python

import wasm3 # type: ignore
from phasmplatform.common.exceptions import PhashPlatformNonIntMainReturnError
def run_once(wasm_bin: bytes) -> int:
env = wasm3.Environment()
rtime = env.new_runtime(1024 * 1024)
rtime.load(env.parse_module(wasm_bin))
result = rtime.find_function('main')()
if result is None:
return 0
if not isinstance(result, int):
raise PhashPlatformNonIntMainReturnError(result)
return result