my webassembly chess ai project doesnt run on python

43 views Asked by At

I have a chess ai project I have written in c++ and compiled it to webasembly with emcc then I wanted to serve it in a server as a webservice and I decided to use python wasmtime library for it when I tried to run it gives some errors

TIME=1import wasmtime

# Create an engine
engine = wasmtime.Engine()

# Create a store
store = wasmtime.Store(engine)

# Load the Wasm module
module = wasmtime.Module(store.engine, open("c.wasm","rb").read())
imports = {
    "Module": {
        "_calcStartConstant": wasmtime.Func(store, wasmtime.FuncType([], [wasmtime.ValType.i32()]), "_calcStartConstant"),
        "_set_side": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.i32()], []), "_set_side"),
        "_set_piecePoints": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32(), wasmtime.ValType.i32()], []), "_set_piecePoints"),
        "_set_depth": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.i32()], []), "_set_depth"),
        "_next": wasmtime.Func(store, wasmtime.FuncType([], []), "_next"),
        "_prev": wasmtime.Func(store, wasmtime.FuncType([], []), "_prev"),
        "_selectBest": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.i32()], [wasmtime.ValType.i32()]), "_selectBest"),
        "_set_Coefs": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32(), wasmtime.ValType.f32()], []), "_set_Coefs"),
        "_set_time_limit": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.i32()], []), "_set_time_limit"),
        "_malloc": wasmtime.Func(store, wasmtime.FuncType([wasmtime.ValType.i32()],[wasmtime.ValType.i32()]), "_malloc")
    }
}
# Instantiate the module
instance = wasmtime.Instance(store,module, imports) 

# Access functions and memory of the module as needed
# For example, to call a function named "_selectBest":
_selectBest = instance.exports.get_func("_selectBest")

# Provide the string argument and get the result
argument = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
result_ptr = _selectBest.call(argument)
if result_ptr:
    result = wasmtime.ffi.string(result_ptr).decode()
    wasmtime.ffi.wasmtime_externref_delete(result_ptr)
    print(result)
else:
    print("Error occurred while calling _selectBest function")
result = wasmtime.ffi.string(result_ptr).decode()

# Handle the result as required
print(result)

it gives that error

TypeError: expected a Func, Global, Memory, Table, Module, or Instance

what can cause it, please help

I want that the code runs and my webassembly file calculates for the best move at the game begining then says the result

0

There are 0 answers