bal build
in the compiler
directory; this will generate a file target/bin/nballerina.jar
. This should work on any system that Ballerina works on.java -jar nballerina.jar example.bal --backend wasm
to compile a Ballerina module into an wat
file example.wat
(note that the backend only supports upto subset 09). Make sure you invoke the nballerina.jar
file inside the cloned nBallerina directory.wat
file into a wasm
file use the wasm-opt
tool in the Binaryen tool chain.
./wasm-opt -O3 example.wat -o example.wasm -all
wasm
file. Use the main.js file inside the wrun
folder. (Supports NodeJs version 17 and 16. Doesn't support NodeJs version 18)
node --experimental-wasm-eh --experimental-wasm-gc main.js example.wasm
The compiler is tested using the test cases in the compiler/testSuite directory. The bal build
command performs a first level of testing on these: it checks that the test cases that should get compile errors do, and that the test cases that should not get compile errors do not. This should work on any platform on which the Ballerina distribution works.
For those test cases that are valid Ballerina programs, the Makefile in the test directory is used to further test that the generated wasm
files can be compiled and produce the expected output when executed. This Makefile has the following targets:
test
(the default target) forces a rebuild of all the .ll
files and wasm
files if the compiler jar has changed, and then does compile
, testwat
and testll
compile
builds any out of date .ll
files (but does not consider the compiler jar when determining whether a .ll
is out of date)testll
builds an executable for each test case, executes it and checks its outputtestwat
builds an executable for each test case, executes it and checks its outputWasm backend supports upto subset 14. A blog post on compiler operation.