Tool | Installation |
---|---|
opam | apt install opam |
llvm | apt install llvm |
gcc | apt install gcc |
Install llvm package for OCaml:
opam install llvm
Install Dependency
opam install ocamlformat
Format the source file and replace with corrected versions, detailed instruction can go to Dune's manual.
dune build @fmt --auto-promote
Install ounit2 package:
opam install ounit2
Build test code:
ocamlbuild -use-ocamlfind -pkgs ounit2 test.native
Run all test cases:
./test.native
Or simply run:
./run_unit_tests.sh
All test cases are in directory test_cases
, where *.gs
are the source programs and *.out
are the expected output. To run all test cases:
./run_integration_tests.sh
Build the GoSci compiler
ocamlbuild -pkgs llvm main.native
Run the GoSci compiler
./main.native <action> [outfile]
And action
can be:
scan
: generate sequence of tokensparse
: generate the abstract syntax tree (AST)scheck
: generate a semantically-checked ASTirgen
: generate LLVM codecodegen
: generate assembly code<outfile>.s
compile
: generate executable with filenameoutfile
run
: compile then execute the program
ast.ml
: abstract syntax tree (AST)scanner.mll
: scannergosciparse.mly
: parsersast.ml
: semantically-checked AST (sAST)semant.ml
: turn an AST to an sASTirgen.ml
: turn sAST to llvm modulemain.ml
: top-level file to run the compiler
test.ml
: test cases for unit testsrun_unit_tests.sh
: shell script to run all unit teststest_cases/*
: test cases for integration testsrun_integration_tests.sh
: shell script to run all integration testscheck.sh
: format the code and run all the tests
example.gs
: a sample GoSci code of all usageexample_demo.gs
: a sample GoSci code of a physics simulation