The documentation for dusk can be found here
A simple programming language built from scratch.
The build scripts use CMake and Ninja to find dependencies and build the project.
Uses flex as a tokenizer.
Uses bison as a parser generator.
The AST is generated with C++.
LLVM is used as a backend to generate machine specific object files which are then compiled with a c compiler into an executable.
This project requires flex, bison, llvm, GNU GMP, and a c/c++ compiler.
The examples for building this project also include ninja, but that is an optional dependency.
Clone the repository, and run deps.sh to automatially install LLVM locally to this project.
git clone --recurse-submodules https://gitlab.com/kian_shepherd/Dusk.git
cd Dusk
./deps.sh
To use the bignum.ds library you also need the GNU Multiple Precision Arithmetic Library
You can find the most recent version here.
./configure --disable-shared --enable-fat --enable-cxx
make
Run the tests before installing
make check
Finally install GMP
make install
Ensure you have flex and bison and build tools
sudo apt install cmake ninja-build flex libfl-dev bison libbison-dev
Ensure you have flex and bison and build tools
brew install bison flex cmake ninja
An old version of bison is the default version so you must relink a newer version to build Dusk
brew unlink bison
brew link bison --force
echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"'>> ~/.zshrc
To generate a compile_commands.json file for use with ccls run
./ccls_file_gen.sh
To build the project run or simply run build.sh.
cmake -G Ninja -S . -B CMake
ninja -C CMake
or
./build.sh
To install the binary run.
ninja -C CMake install
Once it is installed you can run dusk x, where x is the name of the file you wish to compile.
For example
dusk test.ds
Would compile a file named test.ds into an executable.
The help menu can be viewed like so.
$ dusk -h
Usage: dusk [options] file...
Options:
-h Display this information.
-d Print out debug information about the final AST and LLVM IR.
-df Print out debug information about the AST at each stage and LLVM IR.
-da Print out debug information about the final AST.
-daf Print out debug information about the AST at each stage.
-di Print out debug information about the LLVM IR.
-dc Print out debug information about the compile commands.
-O Optimize the generated object / executable.
-c Only compile the sources do not link into executable.
-o <file> Set the name of the outputted object / executable.
-cc <compiler> Set the c / c++ compiler to use (default is g++).
-l<library> Add library to link to executable at compile time.
-L<path> Add path to library link paths.
-I<path> Add path to include file paths.
- Base types
- Atomic types
- i1: boolean
- i8: char (equivalent to C char)
- i64: int (equivalent to C long)
- i128: long (equivalent to C long long)
- f64: float (equivalent to C double)
- String struct for easier managing of string like objects
bignum.dsalso provides these for handling of float and integer numbers of unbounded size- BigInt
- BigFloat
vector.dsalso provides these for handling of various vector types.- Vec
- Vec
- Vec template type for other Structs
linkedlists.dsalso provides these for handling of various linked list types- LinkedList
- LinkedList template type for other Structs
- Array Types
- boolean array
- strings
- int array
- float array
- string arrays (array of char's)
- Vector Types under
vector.ds- String
- int
- float
- User Defined Structs
- Member fields
- Heap allocated
- Constructor overloading
- Operator overloading
- Method Overloading
- Automatic Reference Counting
- Destructors
templatekeyword- Template Structs can be created that are generic over Struct types.
- Supports Templated member fields
- Supports Templated methods
- Can also override specific templated typed functions
- Atomic types
- Functions
mainas entry point- accepts and handles command line arguments
- Can be self recursive
- Optimized so tail call omptimization can be preformed to remove recursive calls where possible
- Can pass arguments to and from
- Can be void
- Variables are properly scoped to be function and block specific
externkeyword to loadCfunctions from libraries (included them in the compilation usingrequiresor-lon the command line)importandrequirekeywords- Can import other
.dsfiles without including them in the CLI - Can require
Clibraries at link time
- Can import other
- Static checking
- Ensure
mainfunction is present and only one exists - Checks for non mutable vairables being mutated
- Ensure
- CLI for dusk executable
- Can print help info on how to use it
- Standard Library
- Base standard library functions
- Casting functions
copyfunctions to allocate on the heapdelfunction to delete heap allocated objects
types.ds(Part of the base standard library)Stringstruct for better string datatypes support
stdio.ds(Part of the base standard library)printfunction, takes C style format stringsinputfunctionreadfilefunction
bignum.dsBigIntstruct for integer numbers of unbounded sizeBigFloatstruct for floating point numbers of unbounded size
vector.ds- Various
Vectypes.Vec<int>Vec<float>Vec<String>
- Various
math.dspowfor int typesfpowfor floating power
- Base standard library functions
- Improve Templates
- Add supprt for multiple templated types
- Improve Automatic Reference Counting
- There are currently a few edge cases around calls to
__INCREF__and__DECREF__that aren't currently implemented.- As I continue to add test caases and catch these more will be fixed.
- There are currently a few edge cases around calls to
stdlibimprovements- More abstract datatypes
- LinkedList
- General Improvements on functionality
- Map
- Set
- LinkedList
- More general functionality
- IO
writefile
- Math functions
- String manipulation
- ...
- IO
- ...
- More abstract datatypes
__iter__method function for structs for loopingfor (v: vec) { ... }- Better compile time failure error messages
- show line that error occured on
This project is licensed under GNU GPLv3, as this project depends on bison.