Skip to content

Latest commit

 

History

History
242 lines (185 loc) · 5.58 KB

File metadata and controls

242 lines (185 loc) · 5.58 KB

ProXPL v1.7.0: The "Wasm World" Release

Target Release Date: Q2 2027
Status: Planned
Codename: Wasm World


🌟 Overview

ProXPL v1.7.0 introduces the WebAssembly compilation target, enabling ProXPL programs to run in browsers and edge runtimes. This release also brings Closures v2 with proper escape analysis, String Templates, Operator Overloading, and the ProXPL Formatter (prox fmt).


✨ New Features

1. WebAssembly (Wasm) Target

Compile ProXPL to WebAssembly for browser and edge deployment.

# Compile to Wasm
proxpl build --target wasm app.prox
# Output: app.wasm + app.js (glue code)

# Serve locally
prm serve --wasm
# Opens browser at localhost:3000

Architecture:

Source (.prox) → AST → IR → LLVM IR → Wasm Backend → .wasm + .js glue

Features:

  • Full language support in Wasm (except FFI and filesystem)
  • JavaScript interop bridge (call JS from ProXPL and vice-versa)
  • DOM manipulation API (std.web.dom)
  • Event handling (std.web.event)
  • Fetch API integration (std.web.http)
  • Canvas 2D drawing support (std.web.canvas)
  • WASI (WebAssembly System Interface) support for server-side Wasm

Browser API Example:

use std.web.dom;
use std.web.event;

func main() {
    let btn = dom.create("button");
    btn.text = "Click me!";
    btn.style.backgroundColor = "#4CAF50";

    event.on(btn, "click", func() {
        dom.alert("Hello from ProXPL!");
    });

    dom.body.append(btn);
}

2. String Templates (Template Literals)

Embedded expressions in strings.

let name = "World";
let age = 25;

// Template literal syntax
let greeting = `Hello, ${name}! You are ${age} years old.`;

// Multi-line strings
let html = `
    <div class="card">
        <h1>${title}</h1>
        <p>${description}</p>
    </div>
`;

// Expression evaluation
let result = `2 + 2 = ${2 + 2}`;
print(result);  // "2 + 2 = 4"

Implementation Details:

  • Backtick (`) delimited strings
  • ${expr} for embedded expressions
  • Multi-line support with preserved whitespace
  • Nested template literals supported
  • New token: TOKEN_TEMPLATE_STRING
  • Compiled to string concatenation at bytecode level

3. Operator Overloading

Custom operators for user-defined types.

class Vector2D {
    let x: float;
    let y: float;

    func init(x, y) {
        this.x = x;
        this.y = y;
    }

    operator +(other: Vector2D): Vector2D {
        return new Vector2D(this.x + other.x, this.y + other.y);
    }

    operator *(scalar: float): Vector2D {
        return new Vector2D(this.x * scalar, this.y * scalar);
    }

    operator ==(other: Vector2D): bool {
        return this.x == other.x && this.y == other.y;
    }

    operator [](index: int): float {
        if (index == 0) return this.x;
        if (index == 1) return this.y;
        throw "Index out of bounds";
    }
}

let a = new Vector2D(1.0, 2.0);
let b = new Vector2D(3.0, 4.0);
let c = a + b;       // Vector2D(4.0, 6.0)
let d = a * 2.0;     // Vector2D(2.0, 4.0)
print(c[0]);          // 4.0

Overloadable Operators:

Category Operators
Arithmetic +, -, *, /, %, @ (matrix mul)
Comparison ==, !=, <, >, <=, >=
Subscript [] (get), []= (set)
Call () (callable objects)
Unary - (negate), ! (not)

4. Closures v2 (Escape Analysis)

Optimized closure representation with escape analysis.

Improvements:

  • Compiler detects if a closure escapes its defining scope
  • Non-escaping closures allocated on the stack (zero-cost)
  • Escaping closures heap-allocated with GC tracking
  • Upvalue deduplication for shared captured variables
  • Result: 3-5x performance improvement for functional programming patterns

5. ProXPL Formatter (prox fmt)

Opinionated code formatter — one style to rule them all.

# Format a single file
prox fmt app.prox

# Format entire project
prox fmt .

# Check formatting without modifying
prox fmt --check .

# Configuration (.proxfmt.pxcf)

Configuration (.proxfmt.pxcf):

formatter {
    indent: "spaces"
    indent_size: 4
    max_line_length: 100
    brace_style: "k&r"
    trailing_comma: true
    sort_imports: true
}

6. Enhanced Error Messages

Developer-friendly error reporting with suggestions.

error[E0412]: Undefined variable 'naem'
  --> src/main.prox:15:12
   |
15 |     print(naem);
   |           ^^^^ not found in this scope
   |
   = help: Did you mean 'name'?
   = note: 'name' is defined at line 10

error[E0308]: Type mismatch
  --> src/math.prox:22:16
   |
22 |     return "42";
   |            ^^^^
   |            expected 'int', found 'string'
   |
   = help: Use to_int("42") to convert

🐛 Bug Fixes

ID Description Component
BUG-501 Fix Wasm stack overflow on deep recursion Wasm backend
BUG-502 Fix template literal escaping for \${ Lexer
BUG-503 Fix operator overload resolution with inheritance Type Checker
BUG-504 Fix closure upvalue capture of loop variables Compiler
BUG-505 Fix formatter mangling multi-line string literals prox fmt

📈 Performance Goals

  • Wasm binary size: < 500KB for hello world
  • Wasm execution: Within 2x of native performance
  • Closure (non-escaping): Zero allocation overhead
  • Formatter: Process 10,000 LOC in < 500ms

🔧 Breaking Changes

  • Backtick (`) now reserved for template literals
  • operator keyword now reserved

ProXPL v1.7.0 — From server to browser, one language everywhere.