An Onyx programming language compiler implementation.
The Fancy Onyx Compiler (FNXC) is an Onyx programming language compiler implementation built in C++ on top of LLVM.
Target ISAs supported by FNXC are i386
, amd64
, arm7
and arm8
.
The fnxc
binary implements the Onyx Compiler Interface standard (the build
and doc
commands), and does not peform neither linking nor dependency management.
For a fully-featured building environment, see Fancy Onyx, which may use FNXC as a dependency.
Additional features of FNXC include running a program in JIT mode, REPL and Onyx Language Server Protocol implementations, and formatting.
$ fnxc -h
Fancy Onyx Compiler, v0
Usage:
$ fnxc, fnxc repl Run the REPL
$ fnxc <file>, fnxc run <file> Run a file in JIT mode
$ fnxc build <file> Build a file in AOT mode
$ fnxc doc <file> Build documentation
$ fnxc serve Run the LSP server
$ fnxc format <file> Run the formatter
Options:
-[-h]elp Display help on topic
-[-v]ersion Display FNXC version
-
Clone the FNXC repository.
$ git clone https://github.com/fancysofthq/fnxc
-
Put the SQLite3 extensions source code under
lib/cpp/sqlite3/ext
, using either variant, so thenoop()
extension source code resides atlib/cpp/sqlite3/ext/misc/noop.c
.-
Use Fossil SCM.
$ mkdir lib/cpp/sqlite3 $ cd lib/cpp/sqlite3 $ fossil clone https://www.sqlite.org/src sqlite.fossil $ fossil open sqlite.fossil
-
Download a snapshot of the complete (raw) source tree from https://sqlite.org/download.html (e.g.
sqlite-src-3330000.zip
), and extract theext
folder tolib/cpp/sqlite3/ext
. -
TODO: Enable extensions in the VCPG
sqlite3
dependency.
-
-
Install LLVM
~> 10
with exception handling enabled. Make sure theLLVMConfig.cmake
file can be found at${LLVM_DIR}
(a variable later passed to CMake).When building LLVM from source, set the following CMake variables:
-DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_TARGETS_TO_BUILD=X86;ARM
For example, on a Windows x64 machine:
$ cmake \ -Thost=x64 \ -DCMAKE_C_COMPILER="C:/msys64/mingw64/bin/clang-cl.exe" \ -DCMAKE_CXX_COMPILER="C:/msys64/mingw64/bin/clang-cl.exe" \ -DCMAKE_LINKER="C:/msys64/mingw64/bin/lld-link.exe" \ -DCMAKE_RANLIB="C:/msys64/mingw64/bin/llvm-ranlib.exe" \ -DCMAKE_AR="C:/msys64/mingw64/bin/llvm-ar.exe" \ -DLLVM_ENABLE_WARNINGS=OFF \ -DLLVM_ENABLE_LTO=THIN \ -DLLVM_ENABLE_EH=ON \ -DLLVM_ENABLE_RTTI=ON \ -DLLVM_TARGETS_TO_BUILD="X86;ARM"
NOTE: For LTO usage with CLang, see https://clang.llvm.org/docs/ThinLTO.html#clang-bootstrap.
NOTE: The manual LLVM installation shall be replaced with VCPKG dependency. Right now it:
-
Does not support exception handling.
-
Does not allow to use compiler other than MSVC, which fails with some
inconsistent behavior between llvm:: and std:: implementation of is_trivially_copyable
error on my machine.
-
-
Install VCPKG. Make sure you have
vcpkg.exe
in yourPATH
environment variable. -
Configure the compiler using a recent CMake version. This will automatically install VCPKG dependencies.
# Note: change VCPKG_PATH and LLVM_DIR to reflect your environment $ cmake \ -DCMAKE_TOOLCHAIN_FILE=${VCPKG_PATH}/scripts/buildsystems/vcpkg.cmake \ -DLLVM_DIR=${LLVM_DIR}
-
Build the compiler.
$ cmake --build . -t fnxc $ ./fnxc -v
Pro tip: On Windows 10, temporaly disable Microsoft Defender Antivirual real-time protection to speed up the build.
-
(Optional) Run C++ tests during development
$ cmake --build . -t tests $ ctest
-
(Optional) Run Onyx tests once the compiler is compiled
$ ./fnxc ../test/nx/all.nx
NOTE: Do not clutter .gitignore
with files local to your workflow!
Use the $GIT_DIR/info/exclude
file instead, as per Git documentation.