Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import dict rather than sequence? e.g. Instance(store, module, {"env": Memory(store, MemoryType(Limits(5, 5)))}) #240

Open
INPUTrrr0 opened this issue Jun 7, 2024 · 5 comments

Comments

@INPUTrrr0
Copy link

Why is the import in Instance defined as "imports: Sequence[AsExtern]" rather than a dict? So instead of having (import "" "hello") in hello.wat, I can have (import "env" "hello"). This would make the import more organized.
(Although linker make use of that first slot in the import, in my understanding it's more like for linking two .wat file files, rather than organizing the imports? Or am I just not understanding how linker works. Please let me know :) )

Thanks!

@alexcrichton
Copy link
Member

Yeah for this it's recommended to use Linker since that does name-based resolution for host functions. Would that work for your use case?

@INPUTrrr0
Copy link
Author

Thanks Alex. I see. Previously my understanding is that for Linker to be used, there must be another module to import. But I only want to give it a different name for clarity of the code. But I can take a closer look at the code.

@alexcrichton
Copy link
Member

Ah yes you can also use define_func to add host functions into a Linker too

@INPUTrrr0
Copy link
Author

Hi Alex. Thanks for your reply. I will take a look at it. I have a follow up question regarding import. I want to import a function with no input parameters. However the code below seems to indicate that the input parameters cannot be none. And The ValType doesn't seem to have a "None" type either. Thanks!

class FuncType(Managed["ctypes._Pointer[ffi.wasm_functype_t]"]):
    def __init__(self, params: List[ValType], results: List[ValType]):
        for param in params:
            if not isinstance(param, ValType):
                raise TypeError("expected ValType")
        for result in results:
            if not isinstance(result, ValType):
                raise TypeError("expected ValType")

@alexcrichton
Copy link
Member

You should be able to pass an empty list since that's the types of the arguments, would that work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants