tspp is an innovative programming language that brings together the familiar syntax of TypeScript with the performance and concurrency model of Go. It compiles to LLVM IR, enabling high-performance native code generation while providing advanced memory management, explicit control over memory regions, smart pointers, and zero-cost abstractions.
π Performance-First: Compiles to optimized LLVM IR
π Memory Safety: Explicit memory region control (#stack, #heap, #static)
π§ Smart Pointers: Built-in support for #shared<T>, #unique<T>, #weak<T>
β‘ SIMD Operations: Native vectorization with #simd
π§ Zero-Cost Abstractions: #zerocast for compile-time optimizations
π‘οΈ Safety Controls: @unsafe annotations for explicit unsafe operations
π― TypeScript Syntax: Familiar syntax for web developers
π Go Semantics: Goroutine-inspired concurrency model
The project is organized as follows:
src/: Source code for the compiler components.lexer/: Lexical analysis and tokenization.parser/: Parsing logic and AST construction.ast/: Abstract Syntax Tree node definitions.codegen/: LLVM IR code generation.interpreter/: JIT interpreter for REPL.core/: Common utilities and diagnostics.tokens/: Token definitions.main.cpp: Compiler entry point.
docs/: Documentation files.tests/: Test suite.scripts/: Helper scripts for installation and setup.
- C++ Compiler: GCC 9+ or Clang 10+
- CMake: Version 3.14 or higher
- LLVM: Version 17 or higher
- Boehm GC: For garbage collection support
sudo apt-get update
sudo apt-get install build-essential cmake llvm-17 llvm-17-dev libgc-devbrew install cmake llvm bdw-gc# Clone the repository
git clone https://github.com/theQuarky/tspp.git
cd tspp
# Build the project
./build.sh
# The binary will be located at ./build/src/tsppCreate a file called hello.tspp:
// hello.tspp - A simple tspp program
#stack string message = "Hello, tspp World!";
function main(): void {
console.log(message);
// Demonstrate memory regions
#heap int* numbers = new int[10];
#stack int counter = 0;
// SIMD operations
#simd float[4] vector = [1.0, 2.0, 3.0, 4.0];
// Smart pointer usage
#shared<MyClass> obj = make_shared<MyClass>();
// Compile-time constants
#const int BUFFER_SIZE = 1024;
}
class MyClass {
#private int value;
constructor(val: int) {
this.value = val;
}
#public getValue(): int {
return this.value;
}
}Compile and run:
./build/src/tspp hello.tspp
# Output: Hello, tspp World!tspp provides explicit control over memory regions:
#stack int localVar = 42; // Stack allocation
#heap int* dynamicVar = new int(42); // Heap allocation
#static int globalVar = 42; // Static/global allocationBuilt-in smart pointer support for safe memory management:
#shared<Resource> resource = make_shared<Resource>();
#unique<Buffer> buffer = make_unique<Buffer>(1024);
#weak<Resource> weakRef = resource.weak_from_this();Native SIMD support for high-performance computing:
#simd float[4] vector1 = [1.0, 2.0, 3.0, 4.0];
#simd float[4] vector2 = [5.0, 6.0, 7.0, 8.0];
#simd float[4] result = vector1 + vector2; // Vectorized additionCompile-time optimizations with zero runtime overhead:
#zerocast function<T> max(a: T, b: T): T {
return a > b ? a : b;
}
#const int result = max(10, 20); // Resolved at compile timetspp follows a modern compiler architecture:
flowchart TD
A[Source Code] --> B[Lexer]
B --> C[Parser]
C --> D[AST]
D --> E[Type Checker]
E --> F[LLVM IR Generator]
F --> G[Optimization]
G --> H[Native Code]
- Lexer: Tokenizes tspp source code
- Parser: Builds Abstract Syntax Tree (AST)
- Type System: Advanced type checking and inference
- Code Generator: LLVM IR generation
- Runtime: Garbage collection and memory management
- Standard Library: Core functionality and utilities
- π Language Specification - Complete language reference
- ποΈ Architecture - High-level compiler architecture
- π§ Compilation Pipeline - How tspp works internally
- π» Development Setup - Setting up the dev environment
- π Grammar Reference - EBNF grammar specification
- π― Examples - Sample programs and tutorials
We welcome contributions! Please see our Contributing Guide for details.
- π Report a Bug
- β¨ Request a Feature
- π¬ Join Discussions
This project is licensed under the MIT License - see the LICENSE file for details.
- Goroutines: Implement
gokeyword for lightweight thread creation - Channels: Typed channels with buffered/unbuffered variants (
chan T,chan<- T,<-chan T) - Select Statement: Multi-way communication with timeout support
- WaitGroups: Synchronization primitives for goroutine coordination
- Mutexes: Read/write mutexes for shared memory protection
-
mark_shared<T>(): Memory sharing annotation for concurrent access -
make(): Dynamic allocation for slices, maps, channels -
new(): Zero-value allocation for any type -
len(): Length function for collections (arrays, slices, maps, strings, channels) -
cap(): Capacity function for slices and channels -
close(): Channel closing mechanism -
copy(): Slice copying with overlap handling -
append(): Slice append with automatic growth -
delete(): Map key deletion -
panic()/recover(): Error handling mechanism
- Interfaces: Method set definitions and dynamic dispatch
- Type Assertions: Runtime type checking (
x.(T),x.(type)) - Type Switches: Pattern matching on interface types
- Slices: Dynamic arrays with length/capacity (
[]T) - Maps: Hash table implementation (
map[K]V) - Method Sets: Interface satisfaction checking
- Defer Statements: Deferred execution with LIFO ordering
- Range Iteration: For-range over slices, maps, channels, strings
- Labeled Breaks/Continues: Multi-level loop control
-
context: Cancellation and deadline propagation -
errors: Error creation and handling utilities -
fmt: Formatted I/O (Printf, Sprintf, etc.) -
io: I/O primitives (Reader, Writer, Closer interfaces) -
sort: Sorting algorithms and interfaces -
strings: String manipulation utilities -
strconv: String conversions (Atoi, Itoa, etc.) -
time: Time and date handling with timezones
-
net: TCP/UDP socket programming- TCP server/client implementation
- UDP socket support
- Unix domain sockets
- IP address parsing and manipulation
-
net/http: HTTP client and server- HTTP/1.1 and HTTP/2 support
- Middleware system
- WebSocket support
- TLS integration
-
net/url: URL parsing and manipulation -
net/smtp: SMTP client implementation
-
os: Operating system interface- File operations (create, open, read, write, delete)
- Directory operations (mkdir, readdir, walk)
- Process management (exec, fork, wait)
- Environment variables
- Signal handling
- User and group information
-
os/exec: External command execution -
path/filepath: File path manipulation -
syscall: Low-level system calls
-
encoding/json: JSON marshaling/unmarshaling -
encoding/xml: XML processing -
encoding/base64: Base64 encoding/decoding -
encoding/hex: Hexadecimal encoding -
encoding/csv: CSV file processing -
compress/gzip: GZIP compression/decompression
-
crypto: Cryptographic primitives -
crypto/rand: Cryptographically secure random numbers -
crypto/md5: MD5 hashing (deprecated but needed) -
crypto/sha1: SHA-1 hashing -
crypto/sha256: SHA-256 hashing -
crypto/aes: AES encryption/decryption -
crypto/rsa: RSA public key cryptography -
crypto/tls: TLS/SSL implementation
-
math: Mathematical functions (sin, cos, sqrt, etc.) -
math/big: Arbitrary precision arithmetic -
math/rand: Pseudo-random number generation
-
sync: Synchronization primitives- Mutex, RWMutex implementations
- WaitGroup for goroutine synchronization
- Once for one-time initialization
- Pool for object reuse
- Atomic operations
-
sync/atomic: Low-level atomic memory primitives
-
testing: Unit testing framework -
log: Logging utilities with different levels -
flag: Command-line flag parsing -
runtime: Runtime reflection and control- Garbage collector interface
- Memory statistics
- Goroutine inspection
- Garbage Collector: Enhance Boehm GC integration
- Memory Regions: Implement
#stack,#heap,#staticannotations - Smart Pointers: Complete implementation of
#shared<T>,#unique<T>,#weak<T> - Memory Safety: Bounds checking for arrays and slices
- Package System: Import/export mechanism with visibility rules
- Generic Programming: Type parameters and constraints
- Reflection: Runtime type information and method calling
- Build System: Package compilation and dependency management
- Cross-compilation: Multiple target architectures
- Post-IR Generation Optimizations: LLVM-based optimization pipeline
- Escape Analysis: Stack vs heap allocation decisions
- Inlining: Function call optimization
- Dead Code Elimination: Unused code removal
- Constant Folding: Compile-time constant evaluation
- Loop Optimizations: Loop unrolling and vectorization
- SIMD Optimizations: Vector operation enhancements
- Register Allocation: Optimal register usage
- Instruction Scheduling: CPU pipeline optimization
-
Phase 1: Core Go Semantics
- Built-in functions (
make,new,len,cap) - Slices and maps basic implementation
- Interfaces and method sets
- Built-in functions (
-
Phase 2: Concurrency Foundation
- Goroutines and channel basics
- Select statements
- Defer implementation
-
Phase 3: Essential Standard Library
fmtpackage for formatted I/Oospackage for file operationsnetpackage for basic networking
-
Phase 4: Advanced Features
- HTTP server/client
- JSON marshaling
- Testing framework
-
Phase 5: Performance & Polish
- IR code optimization passes (post-IR generation)
- Memory management refinements
- Documentation and examples
- LLVM Project - For the excellent compiler infrastructure
- Boehm GC - For garbage collection support
- TypeScript Team - For syntax inspiration
- Go Team - For semantic design inspiration
Made with β€οΈ by the tspp community
Website β’ Documentation β’ Discord
