Skip to content

Implement foreign export javascript#492

Open
Tritlo wants to merge 1 commit into
augustss:masterfrom
Tritlo:master
Open

Implement foreign export javascript#492
Tritlo wants to merge 1 commit into
augustss:masterfrom
Tritlo:master

Conversation

@Tritlo

@Tritlo Tritlo commented Jul 1, 2026

Copy link
Copy Markdown

The parser already accepted it; the calling convention was dropped in Desugar. It now reaches makeFFI (an FE/FEJS marker pair, and an IsJavascript flag through the export table), where a javascript export differs from a ccall one in two ways: the generated wrapper is EMSCRIPTEN_KEEPALIVE, so it is a wasm export without any EXPORTED_FUNCTIONS listing, and the type table also allows Bool, marshalled by new mhs_from_Bool/mhs_to_Bool runtime adapters (a Bool is the K (False) or A (True) combinator, not an int node). Compile a module with -c, link with emcc, and JS calls the exports directly:

m._mhs_init();
m._addOne(41);

A define-empty fallback keeps the generated C compiling natively. Tested by testforexpjs (opt-in: needs emcc and node).

The parser already accepted it; the calling convention was dropped in
Desugar.  It now reaches makeFFI (an FE/FEJS marker pair, and an
IsJavascript flag through the export table), where a javascript export
differs from a ccall one in two ways: the generated wrapper is
EMSCRIPTEN_KEEPALIVE, so it is a wasm export without any
EXPORTED_FUNCTIONS listing, and the type table also allows Bool,
marshalled by new mhs_from_Bool/mhs_to_Bool runtime adapters (a Bool
is the K (False) or A (True) combinator, not an int node).  Compile a
module with -c, link with emcc, and JS calls the exports directly:

    m._mhs_init();
    m._addOne(41);

A define-empty fallback keeps the generated C compiling natively.
Tested by testforexpjs (opt-in: needs emcc and node).
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

Successfully merging this pull request may close these issues.

1 participant