Jarlang is an Erlang compiler which outputs to ES6 spec JavaScript, written in a combination of Erlang and JavaScript (NodeJS).
Jarlang is implemented via the following, simple, pipeline:
- Utilising the Erlang compiler, we generate Erlang's intermediate language, CoreErlang
- Utilise built in Erlang tools to generate an abstract syntax tree from generated CoreErlang, not too dissimilarly from projects such as LuvvieScript and ElixirScript
- Map the generated CoreErlang abstract syntax tree into an equivalent JavaScript abstract syntax tree
- Utilise NodeJS and tools such as escodegen to generate valid JavaScript.
Our JavaScript AST is based off the documentation you can find here: JSTree AST.
Jarlang is still in development and can't at this time can only transpile trivial pieces of Erlang to JavaScript. The following instructions will help you get an environment set up for development and testing purposes only. This tool is not at all ready for any real world usage.
- Erlang 18 (Other versions may work, but any development and testing so far has only been done using version 18)
- NodeJS v8.8.0 (Other versions may work, but any development and testing so far has only been done using v8.8.0)
- Clone the repo with
git clone https://github.com/vereis/jarlang
on the commandline which should create ajarlang
folder containing all our source code - Go into the
jarlang
folder withcd jarlang
- Get required NodeJS packages with the command
npm install
- Run the
make
ormake debug
commands which will build either the release build of Jarlang or the debug build of Jarlang respectively. - Run
jarlang
with the commandebin/jarlang
oredebug/jarlang
followed by paths to erlang files to compile into JavaScript. Additional info is available if you run the commandjarlang -h
. - Add jarlang.js to your webpage and whatever erlang code you've transpiled and hope it all works out :)
Run the command make test
which will compile the project into the etesting
directory and run the following tests:
- Eunit tests in all modules where we have tests implemented
- Dialyzer performing static analysis of Jarlang
- Elvis to lint our code to confirm to a given style
Eventually, we will need to add some rudimentary testing on the JavaScript side, as well as testing to ensure the results of running Erlang code and transpiled JavaScript code are functionally the same.
- The escodegen guys for making generating JavaScript code so painless.
- The people who documented the EStree specification. Thank you. So much.