A high-performance AI/ML programming language built in Rust
Cortex is a compiled programming language designed for AI and machine learning.
Its goal is to make building, training, and experimenting with models simpler and faster by combining:
- Readable, bracket-based syntax β focused on clarity and flow
- Rust-powered performance β memory-safe and blazingly fast
- AI-first primitives β tensors, datasets, models, training utilities
- Professional tooling β CLI, VSCode extension, language server, debugger
Instead of writing AI in bloated frameworks, Cortex gives you a language designed from the ground up for machine intelligence.
- AI-first design β control flow, data structures, and math built with ML in mind
- Concise syntax β
if [x > 5] | print[x] ^ - Rust-powered β memory-safe, zero-cost abstractions, and blazingly fast
- Integrated ML stack β arrays β tensors, objects β models, dicts β datasets
- Professional tooling β Complete development environment with debugging, IntelliSense, and testing
- Extendable β pluggable backend (CPU now, GPU later)
- Rust 1.70+
- Node.js 16+ (for VSCode extension)
- Git
# Clone the repository
git clone https://github.com/muhyadinmohamed/cortex
cd cortex
# Build the compiler (Rust)
cd packages/compiler
cargo build --release
# The compiler binary will be at: target/release/cortexc# Create a new project
cortex new hello-world
cd hello-world
# Run the program
cortex run src/main.ctx
# Or run directly
cortex run examples/hello_world.ctxCortex now has a fully functional Rust interpreter with syntax highlighting and formatting support!
- π₯ High-Performance Interpreter: Rust-powered execution with memory safety
- π₯ Syntax Highlighting: Beautiful VS Code extension with custom color palette
- π₯ Code Formatting: Automatic formatting with configurable indentation
- π₯ Arithmetic Operations: All math operations (+, -, *, /, %, **) with correct type handling
- π₯ String & Number Printing: Proper output formatting for both strings and numbers
- π₯ While Loops: Complete loop implementation with condition evaluation
- π₯ Functions: Function definitions, calls, and parameter handling
- π₯ Variables: Variable assignment, scoping, and expression evaluation
- π₯ Cross-Platform: Works on macOS, Linux, and Windows
# Run arithmetic operations
cd rust
cargo run -- run ../examples/arithmetic.ctx
# Output: Arithmetic Operations with all calculations
# Run loops with factorial
cargo run -- run ../examples/simple_loops.ctx
# Output: Loop iterations and factorial calculation
# Run hello world
cargo run -- run ../examples/hello_world.ctx
# Output: Hello, World!
# Welcome to Cortex - the AI/ML programming language!let greeting := "Hello"
func add[a, b] |
return[a + b]
^
func main[] |
print[greeting + " from Cortex!"]
let sum := add[10, 20]
print["Result: " + str[sum]]
^
main[]
func main[] |
let a := 10
let b := 3
let sum := a + b
let diff := a - b
let product := a * b
let quotient := a / b
print[sum]
print[diff]
print[product]
print[quotient]
^
main[]
func main[] |
let counter := 1
while [counter <= 5] |
print[counter]
let counter := counter + 1
^
// Factorial calculation
let n := 5
let factorial := 1
let temp := 1
while [temp <= n] |
let factorial := factorial * temp
let temp := temp + 1
^
print[factorial]
^
main[]
- Variables:
let x := 42with type inference - Functions:
func name[params] | body ^with parameter handling - Arithmetic: All basic operations (+, -, *, /, %, **)
- Printing:
print[value]for strings and numbers - Loops:
while [condition] | body ^with proper condition evaluation - Control Flow:
if [condition] | body ^with else support - Comments:
//single-line and/* */multi-line
- Arrays: Basic array data structures
- String Concatenation:
"hello" + "world" - For Loops:
for [i in range[10]] | body ^ - Advanced Types: Enhanced type system
- Multi-dimensional tensors:
tensor[[1,2],[3,4]]with shape inference - Tensor operations:
A @ B(matrix multiplication),β[loss](gradients) - Memory optimization: Contiguous storage, lazy evaluation, sparse tensors
- Device support: CPU/GPU/TPU tensor operations
- Modular neurons:
Neuron { weights, bias, activation, domain } - Composable layers:
Layer { neurons, learning_curve, capabilities } - Network assembly:
compose_network[medical_layer, educational_layer] - Layer registry: Import/export specialized domain layers
- Computational graphs: Forward/backward pass infrastructure
- Gradient operators:
β[loss, params],β[f, x](partial derivatives) - Chain rule: Automatic gradient computation for all operations
- Optimization: SGD, Adam, RMSprop with learning rate scheduling
- GPU acceleration: CUDA/OpenCL backends for tensor operations
- Distributed training: Multi-GPU/multi-node support
- Model serving: High-performance inference with sub-millisecond latency
- Package system: Community-driven layer and model sharing
cortex/
ββ packages/ # Core packages
β ββ compiler/ # Rust compiler/interpreter β
β β ββ src/ # Source code
β β β ββ main.rs # CLI interface
β β β ββ lib.rs # Library interface
β β β ββ lexer.rs # Tokenizer (with tests)
β β β ββ parser.rs # Parser (with tests)
β β β ββ ast.rs # AST definitions (with tests)
β β β ββ codegen.rs # Interpreter (with tests)
β β β ββ error.rs # Error handling
β β β ββ debugger.rs # Debugger
β β ββ tests/ # Integration tests
β β β ββ integration_tests.rs # 28 end-to-end tests
β β ββ Cargo.toml # Rust dependencies
β ββ vscode-extension/ # VSCode extension
β ββ extension.js # Extension implementation
β ββ package.json # Extension manifest
β ββ syntaxes/ # Syntax highlighting
β ββ icons/ # Extension icons
ββ docs/ # Comprehensive documentation
β ββ api/ # API reference
β ββ examples/ # Example .ctx programs
β ββ ADVANCED_FEATURES.md
β ββ AI_ML_IMPLEMENTATION_GUIDE.md
β ββ SYNTAX_REFERENCE.md
β ββ ... (20+ documentation files)
ββ assets/ # Logos and branding
β ββ cortex-with-text.svg
β ββ cortex.svg
ββ cortex.toml # Project configuration
ββ README.MD # Main documentation
ββ TEST_SUMMARY.md # Test suite report
ββ run_cortex.sh # Convenience scriptNote: The project has been cleaned to include only functional, tested components. CLI and language-server packages can be added in the future when fully implemented.
# Navigate to the rust directory
cd rust
# Run a program (interpreter mode)
cargo run -- run program.ctx
# Check syntax
cargo run -- check program.ctx
# Build executable
cargo run -- build program.ctx -o program# From the project root directory
cd /path/to/cortex
# Run any example
cd rust && cargo run -- run ../examples/hello_world.ctx
# Or use the provided shell script
./run_cortex.sh examples/hello_world.ctxIf you have the Cortex VS Code extension installed:
- Open any
.ctxfile in VS Code - Press F5 or use "Run and Debug" to execute the file
- Use Ctrl+Shift+P and search for "Cortex" commands
- Format on save is automatically enabled for
.ctxfiles
Shorthand Commands (Recommended):
# From project root - use the shorthand scripts
./ctx hello_world
./ctx function_demo
./ctx arithmetic
./ctx simple_algorithms
./ctx fibonacci
./ctx factorial
./ctx prime_numbers
./ctx bubble_sort
./ctx comprehensive_features
./ctx ai_ml_comprehensive
./ctx simple_loops
./ctx loops
./ctx printing
./ctx simple_arithmetic
# Check syntax
./ctxc hello_world
# Run any .ctx file
./ctx run examples/hello_world.ctx
./ctxc check examples/hello_world.ctxFull Commands:
# Navigate to the rust directory
cd rust
# Basic hello world
cargo run -- run ../examples/hello_world.ctx
# Functions and variables
cargo run -- run ../examples/function_demo.ctx
# Arithmetic operations
cargo run -- run ../examples/arithmetic.ctx
# Simple algorithms (prime, factorial, fibonacci, GCD)
cargo run -- run ../examples/simple_algorithms.ctx
# Fibonacci sequence
cargo run -- run ../examples/fibonacci.ctx
# Factorial calculation
cargo run -- run ../examples/factorial.ctx
# Prime number checking
cargo run -- run ../examples/prime_numbers.ctx
# Bubble sort demo
cargo run -- run ../examples/bubble_sort.ctx
# Comprehensive features showcase
cargo run -- run ../examples/comprehensive_features.ctx
# AI/ML algorithms demo
cargo run -- run ../examples/ai_ml_comprehensive.ctx
# Loop examples
cargo run -- run ../examples/simple_loops.ctx
cargo run -- run ../examples/loops.ctx
# Printing examples
cargo run -- run ../examples/printing.ctx
# Simple arithmetic
cargo run -- run ../examples/simple_arithmetic.ctx
# Check syntax of any example
cargo run -- check ../examples/hello_world.ctx- Core Language: Variables, functions, control flow
- Rust Interpreter: High-performance execution with memory safety
- VS Code Extension: Syntax highlighting and code formatting
- Standard Library: Math, string operations
- Tensor Primitives: Multi-dimensional arrays with shape inference
- Neural Network Primitives: Modular neurons, layers, and networks
- Automatic Differentiation: Computational graphs and gradient operators
- GPU Support: CUDA/OpenCL backends for tensor operations
- Layer Registry: Community-driven specialized layer sharing
- Lexer and parser
- AST and interpreter
- Basic syntax and operations
- Function calls and control flow
- Rust interpreter β COMPLETED!
- VS Code extension β COMPLETED!
- Tensor Primitives: Multi-dimensional arrays with shape inference
- Neural Network Primitives: Modular neurons, layers, and networks
- Automatic Differentiation: Computational graphs and gradient operators
- Optimization Framework: SGD, Adam, RMSprop with scheduling
- Layer Registry: Community-driven specialized layer sharing
- Rust interpreter β COMPLETED!
- Memory safety β COMPLETED!
- Advanced memory optimization
- Parallel execution
- GPU acceleration
- Package manager
- Standard ML library
- Enhanced IDE support and debugging
- Community and documentation
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make your changes and add tests
- Run the test suite:
python3 -m pytest tests/ - Submit a pull request
Rust Implementation:
git clone https://github.com/yourname/cortex
cd cortex/packages/compiler
cargo build
# Run examples
cargo run -- run ../../docs/examples/hello_world.ctx
# Check syntax
cargo run -- check ../../docs/examples/hello_world.ctxThe Cortex compiler has comprehensive test coverage including unit tests, integration tests, and doc tests.
# Run all tests
cd packages/compiler
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_simple_variable_assignment
# Run tests and show ignored tests
cargo test -- --include-ignored
# Generate and open documentation (includes doc tests)
cargo doc --no-deps --openTest Organization:
- Unit tests: Located in each source file within
#[cfg(test)]modules - Integration tests: Located in
packages/compiler/tests/directory - Doc tests: Embedded in documentation comments throughout the codebase
MIT License - see LICENSE for details.
- Documentation: docs/shared/
- Examples: docs/shared/examples/
- Function Status: docs/shared/FUNCTION_STATUS.md
- Python Implementation: python/
- Rust Implementation: rust/
- VS Code Marketplace: Cortex Language Extension
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Ready to try Cortex? Start with our Getting Started Guide and explore the examples!
Rust implementation is ready! High-performance interpreter with VS Code support! π