Skip to content

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 the compile() 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. The context 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 to compile().
  • main.rs — This file is used in place of lib.rs when compiling into an executable (e.g. for debugging).
Clone this wiki locally