Skip to content

SindarinSDK/sindarin-compiler

Repository files navigation

Sindarin (Sn) Programming Language

Sindarin is a statically-typed procedural programming language that compiles to C. It features clean arrow-based syntax, powerful string interpolation, and built-in array operations.

.sn source → Sn Compiler → C code → GCC/Clang → executable

Features

  • Static typing with explicit type annotations
  • Arrow syntax (=>) for clean, readable code blocks
  • String interpolation with $"Hello {name}!"
  • Arrays with built-in operations (push, pop, slice, join, etc.)
  • Structs for structured data and C library interop
  • String methods (toUpper, toLower, trim, split, splitLines, isBlank, etc.)
  • File I/O with TextFile and BinaryFile types
  • Control flow with for, for-each, while, match, break, continue
  • Module imports for code organization
  • Memory semantics with as ref/as val ownership and copy semantics
  • C interoperability with native functions, pointers, and callbacks
  • SDK modules for crypto, networking, JSON/XML/YAML, compression, and more

Installation

Linux / macOS

curl -fsSL https://raw.githubusercontent.com/SindarinSDK/sindarin-compiler/main/scripts/install.sh | bash

Windows

irm https://raw.githubusercontent.com/SindarinSDK/sindarin-compiler/main/scripts/install.ps1 | iex

See docs/building.md for building from source and other installation options.

Quick Start

# Compile a program
sn samples/main.sn -o myprogram
./myprogram

# Or emit C code only
sn samples/main.sn --emit-c -o output.c

Example

fn is_prime(n: int): bool =>
  if n <= 1 =>
    return false
  var i: int = 2
  while i * i <= n =>
    if n % i == 0 =>
      return false
    i = i + 1
  return true

fn main(): void =>
  var primes: int[] = {}
  for var n: int = 2; n <= 50; n++ =>
    if is_prime(n) =>
      primes.push(n)
  print($"Primes: {primes.join(\", \")}\n")

Documentation

Language

Document Description
Overview Language philosophy, syntax overview, examples
Building Build instructions for Linux, macOS, Windows
Strings String methods and interpolation
Arrays Array operations and slicing
Structs Struct declarations and C interop
Match Match expressions for multi-way branching
Lambdas Lambda expressions and closures
Memory Ownership model, as ref/as val semantics, and memory management
Threading Threading with spawn and sync
Namespaces Namespaced imports for collision resolution
Interop C interoperability and native functions

SDK Modules

SDK documentation is available at sindarin-pkg-sdk.

Document Description
SDK Overview All SDK modules
Crypto Hashing, encryption, HMAC, PBKDF2, secure random
Date Calendar date operations
Time Time and duration operations
Random Random number generation
UUID UUID generation and manipulation
Environment Environment variable access
Process Process execution and output capture
Math Mathematical functions and constants
JSON JSON parsing and serialization
XML XML parsing, XPath, and DOM manipulation
YAML YAML parsing and serialization
ZLib Compression and decompression
Stdio Standard input/output/error streams
File I/O TextFile, BinaryFile, Path, Directory, Bytes
Networking TCP, UDP, TLS, DTLS, SSH, QUIC

Architecture

Source (.sn)
    ↓
Lexer → Parser → Type Checker → Optimizer → Code Gen → GCC
    ↓
Executable

See src/ for compiler implementation details.

Testing

make test                    # All tests
make test-unit               # Unit tests only
make test-cgen               # Code generation tests (compare generated C)
make test-mgen               # Model generation tests (compare JSON model)
make test-integration        # Integration tests only
make test-integration-errors # Integration error tests
make test-explore            # Exploratory tests only
make test-explore-errors     # Exploratory error tests

Or use the test runner directly (cross-platform):

python3 scripts/run_tests.py all                # All tests
python3 scripts/run_tests.py unit               # Unit tests
python3 scripts/run_tests.py cgen               # Code generation tests
python3 scripts/run_tests.py mgen               # Model generation tests
python3 scripts/run_tests.py integration        # Integration tests
python3 scripts/run_tests.py integration-errors # Integration error tests
python3 scripts/run_tests.py explore            # Exploratory tests
python3 scripts/run_tests.py explore-errors     # Exploratory error tests

Project Structure

├── src/           # Compiler source (lexer, parser, type checker, codegen, runtime)
├── sdk/           # SDK modules (.sn definitions + .c implementations)
├── tests/         # Unit, integration, SDK, and exploratory tests
├── docs/          # Language and SDK documentation
├── samples/       # Example .sn programs
├── scripts/       # Test runner and dependency setup
├── packaging/     # Distribution packaging (deb, rpm, homebrew, winget, arch)
├── benchmark/     # Performance benchmarks
├── bin/           # Compiled outputs (sn compiler, runtime library, SDK)
└── CMakeLists.txt # CMake build configuration

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Run tests with make test
  4. Submit a pull request

License

MIT License - feel free to use, modify, and distribute!


Named after the Elvish language from Tolkien's legendarium

About

The sindarin language compiler

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors