Litan
Litan copied to clipboard
Programming/scripting language
Litan
Litan is a gradual typed programming language with a C-like syntax. The Compiler and Bytecode-VM can be used as standalones or C++-Library to add scripts to any application.
Hello World
function main() {
std::println("Hello World");
}
Lamdas and Higher-Order-Functions
Litan has fully-featured lambda expressions and supports higher-order-functions.
function use_lambda(fx) {
return fx(1, 2);
}
function make_lambda(c)
=> lambda[c](a, b) => (a + b + c)
function main() {
std::println(use_lambda(make_lambda(3))); // 6
}
Reflections
Reflections allow you to gather infos about your programm at compile-time.
function main() {
std::println("Line: " + std::str(reflect(line))); // Line 2
}
Learn more
Structs
Litan uses structs whose members can added or removed dynamically.
function main() {
var object = std::struct();
object.foo = 42;
object.bar = 1337;
std::println(object.foo);
std::println(object.bar);
}
Useful Libraries
- Sphinx (Unit test framework)
Build, Use and Install
Requirements
- CMake 3.13 or newer
- A modern C++ compiler with C++20 support
- Clang++-10 or newer
- GCC-10 or newer
- stdxx library
Use as Standalone
- Clone the repository recursively.
- Run
./build.shto compile the compiler, vm and everything needed.- Note: Clang++ is choosen by default but this can be changed.
Just run
./build.sh COMPILER_GOES_HEREin this case.
- Note: Clang++ is choosen by default but this can be changed.
Just run
- Run
./install.shto install ltn, ltnc, ltnvm and ltninfo into the /usr/local/bin/ directory.
Use as library
- Add litan as a submodule to your project.
- Add stdxx as a submodule to your project.
- Add the litan subdirectory to your project: e.g.
add_subdirectory(libs/litan) - Link the library: e.g.
target_link_libraries(my_project litan) - Include the main header: e.g.
#include "libs/litan/Litan.hxx"
Special Thanks
Bob Nystrom: For his great book "Crafting Interpreters" which provided a large portion of the information I needed to realize this project.