PyMor is a small hobby compiler for the Môr programming language written in Python. The language aims to provide C-like power with a friendlier syntax and some safety-oriented features.
Môr currently compiles to C for portability and interoperability with existing C code.
This is a hobby project and is still experimental. The compiler is usable for small programs but the language and implementation may change frequently. Features are still being improved.
Hello world
def main(u0) -> i32:
print("Hello world")
return 0
Bubble sort
#include <stdio.h>
extern def printf(u8[], i32) -> u0
def swap(i32[] arr, u32 i, u32 j) -> u0:
i32 temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
def bubble_sort(i32[] arr, u32 n) -> u0:
for u32 i = 0; i < n - 1; i += 1:
for u32 j = 0; j < n - i - 1; j += 1:
if arr[j] > arr[j + 1]:
swap(arr, j, j+1)
def dont_sort(i32[] arr, u32 n) -> u0:
return
typedef fn(i32[], u32) -> u0 SortFunction
def main(u0) -> i32:
i32[] arr = [5, 6, 1, 3]
i32 n = (sizeof arr) / (sizeof arr[0])
ptr SortFunction sort_function = &bubble_sort
sort_function(arr, n)
for u32 i = 0; i < n; i += 1:
printf("%d ", arr[i])
return 0
No installation required beyond Python.
python -m mor [options] files
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
make
The executable will be generated in dist/.
usage: python -m mor [options] files
options:
-h, --help Display help message.
-o, --out OUT Output filename.
-I INCLUDES File includes directory.
--emit-c, -c Emit generated c code.
--ast Print a representation of the AST.
--typed-ast Print a representation of the AST with type information.
--crash Crash on error with full stack trace.
--run-immediately Immediately run generated executable.
--no-runtime Do not include the Môr runtime library (will break features).
OR with an executable
mor.exe [options] file
mor [options] file
Môr is a small programming language inspired by C, HolyC, and (syntactically) Python. It aims to match C functionality but with a friendlier syntax, some convenient constructs, and some improved security. It compiles to C and is intended for easy interoperability with C via the extern keyword.
WIP
- Parser error recovery is incomplete
- Error collection is not implemented in all compilation stages
- Generated C code currently produces several compiler warnings
- Preprocessor
- Lexing
- Parsing
- Semantic analysis
- statements
- expressions
- Security pass
- Code generation
-
while -
if/else -
return -
for -
break/continue - pointers/arrays
- functions
- structs
-
sizeof - variadic functions
-
switch - ternary operator
-
union -
enum
-
bool - struct literals
-
unsafe -
optional -
auto - for x in y
-
defer -
assert - dynamic array (
list) - slices
-
class
mor/ Compiler implementation
mor-extension/ VS Code syntax highlighting extension
examples/ Example programs
tests/ Compiler tests