-
Notifications
You must be signed in to change notification settings - Fork 7
Main Driver
Bernard Teo edited this page Apr 18, 2020
·
1 revision
This crate is the only crate that interfaces with the host environment. It contains the only function (compile()
) that can be called by the host (i.e. JavaScript). It simply invokes Frontend-ESTree, followed by Backend-Wasm, followed by Wasmgen's binary encoder.
There are two files:
-
lib.rs
— The file which contains thecompile()
function callable by JavaScript. The#[wasm_bindgen]
annotation makes the Rust compiler generate the necessary bindings to allow the function to be callable from the host. Thecontext
parameter is an opaque value that is passed into any host imported function called from our compiler (such as compile error/warning reporting). It allows the host to associate the callback with the corresponding call tocompile()
. -
main.rs
— This file is used in place oflib.rs
when compiling into an executable (e.g. for debugging).