Git Product home page Git Product logo

Comments (9)

rianhunter avatar rianhunter commented on July 26, 2024 1

@bjfish the function being named "main" is the convention, isn't it? whatever is running the wasm can just assume that is the main entry point by convention.

from wasi-libc.

rianhunter avatar rianhunter commented on July 26, 2024
  • I'm not 100% sure but I don't think this is the intended purpose of the wasm start function. Using it this way would mean that main() would get called when the main module is instantiated.
  • Where does the argv data ultimately come from? Unless I'm missing something, it seems better for the module to ask the module from which it's importing where the argv data is, instead of setting it.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024

I'm not 100% sure but I don't think this is the intended purpose of the wasm start function. Using it this way would mean that main() would get called when the main module is instantiated.

That's a good point. I've tweaked the wording a little, but let me also explain here: Calling main from the wasm start function isn't the only way to do it, but for purely command-line-oriented programs, I think it is a natural way to do it. The important aspect here is that we don't want to rely on the entrypoint (whatever it is) having arguents or return values.

Where does the argv data ultimately come from? Unless I'm missing something, it seems better for the module to ask the module from which it's importing where the argv data is, instead of setting it.

The argv data comes from whatever entity satisfies these imports. In a command-line-oriented wasm runner, these might be provided by the runner itself. In a browser, there might be a polyfill module providing a command-line-environment to run in. Other environments could decide how to resolve these symbols in whatever way makes sense in their contexts.

As for pointing the module to where the argv data is rather than copying it in, the difficulty is that Wasm programs by design can't refer to data they haven't been explicitly given access to.

from wasi-libc.

rianhunter avatar rianhunter commented on July 26, 2024

Where does the argv data ultimately come from? Unless I'm missing something, it seems better for the module to ask the module from which it's importing where the argv data is, instead of setting it.

The argv data comes from whatever entity satisfies these imports. In a command-line-oriented wasm runner, these might be provided by the runner itself. In a browser, there might be a polyfill module providing a command-line-environment to run in. Other environments could decide how to resolve these symbols in whatever way makes sense in their contexts.

As for pointing the module to where the argv data is rather than copying it in, the difficulty is that Wasm programs by design can't refer to data they haven't been explicitly given access to.

I see, so the module runner is responsible for filling the argv data when the module calls store_argv_data. The naming was a bit confusing for me, since by "store" I thought that meant it was sending (storing) the pointer to the module runner.

from wasi-libc.

bjfish avatar bjfish commented on July 26, 2024

It would be nice if there was some convention regarding calling a main() or init() but calling this from start has this limitation? WebAssembly/design#1160

from wasi-libc.

bjfish avatar bjfish commented on July 26, 2024

@rianhunter Yes, I think a "main" function being the entry point would be a good convention for a wasm runtime. It'd be nice to have an option to override this via configuration as well.

from wasi-libc.

lachlansneff avatar lachlansneff commented on July 26, 2024

Would that pass in cli arguments as parameters like emscripten does? Or would imported functions be used to get the cli arguments?

from wasi-libc.

bjfish avatar bjfish commented on July 26, 2024

@lachlansneff I think the way emscripten does this is by generating glue code (shims) which call it’s own wasm syscall/runtime API. In the short term, I think imported functions could be used directly but hopefully future glue code would adopt the new reference syscall API.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024

This design for command-line arguments is now subsumed by the WASI proposal; see the __wasi_args_* functions in the API.

from wasi-libc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.