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

WASM import all non-compile axioms with alphanum names in entrypoint #1426

Merged
merged 4 commits into from
Aug 2, 2022

Conversation

paulcadman
Copy link
Collaborator

@paulcadman paulcadman commented Aug 1, 2022

⚠️ The tests now depend on node in order to test injecting WASM import functions into a Juvix program.

This is part of the implementation for #1355

This PR adds __attribute__((import_name(<name>)) declarations to every type signature corresponding to axioms with no-compile block that has an alpha numeric name in the entry point module (so that it can safely be present in the output C file).
This causes these functions to be present in the import table of the resulting WASM module.

To try this out:

cd tests/positive/MiniC/ImportExportName
juvix compile --runtime standalone Input.juvix

To see the imports and exports of the module:

wasmer inspect Input.wasm
Type: wasm
Size: 172 B
Imports:
  Functions:
    "env"."hostDisplayString": [I32] -> []
  Memories:
  Tables:
  Globals:
Exports:
  Functions:
    "juvixRender": [] -> []
  Memories:
    "memory": not shared (2 pages..)
  Tables:
  Globals:

You can then inject an implementation of hostDisplayString from nodeJS, which is called in Juvix and invoke the juvixRender Juvix function from the nodeJS file with:

node input.js
Hello World from Juvix!

@paulcadman paulcadman added this to the 0.2.3 milestone Aug 1, 2022
@paulcadman paulcadman self-assigned this Aug 1, 2022
@paulcadman paulcadman marked this pull request as draft August 1, 2022 09:54
@paulcadman paulcadman force-pushed the non-compile-axiom-import-name branch 2 times, most recently from 13be7f0 to 189a227 Compare August 1, 2022 11:07
@paulcadman paulcadman marked this pull request as ready for review August 1, 2022 13:08
@jonaprieto
Copy link
Collaborator

jonaprieto commented Aug 2, 2022

Awesome! Could you please add one entry in the documentation about this particular example, the Hello World? I'd put it in the section Tutorials.

This commit adds `__attribute__((input_name(<name>)))` to the type
signature of all axioms that do not have a compile block. This indicates
to the compiler that this function should be added to the input table of
the WASM binary.

Adds a test that an imported function can be called from Juvix.
@paulcadman paulcadman force-pushed the non-compile-axiom-import-name branch from a5962e6 to 557ca1d Compare August 2, 2022 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants