A lightweight programming language with Python-like syntax that compiles to native machine code
β‘ No GCC/LLVM required! β‘
Quick Start β’ Features β’ Documentation β’ Comparison β’ Contributing
| Feature | LP | Python | C | Go | Rust |
|---|---|---|---|---|---|
| Compilation | Native ASM | Interpreted | Native | Native | Native |
| Dependencies | ~5MB (binutils) | ~100MB+ | ~500MB (GCC) | ~200MB | ~1GB+ |
| Startup Time | β‘ Instant | π’ Slow | β‘ Instant | β‘ Instant | β‘ Instant |
| Performance | π Native | π Slow | π Native | π Native | π Native |
| Syntax | π Python-like | π Python | π° Verbose | π― Clean | π° Complex |
| Learning Curve | β Easy | β Easy | β Hard | β Hard |
- π₯ Native Compilation - Direct LP β Assembly β Machine Code (no GCC/LLVM needed!)
- πͺΆ Ultra-lightweight - Only requires binutils (
as+ld, ~5MB) - π Python-like Syntax - Familiar
def,class,if,for,while,import - β‘ Modern Features - F-Strings, Pattern Matching, Decorators, Async/Await, Generics, Type Unions
- π§΅ Built-in Modules -
math,random,time,os,sys,http,json,sqlite,thread,memory,dsa - π DSA Module - Data Structures & Algorithms for competitive programming (Stack, Queue, DSU, Heap, Segment Tree, Graph algorithms, Geometry)
- π Native OpenMP - Automatic parallel execution with
parallel for - βοΈ @settings Decorator - Fine-grained control over parallel threads, GPU, scheduling
- π @security Decorator - Built-in rate limiting, authentication, input validation
- π― Optimizations - Constant folding, dead code elimination, loop unrolling
- Linux x86-64: binutils (
as,ld) - usually pre-installed - Windows: MSYS2 UCRT64 or MinGW
- macOS: Xcode Command Line Tools
# POSIX shell
./compile.sh
# Or using make
makeCreate hello.lp:
def main():
print("Hello from LP!")
main()Run it with native compilation:
# Native compilation (default - no GCC needed!)
./build/lp hello.lp
# Or with GCC backend (optional)
./build/lp hello.lp --gcc# Variables with type inference
name = "LP"
version = "0.1.0"
active = True
# Explicit types
count: int = 100
ratio: float = 0.5
label: str = "text"
# F-Strings
greeting = f"Hello from {name} v{version}!"
print(greeting) # Output: Hello from LP v0.1.0!match value:
case 1:
print("one")
case 2:
print("two")
case n if n > 10:
print("big")
case _:
print("other")# @settings - Configure parallel/GPU execution
@settings(threads=8, schedule="dynamic", chunk=100)
def parallel_task(data: list) -> list:
results = []
parallel for item in data:
results.append(process(item))
return results
# @settings with GPU acceleration
@settings(device="gpu", gpu_id=0)
def gpu_compute(n: int) -> int:
result = 0
parallel for i in range(n):
result += i * i
return result
# @security - Built-in security features
@security(level=3, auth=True, rate_limit=100)
def secure_api_endpoint(data: dict) -> dict:
return {"status": "ok"}async def fetch_data(url: str) -> str:
return "data from " + url
async def main():
data = await fetch_data("https://example.com")
print(data)class Box[T]:
value: T
def get(self) -> T:
return self.value
# Usage
int_box: Box[int] = Box()
int_box.set(42)# OpenMP-style parallel for (auto-enabled!)
parallel for i in range(1000000):
process_item(i)
# With @settings decorator for fine-grained control
@settings(threads=4, schedule="dynamic", chunk=1000)
def process_large_dataset(data: list) -> int:
total = 0
parallel for item in data:
total += item
return total
# GPU acceleration
@settings(device="gpu", unified=True)
def gpu_matrix_multiply(a: list, b: list) -> list:
# Automatically runs on GPU if available
parallel for i in range(len(a)):
compute(a[i], b[i])import math
import time
import http
import json
import sqlite
import thread
import memory
# Math
pi: float = math.pi
result = math.sqrt(16) # 4.0
# HTTP
response: str = http.get("https://api.example.com")
# JSON
data = json.loads('{"name": "LP"}')
text = json.dumps(data)
# SQLite
db = sqlite.connect("mydb.db")
results = sqlite.query(db, "SELECT * FROM users")
# Threading
# Worker must be a named function with 0 args, returning int or void
def worker_function() -> int:
return 42
t = thread.spawn(worker_function)
result = thread.join(t)
# Memory Management
arena = memory.arena_new(1024)
ptr = memory.arena_alloc(arena, 64)LP provides a comprehensive DSA module optimized for competitive programming:
import dsa
# Fast I/O (critical for competitive programming)
n = dsa.read_int()
dsa.write_int_ln(n)
# Number Theory
primes = dsa.sieve(1000000)
is_prime = dsa.is_prime(17)
result = dsa.mod_pow(2, 100, 1000000007)
# Data Structures
stack = dsa.stack_new(100)
dsa.stack_push(stack, 10)
dsa.stack_pop(stack)
queue = dsa.queue_new(100)
dsa.queue_push(queue, 1)
dsa.queue_pop(queue)
# DSU (Union-Find)
dsu = dsa.dsu_new(n)
dsa.dsu_union(dsu, 0, 1)
same = dsa.dsu_same(dsu, 0, 1)
# Heap / Priority Queue
heap = dsa.heap_new(100)
dsa.heap_push(heap, value, priority)
# Graph Algorithms
g = dsa.graph_new(n, True)
dsa.graph_add_edge(g, 0, 1, 10)
dist = dsa.graph_dijkstra(g, 0)
# Segment Tree with Lazy Propagation
seg = dsa.segtree_new(arr, n, "sum")
dsa.segtree_build(seg)
dsa.segtree_update(seg, 1, 4, 10)
result = dsa.segtree_query(seg, 0, 5)
# Geometry
hull = dsa.convex_hull(points, n)
area = dsa.polygon_area(hull.points, hull.count)lp file.lp # Run with native backend (default)
lp file.lp --gcc # Run with GCC backend (optional)
lp file.lp -o out.c # Generate C code
lp file.lp -c out.exe # Compile to executable
lp file.lp -asm out.s # Generate assembly
lp test examples # Run tests
lp profile file.lp # Profile execution
lp watch file.lp # Hot reload mode
lp build file.lp --release # Build optimized executable
lp package file.lp # Package for distributionLP/
βββ compiler/ # Compiler source code (C)
βββ runtime/ # Runtime library
βββ examples/ # Example programs
βββ docs/ # Documentation
βββ vscode-lp/ # VSCode extension
βββ skills/ # AI assistant skills
βββ Makefile # Build configuration
βββ compile.sh # Build script (POSIX)
βββ build.bat # Build script (Windows)
See the LP Language Wiki for comprehensive documentation:
| Document | Description |
|---|---|
| Feature Status | Comprehensive feature status |
| Language Reference | Complete language reference |
| Runtime Modules | Built-in modules (math, http, json, dsa, etc.) |
| Parallel Computing | OpenMP integration |
| Vietnamese Guide | HΖ°α»ng dαΊ«n tiαΊΏng Viα»t |
| Feature | LP | Python | C | Go |
|---|---|---|---|---|
| Compilation | Native ASM | Interpreted | Native | Native |
| Dependencies | ~5MB (binutils) | ~100MB+ | ~500MB (GCC) | ~200MB |
| Startup Time | Instant | Slow | Instant | Instant |
| Performance | Native | Slow | Native | Native |
| Memory Safe | Partial | Yes | No | Yes |
We welcome contributions! See CONTRIBUTING.md for guidelines.
- π Report bugs
- π‘ Suggest features
- π Improve documentation
- π§ Submit pull requests
- β Star the repository!
MIT License - See LICENSE
Made with β€οΈ by Ho Quang Huy
