Skip to content

MayaFlux/lilacode

Repository files navigation

LilaCode

Also available for Neovim: lila.nvim - Live C++ coding with the same capabilities in Neovim.

Live C++ Coding in VS Code

LilaCode is a VS Code extension that enables real-time, interactive live coding of any C++ code directly within your editor. It connects to the Lila REPL server—a high-performance incremental Clang/LLVM JIT compiler—allowing you to evaluate code with near-zero latency (~1ms, designed for 1 buffer/frame cycle) and see results instantly.

Overview

Lila is MayaFlux's embedded live coding engine: an LLVM 21+ backed C++ JIT interpreter that compiles and executes arbitrary C++ code at runtime with sub-buffer latency. LilaCode brings this power into VS Code, eliminating the gap between code authorship and execution.

Why Live Coding in C++?

  • Instant Feedback: Execute code in milliseconds without recompilation
  • Exploratory Development: Iterate on algorithms interactively—algorithms, DSP, graphics pipelines, you name it
  • Deterministic Latency: 1 buffer/frame cycle designed for real-time systems
  • Full C++ Capability: Execute any valid C++20 code, access all linked libraries
  • Persistent State: Modifications layer onto previous evaluations; your session accumulates

Live coding isn't just faster iteration. It's a fundamentally different way to work—closer to interactive development in Lisp/Scheme, but with C++'s power and MayaFlux's real-time guarantees.

Features

  • Evaluate Line: Execute a single line of code (Ctrl+Alt+E)
  • Evaluate Selection: Run highlighted code blocks (Ctrl+Alt+S)
  • Evaluate Buffer: Execute your entire file (Ctrl+Alt+B)
  • Evaluate Node: Run semantic code blocks intelligently (experimental, Ctrl+Alt+N)
  • Auto-Connect: Automatically start and connect to the Lila server on extension load
  • Live Output: See compilation results, errors, and output in the integrated console
  • Real-Time Status: Monitor connection state at a glance
  • Session Persistence: State accumulates across evaluations

Installation

From VS Code Marketplace

Search for "LilaCode" in the VS Code Extensions marketplace and install.

From VSIX File

  1. Download the .vsix file from Releases
  2. Open VS Code
  3. Ctrl+Shift+P → "Extensions: Install from VSIX..."
  4. Select the downloaded file

Build from Source

npm install
npm run compile
npm run package  # Generates lilacode-*.vsix

Lila Server Setup

The Lila JIT compiler must be available on your system. Use Weave for easiest setup:

Option 1: Use Weave (Recommended)

Download and run Weave for your platform:

  • macOS: Weave-X.X.X.pkg
  • Windows: Weave-X.X.X.exe
  • Linux: Weave-X.X.X (GUI) or use CLI tools

Weave handles:

  • Downloading MayaFlux and Lila
  • Installing all dependencies
  • Configuring environment variables
  • Creating new projects

Option 2: Manual Installation from Release Artifacts

  1. Download the latest MayaFlux release from GitHub Releases
  2. Extract the tarball:
    tar -xzf mayaflux-X.X.X-linux-x86_64.tar.gz
  3. Organize files into installation directory:
    mkdir -p ~/.local/mayaflux
    mv extracted/bin ~/.local/mayaflux/
    mv extracted/lib ~/.local/mayaflux/
    mv extracted/share ~/.local/mayaflux/
  4. Add to PATH:
    export PATH="$HOME/.local/mayaflux/bin:$PATH"

Option 3: Build from Source

For development or if you need to customize the build:

git clone https://github.com/MayaFlux/MayaFlux.git
cd MayaFlux
./scripts/setup_*.sh  # Platform-specific setup
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel
sudo cmake --install build

Quick Start

Prerequisites

  1. Install Lila Server using Weave or from release artifacts (see setup above)

  2. Verify Installation

    lila_server --help

Basic Workflow

1. Open a C++ file

// example.cpp
int main() {
    int x = 10;
    int y = 20;
    return 0;
}

2. Send code to Lila

Evaluate line by line:

int x = 10;  // Ctrl+Alt+E
int y = 20;  // Ctrl+Alt+E
int sum = x + y;  // Ctrl+Alt+E

Or select multiple lines:

int x = 10;
int y = 20;
int sum = x + y;

Press Ctrl+Alt+S to evaluate the selection.

3. See results in the output console

The "Lila" output panel shows:

  • ✓ Successful evaluations
  • ✗ Compilation errors with diagnostics
  • Printed output (via std::cout, etc.)

State Persistence

State persists across evaluations within a session:

int counter = 0;  // Evaluate this

Later, in a separate evaluation:

counter++;  // counter still exists, now equals 1
std::cout << counter << std::endl;  // Prints: 1

This allows you to build up complex systems incrementally.

Commands

Command Shortcut Description
lila.startServer Start the Lila REPL server
lila.stopServer Stop the server and disconnect
lila.restartServer Restart the server
lila.connect Manually connect to a running server
lila.disconnect Disconnect from the server
lila.evalLine Ctrl+Alt+E Evaluate the current line
lila.evalSelection Ctrl+Alt+S Evaluate selected code
lila.evalBuffer Ctrl+Alt+B Evaluate the entire file
lila.evalNode Ctrl+Alt+N Evaluate a semantic code block (experimental)
lila.showOutput Show the Lila output panel
lila.clearOutput Clear the output console
lila.showStatus Display connection and server status

Access commands via Ctrl+Shift+P and type "Lila".

Configuration

Add these settings to your VS Code settings.json (or configure via the Settings GUI):

{
  "lila.host": "127.0.0.1",
  "lila.port": 9090,
  "lila.serverPath": "lila_server",
  "lila.autoStartServer": true,
  "lila.autoConnect": true
}

Custom Server Path

If lila_server is not in PATH, specify the full path:

{
  "lila.serverPath": "/usr/local/bin/lila_server"
}

On Windows:

{
  "lila.serverPath": "C:\\Program Files\\MayaFlux\\bin\\lila_server.exe"
}

Server Configuration

The Lila server supports additional options via command-line flags:

lila_server -p 9090 -v -l DEBUG

Options:

  • -p, --port <port>: Server port (default: 9090)
  • -v, --verbose: Enable verbose logging
  • -l, --level <level>: Log level (TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
  • -h, --help: Show help message

Architecture

How It Works

  1. Extension Activation: Loads on command execution or when opening .cpp files
  2. Server Launch: Spawns lila_server process (if not already running)
  3. Client Connection: Establishes TCP connection to server (default: 127.0.0.1:9090)
  4. Code Submission: Sends C++ code to server over TCP
  5. JIT Compilation: Server uses Clang's incremental compiler to compile code
  6. Execution: Compiled code executes in-process with access to all linked libraries
  7. Result Return: Output, errors, and results stream back to VS Code

Connection States

  • Disconnected (○): Not connected to server
  • Connecting (○): Attempting to establish connection
  • Connected (✓): Ready to send code
  • Error (✗): Connection failed

Session Model

Each Lila session maintains:

  • Symbol table: All defined variables, functions, types persist
  • Compiled code: Previous evaluations remain accessible
  • Execution context: State from one eval available to the next

This enables incremental development: build algorithms step-by-step, modifying and extending as you go.

Use Cases

Audio DSP Development

// Define a simple filter
struct SimpleFilter {
    float state = 0.0f;
    float process(float x) {
        state = state * 0.9f + x * 0.1f;
        return state;
    }
};

SimpleFilter filter;  // Evaluate this

Then test and refine iteratively:

float output = filter.process(0.5f);  // Evaluate and see result
// Modify the filter coefficients inline
state = state * 0.95f + x * 0.05f;    // Adjust decay behavior

Algorithm Exploration

#include <cmath>
#include <iostream>

// Evaluate DSP algorithms in real-time
auto polynomial = [](double x) { return x * x * x - 2 * x + 1; };
std::cout << polynomial(0.5) << std::endl;  // Immediate feedback

MayaFlux Development

If you have MayaFlux linked to the Lila server, you can live-code multimedia systems:

#include "MayaFlux/MayaFlux.hpp"

// Create nodes
auto sine = vega.Sine(200)[{0, 1}] | Audio;

// Modify while running
sine->set_frequency(300);  // Evaluate to change pitch live

For MayaFlux-specific examples, see Getting Started.

Troubleshooting

Server fails to start

  1. Check that lila_server is installed:

    which lila_server
  2. If not found, ensure it's in PATH or update lila.serverPath in settings

  3. Run the server manually to check for errors:

    lila_server --help
    lila_server -v -l DEBUG  # Verbose + DEBUG logging

Connection times out

  1. Check server status: Lila: Show Status command
  2. Verify local network: lila.host should be 127.0.0.1
  3. Try a different port in settings if 9090 is in use
  4. Restart server: Lila: Restart Server command
  5. Check VS Code output channel: View → Output → Lila

Code doesn't evaluate

  1. Check the "Lila" output console for error messages
  2. Verify C++ syntax is correct (Clang will report syntax errors)
  3. Ensure required headers are available (check PCH configuration in Lila server logs)
  4. Try a simpler test (e.g., int x = 42;)
  5. Restart the server and reconnect

Compilation errors

Clang reports diagnostics in the output console. Common issues:

  • Missing includes: Add #include statements or check PCH setup
  • Undefined symbols: Symbols from previous evals should persist; restart server if needed
  • Type errors: Verify C++20 syntax and template instantiations
  • Linker errors: Ensure libraries are linked to the Lila server binary

Performance

  • Compilation latency: ~1ms per evaluation (LLVM JIT cached code)
  • Execution latency: Depends on code complexity (typically <1ms for simple operations)
  • Buffer cycle: Designed for 1 buffer/frame timing (~21-42ms at typical buffer sizes)
  • Memory: Incremental compilation minimizes allocations; restart server to reset state

Philosophy

LilaCode embodies MayaFlux's core principle: embrace purely digital computation.

Instead of asking "how do we simulate analog hardware?", we ask "what becomes possible when code itself becomes creative material?"

Live coding removes the friction between thought and execution. You don't write C++ into a text editor, then recompile, then test. Instead, you think in code, executing and refining in real-time.

This is fundamentally different from traditional development—closer to the exploratory, feedback-driven workflows of Lisp, SuperCollider, and Pure Data, but with C++'s performance and flexibility.

Roadmap

Planned features:

  • Breakpoint Debugging: Step through evaluated code
  • Symbol Introspection: Hover for type info and values
  • REPL History: Browse and re-execute previous evaluations
  • Multi-File Sessions: Include other .cpp/.h files seamlessly
  • Performance Profiling: Built-in timing and profiling output
  • Remote Sessions: Connect to Lila servers over the network
  • Collaborative Sessions: Multiple users live-coding simultaneously

Limitations

  • Currently supports local connections only (127.0.0.1)
  • No persistent sessions between editor restarts (state resets when server stops)
  • No debugger integration yet (planned)
  • No symbol introspection UI (planned)
  • Large evaluations may have noticeable compile time (optimization in progress)

Contributing

Issues, feature requests, and contributions welcome on GitHub.

License

GNU General Public License v3.0 (GPLv3)

See LICENSE for full terms.


LilaCode: Live C++ coding without barriers. Execute, iterate, explore. Code as a creative medium.

For more on the MayaFlux philosophy and vision, see the main project README.

About

VSCode client plugin for Lila Live Coding JIT Server (MayaFlux)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors