Menu
Learn
Overview 50 Dimensions Tutorial Snippets vs Other Languages
Build
Editor Playground Compiler API
Docs
Language Spec Formats u keyword Dataframe AI Library Feature Status Packages What's Implemented
Platform
Server About Transpilation Web & Templates
Safebox
Why U Analysis Engine Comparison Possibilities

Compiler API

One endpoint, six output formats. Send U source, get back C code, WebAssembly, AST, tokens, or just lint results.

Base URL: https://compiler.ulanguage.org

Machine-readable specs: OpenAPI 3.1 · MCP tools

POST /compile

POST/compile

Compile U source code. The format query parameter controls what comes back.

Query parameters

ParamValuesDefaultDescription
formatc wasm wat ast lint tokenscOutput format
source_typeu pythonuInput language (Python transpiles to U server-side)
optimize0 1 2 32Optimization level (WASM only)

Request body

Send raw source as text/plain, or wrap in JSON: {"source": "..."}.

Examples

Compile to C

# Returns JSON with generated C code curl -X POST https://compiler.ulanguage.org/compile \ -H "Content-Type: text/plain" \ -d 'f main() -> I r => 42'
{"ok": true, "errors": [], "warnings": [], "c": "/* Generated by u2c ... */\n#include \"u_runtime.h\"..."}

Compile to WebAssembly

# Returns raw .wasm binary (application/wasm) curl -X POST https://compiler.ulanguage.org/compile?format=wasm \ -H "Content-Type: text/plain" \ -d 'f main() -> I r => 42' -o output.wasm

Lint only

# Check for errors without generating code curl -X POST https://compiler.ulanguage.org/compile?format=lint \ -H "Content-Type: text/plain" \ -d 'f main() -> I r => 42'
{"ok": true, "errors": [], "warnings": []}

Get AST

# Returns the parsed abstract syntax tree curl -X POST https://compiler.ulanguage.org/compile?format=ast \ -H "Content-Type: text/plain" \ -d 'f main() -> I r => 42'

Get token stream

# Returns tokenized source curl -X POST https://compiler.ulanguage.org/compile?format=tokens \ -H "Content-Type: text/plain" \ -d 'f main() -> I r => 42'

Transpile Python to U, then compile

# Server-side Python → U transpilation + compile curl -X POST 'https://compiler.ulanguage.org/compile?source_type=python' \ -H "Content-Type: text/plain" \ -d 'def fib(n): if n <= 1: return n return fib(n-1) + fib(n-2)'

JSON body

curl -X POST https://compiler.ulanguage.org/compile \ -H "Content-Type: application/json" \ -d '{"source": "f main() -> I\n\tr => 42"}'

GET /health

GET/health

Returns service status and available capabilities.

curl https://compiler.ulanguage.org/health
{"status": "ok", "compiler": "python-u2c", "capabilities": {"formats": ["c","wasm","wat","ast","lint","tokens"], "gcc": true, "wasi_sdk": true}}

MCP Integration

The compiler exposes MCP tool definitions at /mcp.json. AI assistants can compile, lint, and transpile U code by calling these tools.

curl https://compiler.ulanguage.org/mcp.json

Available tools: compile, compile_wasm, lint, transpile_python, ast, tokens.

Error format

Errors include source context with line numbers and column markers:

{"ok": false, "errors": ["input.u:2: error: 'xx' is not defined\n r => xx\n ^~~~"], "warnings": []}