Skip to content

tspp-io/tspp-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

67 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

tspp Programming Language

tspp Logo

A modern systems programming language combining TypeScript-like syntax with Go-style semantics

License Build Status Language LLVM

Overview

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.

Key Features

πŸš€ 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

Project Structure

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.

Quick Start

Prerequisites

  • C++ Compiler: GCC 9+ or Clang 10+
  • CMake: Version 3.14 or higher
  • LLVM: Version 17 or higher
  • Boehm GC: For garbage collection support

Ubuntu/Debian

sudo apt-get update
sudo apt-get install build-essential cmake llvm-17 llvm-17-dev libgc-dev

macOS

brew install cmake llvm bdw-gc

Building from Source

# 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/tspp

Your First tspp Program

Create 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!

Language Features

Memory Management

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 allocation

Smart Pointers

Built-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();

SIMD and Performance

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 addition

Zero-Cost Abstractions

Compile-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 time

Architecture

tspp 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]
Loading

Components

  • 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

Documentation

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Links

License

This project is licensed under the MIT License - see the LICENSE file for details.

TODO - Roadmap to Full Implementation

πŸ”„ Go Semantics Implementation

Concurrency Primitives

  • Goroutines: Implement go keyword 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

Built-in Functions

  • 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

Type System Extensions

  • 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

Control Flow

  • Defer Statements: Deferred execution with LIFO ordering
  • Range Iteration: For-range over slices, maps, channels, strings
  • Labeled Breaks/Continues: Multi-level loop control

πŸ“š Standard Library Implementation

Core Packages

  • 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

Network Programming

  • 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

Operating System Interface

  • 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

Data Encoding/Decoding

  • 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

Cryptography & Security

  • 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

Mathematics

  • math: Mathematical functions (sin, cos, sqrt, etc.)
  • math/big: Arbitrary precision arithmetic
  • math/rand: Pseudo-random number generation

Concurrency Support

  • 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

Development & Testing

  • 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

πŸ—οΈ Language Infrastructure

Memory Management

  • Garbage Collector: Enhance Boehm GC integration
  • Memory Regions: Implement #stack, #heap, #static annotations
  • Smart Pointers: Complete implementation of #shared<T>, #unique<T>, #weak<T>
  • Memory Safety: Bounds checking for arrays and slices

Compiler Features

  • 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

IR Code Optimization Passes

  • 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

🎯 Priority Implementation Order

  1. Phase 1: Core Go Semantics

    • Built-in functions (make, new, len, cap)
    • Slices and maps basic implementation
    • Interfaces and method sets
  2. Phase 2: Concurrency Foundation

    • Goroutines and channel basics
    • Select statements
    • Defer implementation
  3. Phase 3: Essential Standard Library

    • fmt package for formatted I/O
    • os package for file operations
    • net package for basic networking
  4. Phase 4: Advanced Features

    • HTTP server/client
    • JSON marshaling
    • Testing framework
  5. Phase 5: Performance & Polish

    • IR code optimization passes (post-IR generation)
    • Memory management refinements
    • Documentation and examples

Acknowledgments

  • 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

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages