Installation

Prerequisites

Simplex compiles to native code via LLVM. Install the required dependencies for your platform:

macOS

Install dependencies using Homebrew, then clone and build:

Terminal
# Install dependencies
brew install llvm openssl sqlite3

# Clone and build
git clone https://github.com/senuamedia/simplex-lang.git
cd simplex-lang
./build.sh

# Add to PATH
export PATH="$PWD/bin:$PATH"

Linux (Ubuntu/Debian)

Install dependencies, then clone and build:

Terminal
# Install dependencies
sudo apt-get install clang libssl-dev libsqlite3-dev

# Clone and build
git clone https://github.com/senuamedia/simplex-lang.git
cd simplex-lang
./build.sh

# Add to PATH
export PATH="$PWD/bin:$PATH"

Windows

Windows support is coming soon. For now, use WSL2 with Ubuntu and follow the Linux instructions.

Verify Installation

Terminal
sxc --version
# Simplex Compiler 0.5.1

Your First Program

Create a file called hello.sx:

hello.sx
fn main() {
    print("Hello, Simplex!")
}

Compile and run:

Terminal
# Compile and run in one step
sxc run hello.sx
# Hello, Simplex!

# Or compile to executable
sxc build hello.sx -o hello
./hello

Project Structure

Create a new project using the package manager:

Terminal
sxpm new my-project
cd my-project

This creates the following structure:

Directory Structure
my-project/
├── simplex.toml        # Project configuration
├── src/
│   ├── main.sx         # Entry point
│   ├── actors/         # Actor definitions
│   └── types/          # Custom types
└── tests/              # Test files

CLI Commands

Essential commands for working with Simplex:

Compiler (sxc)

Command Description
sxc build <file.sx> [-o output] Compile to executable
sxc compile <file.sx> Generate LLVM IR file
sxc run <file.sx> Compile and execute
sxc check <file.sx> Validate syntax only

Package Manager (sxpm)

Command Description
sxpm new <name> Initialize new package
sxpm build Compile current package
sxpm run Build and execute
sxpm test Run test suite
sxpm add <package> Add dependency

Your First Actor

Actors are the core building blocks in Simplex. Create a simple counter actor:

counter.sx
actor Counter {
    var count: i64 = 0

    receive Increment {
        count += 1
        print(f"Count: {count}")
    }

    receive GetCount -> i64 {
        count
    }
}

fn main() {
    let counter = spawn Counter

    send(counter, Increment)
    send(counter, Increment)
    send(counter, Increment)

    sleep(Duration::milliseconds(100))

    let final_count = ask(counter, GetCount)
    print(f"Final count: {final_count}")
}

Run it:

Terminal
sxc run counter.sx
# Count: 1
# Count: 2
# Count: 3
# Final count: 3

Your First AI Call

Simplex has first-class AI support. Here's a simple example:

ai_example.sx
use ai

fn main() {
    // Text completion
    let response = await ai::complete("What is the capital of France?")
    print(f"Answer: {response}")

    // Classification
    enum Sentiment { Positive, Negative, Neutral }

    let review = "This product is amazing, best purchase ever!"
    let sentiment = await ai::classify<Sentiment>(review)
    print(f"Sentiment: {sentiment}")

    // Structured extraction
    type Person {
        name: String,
        age: Option<i64>
    }

    let text = "John is 30 years old"
    let person = await ai::extract<Person>(text)
    print(f"Extracted: {person.name}, age {person.age}")
}

Run it:

Terminal
sxc run ai_example.sx
# Answer: The capital of France is Paris.
# Sentiment: Positive
# Extracted: John, age Some(30)

Build Your First Simplex Solution

Let's build a simple document processor that demonstrates actors, AI, and fault tolerance:

doc-processor.sx
// Define message types
struct Document {
    id: String,
    content: String
}

struct ProcessedDoc {
    id: String,
    summary: String,
    entities: List<String>,
    sentiment: String
}

// Document processor actor
actor DocProcessor {
    var processed: i64 = 0

    receive Process(doc: Document) -> ProcessedDoc {
        // Checkpoint before processing (for fault tolerance)
        checkpoint()

        // Parallel AI operations
        let (summary, entities, sentiment) = await parallel(
            ai::complete(f"Summarize: {doc.content}"),
            ai::extract<List<String>>(f"Extract entities: {doc.content}"),
            ai::classify<String>(f"Sentiment: {doc.content}")
        )

        processed += 1

        ProcessedDoc {
            id: doc.id,
            summary,
            entities,
            sentiment
        }
    }

    receive GetStats -> i64 {
        processed
    }
}

// Supervisor for fault tolerance
supervisor ProcessorSupervisor {
    strategy: OneForOne,
    max_restarts: 3,
    within: Duration::seconds(60),

    children: [
        child(DocProcessor, restart: Always)
    ]
}

fn main() {
    // Start supervised processor
    let supervisor = spawn ProcessorSupervisor
    let processor = supervisor.get_child(DocProcessor)

    // Process a document
    let doc = Document {
        id: "doc-001",
        content: "Simplex is a new programming language designed for AI..."
    }

    let result = ask(processor, Process(doc))

    print(f"Summary: {result.summary}")
    print(f"Entities: {result.entities}")
    print(f"Sentiment: {result.sentiment}")
}

Deploy to a Swarm

Local Development Swarm

Start a local swarm for development and testing:

Terminal
# Start a local 3-node swarm
sxpm swarm start --local --nodes 3

# Deploy your app
sxpm swarm deploy

# View status and logs
sxpm swarm status
sxpm swarm logs --follow

# Stop swarm
sxpm swarm stop

Cloud Deployment

Deploy to the cloud with cost-optimized spot instances:

Terminal
# Deploy to AWS
sxpm deploy --cloud aws \
    --region us-east-1 \
    --instance-type t4g.micro \
    --spot-enabled \
    --min-nodes 3 \
    --max-nodes 10

# Monitor
sxpm swarm status

Getting Help

Use the built-in CLI help for detailed command documentation:

Terminal
# Compiler help
sxc --help
sxc build --help

# Package manager help
sxpm --help
sxpm test --help

Next Steps

Need Help?

Check out the GitHub repository for source code, discussions, and issue tracking.