OpenLatinum is a statically typed programming language with Latin-inspired syntax. It compiles .lat source files to stack-based bytecode. The compiler is available in both Python and Rust and supports multiple compilation paths for teaching and experimentation.
This project is a community-driven evolution of the original OpenLatinum compiler (University of Minho, 2022).
git clone https://github.com/awdemos/OpenLatinium.git
cd OpenLatinum
pip install -e .git clone https://github.com/awdemos/OpenLatinium.git
cd OpenLatinum
cargo build --workspace
cargo test --workspacedocker build -t openlatinum .
docker run --rm -v $(pwd):/app openlatinum build examples/hello_world.latlat build examples/hello_world.latSingle-line comments with //:
// This is a commentMultiline comments with /* */:
/*
This is a multiline comment
*/integer,float,filum: Basic types&integer,&float,&filum: Pointer typesvec<integer>,vec<float>,vec<filum>: Array types
+,-,*,/operators==,!=,<,>,<=,>=operatorset,aut(logical AND, OR)non(logical NOT)
Pointer arithmetic:
+adds an integer to a pointer-subtracts an integer from a pointer>,<,>=,<=compare two pointers
Declare and initialize:
a: integer = 10Declare only (initialized to 0):
a: integerReassign:
a = 20a: vec<integer>[10] // Size-based declaration
a: vec<integer> = [10, 20, 30] // List initialization
a: vec<integer> = [1 ... 10] // Range initializationAccess:
a[0]si (if):
si expression {
// code
} aliter {
// code
}par (match):
par expression {
expression -> {
// code
}
defectus -> {
// code
}
}dum (while):
dum expression {
// code
}facio dum (do-while):
facio {
// code
} dum(expression)enim (for):
enim(i: integer = 0; i < 10; i = i + 1) {
// code
}munus sum(a: integer, b: integer) -> integer {
reditus a + b
}Call:
sum(10, 20)lat [MODE] [INPUT] [OPTIONS]
Modes:
run Compile and run the program
build Compile the program to bytecode
test Compile and run test programs
euler Check Euler problem solutions
examples Compile and run example programs
Options:
-h, --help Show help
-o, --output Specify output file
-v, --verbose Show verbose output
--ast Use AST-based compiler path
--ir Use IR pipeline (AST → IR → bytecode)
--check Semantic analysis only (no codegen)
-rec, --record Record program outputs
-clc, --clean-up Clean generated files
Run all unit tests:
python -m pytest tests/ -vRun specific test files:
python -m pytest tests/test_parser.py -v
python -m pytest tests/test_semantic.py -v
python -m pytest tests/test_codegen.py -vRun the Rust workspace tests:
cargo test --workspaceRun with output:
cargo test --workspace -- --nocaptureRun the full test suite against .lat programs:
lat testRun with verbose output:
lat test -vRun with AST compiler path:
lat test --astOpenLatinum has two execution backends:
-
C VM (original): The bytecode runs on a C-based stack VM. Build from
vms-source.zip:unzip vms-source.zip -d /tmp/vms cd /tmp/vms/vms make -
Python Interpreter (new): The bytecode can also run on a pure Python interpreter included in the compiler. This eliminates the C VM dependency for development and testing.
The Python interpreter is transparent to the user - the same .vms bytecode files work with both backends.
The compiler has three Python compilation paths and a Rust compiler frontend:
- Original:
lat/lexing/_lexer.py→lat/parsing/_parser.py→lat/semantics/*→ bytecode (single-pass, syntax-directed) - AST path (
--ast):lat/parsing/ast_parser.py→lat/semantic/analyzer.py→lat/codegen/generator.py→ bytecode - IR path (
--ir): AST →lat/ir/generator.py→lat/ir/nodes.py→lat/codegen/from_ir.py→ bytecode
A Rust implementation of the compiler frontend (lexer → parser → AST → semantic analysis) is available in the lat-core crate. It can be used as a library or via the lat! procedural macro for embedding OpenLatinum code in Rust programs.
Workspace crates:
lat-core— Lexer, parser, AST, and semantic analyzer (Rust)lat-macro— Procedural macros (thelat!macro)lat— Integration tests and CLI bindings
Key modules:
lat/cli.py— Entry point, argument parsing, test runnerlat/parsing/ast_parser.py— PLY-based parser that builds AST (lat/ast/nodes.py)lat/semantic/analyzer.py— Visitor-based semantic analyzer with error collectionlat/codegen/generator.py— AST-to-bytecode generator (produces EWVM instructions)lat/vm_interpreter.py— Python bytecode interpreter for executing.vmsfileslat/ir/generator.py— AST-to-IR converter (three-address code)lat/codegen/from_ir.py— IR-to-bytecode generatorlat-core/src/— Rust lexer, parser, AST, and semantic analysis
| Latin | English | Purpose |
|---|---|---|
si |
if | Conditional |
aliter |
else | Alternative branch |
par |
match | Pattern matching |
casus |
case | Match case |
defectus |
default | Default case |
dum |
while | While loop |
facio |
do | Do-while loop |
enim |
for | For loop |
confractus |
break | Break out of loop |
pergo |
continue | Continue to next iteration |
munus |
function | Function declaration |
reditus |
return | Return from function |
et |
and | Logical AND |
aut |
or | Logical OR |
non |
not | Logical NOT |
imprimo |
Print statement | |
legerei |
read_int | Read integer |
legeref |
read_float | Read float |
legeres |
read_string | Read string |
integer |
int | Integer type |
float |
float | Float type |
filum |
string | String type |
vec |
array | Array type |
This is an open-source community project. Contributions welcome!
MIT License - See LICENSE file for details.