Sigil, the programming language
Find a file
rdenadai ee2f10ea61
All checks were successful
Sigil / test (3.11.9) (push) Successful in 1m1s
Sigil / test (3.12.3) (push) Successful in 58s
Sigil / test (3.13.0) (push) Successful in 1m0s
Update .forgejo/workflows/python-tests.yml
2025-10-30 12:27:11 +00:00
.forgejo/workflows Update .forgejo/workflows/python-tests.yml 2025-10-30 12:27:11 +00:00
.vscode feat: Sigil Lexer v0.0.1 2025-09-17 22:11:14 -03:00
src fix: Import 2025-09-26 21:49:14 -03:00
static docs: Readme improvements 2025-09-20 00:47:02 -03:00
tests fix: Import 2025-09-26 21:49:14 -03:00
.gitignore Initial commit 2025-09-16 09:44:01 -03:00
conftest.py chore: github workflow for tests 2025-09-23 00:40:00 -03:00
LICENSE Initial commit 2025-09-16 09:44:01 -03:00
pyproject.toml fix: Import 2025-09-26 21:49:14 -03:00
README.md chore: Moving to Forgejo 2025-10-29 09:51:51 -03:00
uv.lock fix: Import 2025-09-26 21:49:14 -03:00

Sigil

Sigil programming language logo

A modern programming language.


Warning

Sigil is a work in progress and is not yet stable. It is under active development, and breaking changes are expected.

Requirements

To build and run Sigil, you need the following dependencies installed on your system:

  • Python 3.12+: Can be installed using pyenv or asdf.
  • uv: A fast Python package installer from Astral.
  • LLVM: The compiler infrastructure.
  • GCC: The GNU Compiler Collection.

Architecture

The Sigil compiler is built with a modular architecture, following a classic multi-stage compilation pipeline. The entire frontend is written in Python.

+-----------------------------------+
|      Frontend (Python)            |
+-----------------------------------+
|                                   |
|      Source Code (.sl)            |
|           |                       |
|           v                       |
|         Lexer --(Tokens)-->       |
|           |                       |
|           v                       |
|         Parser --(AST)-->         |
|           |                       |
|           v                       |
|   Semantic Analyzer --(Validated AST)--> |
|           |                       |
|           v                       |
|     Code Generator                |
|           | (LLVM IR)             |
|           v                       |
+-----------------------------------+
              |
              v
+-------------------------------------+
|    Backend (LLVM Toolchain)         |
+-------------------------------------+
|                                     |
|       LLVM IR (.ll)                 |
|           |                         |
|     +-----+------+                  |
|     |            |                  |
|     v            v                  |
| opt (Optional)   llc                |
|     |            ^                  |
| (Optimized IR)   |                  |
|     |            |                  |
|     +------>-----+                  |
|                  | (Object File .o) |
|                  v                  |
|                 gcc                 |
|                  | (Executable)     |
|                  v                  |
|             Executable              |
|                                     |
+-------------------------------------+
  1. Lexical Analysis (Lexer): The source code is first processed by the lexer, which scans the text and converts it into a stream of tokens. This stage handles indentation, comments, and the basic elements of the language like keywords, identifiers, and operators.

  2. Syntactic Analysis (Parser): The parser takes the stream of tokens and constructs an Abstract Syntax Tree (AST). This tree represents the hierarchical structure of the code and validates it against the language's grammar.

  3. Semantic Analysis (Analyzer): The semantic analyzer traverses the AST to check for semantic correctness. It builds a symbol table to track variables, functions, and types, ensuring that the code is logically sound (e.g., type checking, scope resolution).

  4. Code Generation (CodeGenerator): After analysis, the code generator walks the AST and translates it into LLVM Intermediate Representation (IR).

  5. Backend Compilation: The generated LLVM IR is then passed to the LLVM toolchain:

    • opt: An optional step to optimize the LLVM IR.
    • llc: Compiles the IR into a native object file (.o).
    • gcc: Links the object file to produce a final executable.

How to Run

To compile a Sigil file (.sl), run the main.py script. The compilation artifacts, including tokens, AST, LLVM IR, and the final executable, will be placed in the build/ directory.

Basic Compilation:

uv run python src/main.py examples/hello_world.sl

Compile and Run:

To compile and immediately execute the resulting program, use the --run flag.

uv run python src/main.py examples/hello_world.sl --run

Compile with Optimizations:

To enable LLVM optimizations at the -O3 level, use the --optm flag. Currently, only -O3 is supported; other optimization levels are not available.

uv run python src/main.py examples/hello_world.sl --optm --run