eyg_compile

EYG compiler that transpiles to JavaScript.

Package Version Hex Docs

gleam add eyg_compiler
import eyg/compiler
import eyg/ir/tree as ir
import gleam/dict

pub fn main() {
  let source = ir.let_("x", ir.integer(5), ir.variable("x"))
  let refs = dict.new()
  compiler.to_js(source, refs)
  // let x$0 = 5;
  // x$0
}

Further documentation can be found at https://hexdocs.pm/eyg_compile.

Development

gleam run
gleam test

Notes

Compilation path follows two main resources.

The current implementation uses a js version of a monad, something is an instance of an Eff or not. If not is is assumed a value. This is similar to thinking of value or null being an Option.

This allows the transpiled JS to look as similar as possible to the original source. There is no lambda lifting or closure conversion and there is no global yielding variable. These are not necessary when relying on the dynamism of JS.

Such an implementation is ineffecient as it always bubbles the effect, there is no evidence passing. A future version could add the evidence vector and other optimisation, however:

It’s probably worth considering what compilation to tiny go or an arduino interpreter looks like.

Search Document