Skip to content

Calls to the embedder #47

Closed
Closed

Description

@jfbastien

The design repo is pretty vague about how calls to the embedder work, mostly because we were waiting on an implementation to really get a good understanding. I''m hoping that the spec repo can try things out, and help inform the design.

Could the spec repo implement something so that I can e.g. compile "Hello World!" and print that string to the screen?

I think the current agreement is that embedder calls look like declared-but-not-defined functions in the module. It's pretty similar to what dynamic linking would do.

Activity

  1. lukewagner commented on Sep 3, 2015

    @lukewagner
    Member

    Improvements/clarifications always welcome, but the design repo does state that the way host environments expose host-specific functionality through builtin modules (see also NonWeb.md).

    Concretely, the way I was expecting this to be reflected in ml-proto:

    • we'd add an imports field to Ast.module (reflecting imports in Modules.md)
    • an import would roughly look like (import @importName "func_name" "module_name" (signature ...)) such that you could (call @importName ...) (like everything else, the name would be optional and an index could be used instead). check.ml would require the call's sig to match the import's sig.
    • per design repo, how an import is resolved is totally up to the host environment. To reflect this in ml-proto, eval.ml would be extended so that Eval.init also took a list imported functions (assumed to match the signatures of Ast.imports) and the impl of call of an import simply called one of these functions.
    • the host part of ml-proto (script.ml, which is not logically part of the spec, but part of the host environment) would then, after parsing the Ast.module from SExprs would iterate down the list of module.imports, look them up in a list of builtin functionality we'd like to expose in ml-proto (stdio, etc) to build the list of imports passed to Eval.init (or fail on unknown imports).

    Thus, just like the C/C++ standard (Section 1.9 Program Execution: "The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine."), the wasm semantics would be parameterized by the host environment (the import arguments to init). When we add page_size, that value would, I expect, be another parameter to init.

    To make the spec vs. reference interpreter embedding distinction clear in ml-proto, I have been thinking it'd be nice to split up the ML files into subdirs (e.g., spec (containing ast.ml, eval.ml, check.ml, types.ml, values.ml) and host (containing script.ml and SExpr parser). I think there should also be a 3rd subdir (say, given) for files that implement basic functionality that we would just take as given (and not redefine) in a real spec (viz., arithmetic.ml, after some massaging).

  2. rossberg commented on Sep 3, 2015

    @rossberg
    Member

    On 3 September 2015 at 21:00, Luke Wagner [email protected] wrote:

    Improvements/clarifications always welcome, but the design repo does state
    that the way host environments expose host-specific functionality through builtin
    modules
    https://github.com/WebAssembly/design/blob/master/Modules.md#imports-and-exports
    (see also NonWeb.md).

    Concretely, the way I was expecting this to be reflected in ml-proto:

    This sounds reasonable to me. (Bikeshed: instead of (signature ...) I
    would just reuse (param ...) and (result ...) there, to mirror func
    definitions.)

    So the linking would be performed by the host? Makes sense. An alternative
    model would be to pass in a module environment (a map from module names to
    instances), and let Eval.init do the lookup.

    • the host part of ml-proto (script.ml, which is not logically part of
      the spec, but part of the host environment) would then, after parsing the
      Ast.module from SExprs would iterate down the list of module.imports,
      look them up in a list of builtin functionality we'd like to expose in
      ml-proto (stdio, etc) to build the list of imports passed to Eval.init
      (or fail on unknown imports).

    Thus, just like the C/C++ standard (Section 1.9 Program Execution: "The
    semantic descriptions in this International Standard define a parameterized
    nondeterministic abstract machine."), the wasm semantics would be
    parameterized by the host environment (the import arguments to init).
    When we add page_size, that value would, I expect, be another parameter
    to init.

    To make the spec vs. reference interpreter embedding distinction clear in
    ml-proto, I have been thinking it'd be nice to split up the ML files into
    subdirs (e.g., spec (containing ast.ml, eval.ml, check.ml, types.ml,
    values.ml) and host (containing script.ml and SExpr parser). I think
    there is also a 3rd subdir (say, given) for files that implement basic
    functionality that we would just take as given (and not redefine) in a real
    spec (viz., arithmetic.ml, after some massaging).

    Makes sense. Regarding arithmetic.ml, I think it would belong into spec
    as well (maybe under a better name), assuming some of the actual operator
    implementations are factored out into given (in particular, Float64 and
    Float32 modules like Dan is working on).

    /Andreas

  3. lukewagner commented on Sep 3, 2015

    @lukewagner
    Member

    So the linking would be performed by the host? Makes sense. An alternative model would be to pass > in a module environment (a map from module names to instances), and let Eval.init do the lookup.

    I was also thinking along these lines. It would describe the builtin module situation well, but not the case where imports lead to dynamic fetches and, recursively, more module loading; for that it seems like you'd need some sort of "go load me this module that's not already in the map" callback which seems more complicated.

  4. lukewagner commented on Sep 3, 2015

    @lukewagner
    Member

    Makes sense. Regarding arithmetic.ml, I think it would belong into spec as well (maybe under a
    better name), assuming some of the actual operator implementations are factored out into given
    (in particular, Float64 and Float32 modules like Dan is working on).

    Agreed (that's what I was alluding to by "after some massaging" :)

  5. jfbastien commented on Sep 3, 2015

    @jfbastien
    MemberAuthor

    Make It So :-)

  6. lukewagner commented on Sep 10, 2015

    @lukewagner
    Member

    Created #54.

  7. added a commit that references this issue on Mar 2, 2023
  8. added a commit that references this issue on Oct 3, 2023
  9. added 2 commits that reference this issue on Aug 30, 2024
  10. added a commit that references this issue on Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions