Skip to content

Commit 388f104

Browse files
Update documentation to the latest version
1 parent 514df4e commit 388f104

File tree

6 files changed

+185
-45
lines changed

6 files changed

+185
-45
lines changed

design/index.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ Source File (.ml)
101101
┌──┴──┐
102102
│ │
103103
▼ ▼
104-
┌───────┐ ┌────────┐
105-
│Python │ │ WASM │ Code generation targets
106-
│Code │ │ Code │
107-
│Gen. │ │ Gen. │
108-
└───┬───┘ └───┬────┘
109-
│ │
110-
▼ ▼
104+
┌───────┐ ┌────────
105+
│Python │ │ WAT │ Code generation targets
106+
│Code │ │ Code │
107+
│Gen. │ │ Gen. │
108+
└───┬───┘ └───┬────┘
109+
110+
111111
┌───────┐ ┌──────────────┐
112-
│Python │ │ Cranelift
113-
│Runtime│ │ Compiler
114-
│(exec) │ │ → .wasm
112+
│Python │ │ WAT text
113+
│Runtime│ │ → wasmtime
114+
│(exec) │ │ (→ .wasm)
115115
└───────┘ └──────────────┘
116116
```
117117

@@ -363,6 +363,7 @@ JSON-based keyword files allow community contributors to add new languages witho
363363
| `multilingualprogramming/core/ir.py` | CoreIRProgram definition |
364364
| `multilingualprogramming/core/lowering.py` | AST → Core IR lowering |
365365
| `multilingualprogramming/codegen/python_generator.py` | Python code generation |
366-
| `multilingualprogramming/codegen/wasm_generator.py` | WASM code generation |
366+
| `multilingualprogramming/codegen/wat_generator.py` | AST → WebAssembly Text (WAT) generation |
367+
| `multilingualprogramming/codegen/wasm_generator.py` | WAT text → WASM binary |
367368
| `multilingualprogramming/runtime/backend_selector.py` | WASM/Python backend selection |
368369
| `multilingualprogramming/runtime/python_fallbacks.py` | Pure Python WASM fallbacks |

index.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permalink: /
66
---
77

88
<section class="hero">
9-
<span class="hero-eyebrow">v0.4.0 &mdash; Now with WASM</span>
9+
<span class="hero-eyebrow">v0.5.1 &mdash; Now with WASM &amp; OOP</span>
1010
<h1 class="hero-title">
1111
Write Code in<br/>
1212
<span class="gradient-text">Any Human Language</span>
@@ -27,7 +27,7 @@ permalink: /
2727
<div class="stat-label">Human Languages</div>
2828
</div>
2929
<div class="stat-item">
30-
<div class="stat-value">858</div>
30+
<div class="stat-value">1,797</div>
3131
<div class="stat-label">Test Cases</div>
3232
</div>
3333
<div class="stat-item">
@@ -39,7 +39,7 @@ permalink: /
3939
<div class="stat-label">Localized Builtins</div>
4040
</div>
4141
<div class="stat-item">
42-
<div class="stat-value">0.4.0</div>
42+
<div class="stat-value">0.5.1</div>
4343
<div class="stat-label">Current Version</div>
4444
</div>
4545
</div>
@@ -184,7 +184,7 @@ saludar(nombre)
184184

185185
<div class="feature-card">
186186
<span class="feature-icon">🧪</span>
187-
<div class="feature-title">858 Tests, 78 Suites</div>
187+
<div class="feature-title">~1,797 Tests, 58 Files</div>
188188
<p class="feature-desc">Comprehensive test coverage across all 17 languages. Every language frontend is validated end-to-end: lexer → parser → semantic → codegen → execution.</p>
189189
</div>
190190

@@ -330,15 +330,15 @@ Surface Language (.ml file)
330330
┌────┴────┐
331331
│ │
332332
▼ ▼
333-
┌───────┐ ┌──────┐
334-
│Python │ │ WASM │ Code generation targets
335-
│ Gen │ │ Gen │
336-
└───┬───┘ └─────┘
337-
│ │
338-
▼ ▼
333+
┌───────┐ ┌─────────
334+
│Python │ │ WAT │ Code generation targets
335+
│ Gen │ │ Gen
336+
└───┬───┘ └────┬────┘
337+
338+
339339
┌───────┐ ┌──────────┐
340-
│Python │ │ Cranelift
341-
│Runtime│ │ Compiler
340+
│Python │ │ wasmtime
341+
│Runtime│ │ (→ .wasm)
342342
└───────┘ └──────────┘
343343
```
344344

reference/compatibility.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: page
33
title: "Compatibility Matrix"
4-
description: "Python 3.12 compatibility baseline for multilingual — 858 tests, 78 suites, 17 languages."
4+
description: "Python 3.12 compatibility baseline for multilingual — ~1,797 tests, 58 test files, 17 languages."
55
category: "Reference"
66
permalink: /reference/compatibility/
77
prev_page:
@@ -12,7 +12,7 @@ prev_page:
1212
This matrix defines the current compatibility baseline for `multilingual`. The source of truth is:
1313

1414
- `examples/complete_features_en.ml` and equivalents in all 17 languages
15-
- `tests/` (858 tests across 78 test suites)
15+
- `tests/` (~1,797 tests across 58 test files)
1616

1717
**Target runtime**: CPython 3.12.x
1818

@@ -187,10 +187,10 @@ SOV and RTL languages can use natural word order. The surface normalizer rewrite
187187

188188
## Test Coverage
189189

190-
858 tests across 78 test suites:
190+
~1,797 tests across 58 test files (~19,848 lines of test code):
191191

192-
| Test area | Suites | Description |
193-
|-----------|--------|-------------|
192+
| Test area | Files | Description |
193+
|-----------|-------|-------------|
194194
| Numerals and dates | 8 | Multilingual numerals, Unicode, Roman, complex, fractions, datetime |
195195
| Lexer | 2 | Tokenization and lexer behavior |
196196
| Parser | 5 | Expressions, statements, compounds, multilingual, errors |
@@ -200,6 +200,7 @@ SOV and RTL languages can use natural word order. The surface normalizer rewrite
200200
| Critical features | 8 | Triple-quoted strings, slices, parameters, tuples, comprehensions, decorators, f-strings |
201201
| Language completeness and CLI | 8 | Augmented assignment, membership, ternary, assert, chained assignment, CLI, REPL |
202202
| Advanced language features | 23 | Loop else, yield/raise from, set comprehensions, parameter separators, f-string formatting, match guards/OR/AS, global/nonlocal, builtins, exceptions, surface normalization, extended builtins, alias resolution, starred unpacking, integration, multilingual |
203+
| WAT/WASM backend | 5 | WAT generation, OOP/inheritance in WAT, WASM execution, corpus projects (20) |
203204
| Infrastructure | 10 | Keyword registry, AST nodes, AST printer, error messages, runtime builtins, REPL |
204205

205206
---
@@ -218,11 +219,22 @@ The following are **not** claimed as universally compatible:
218219

219220
---
220221

222+
## Known Fixes (v0.5.x)
223+
224+
| Version | Fix |
225+
|---------|-----|
226+
| v0.5.1 | Documentation updates |
227+
| v0.5.0 | WAT/WASM OOP object model: class lowering with linear-memory bump allocator, inheritance with C3 MRO, `super()` resolution, WAT execution tests |
228+
| v0.5.0 | SemanticAnalyzer: plain assignments (`x = 5`) now correctly define the variable in scope rather than triggering a false `UNDEFINED_NAME` error (was a false-positive in some languages, e.g., French) |
229+
| v0.5.0 | Augmented assignment (`x += 1`) now correctly reports `UNDEFINED_NAME` when the target variable has not been previously defined |
230+
231+
---
232+
221233
## Recommendation
222234

223235
When evaluating compatibility for a real codebase:
224236

225237
1. Start from this matrix
226-
2. Run smoke tests: `python -m multilingualprogramming smoke --all`
227-
3. Run focused tests: `python -m multilingualprogramming run yourprogram.ml --lang en`
238+
2. Run smoke tests: `multilingual smoke --all`
239+
3. Run focused tests: `multilingual run yourprogram.ml --lang en`
228240
4. Track gaps as concrete syntax/runtime items

reference/index.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ next_page:
88
title: "Built-in Aliases"
99
url: /reference/builtins/
1010
badges:
11-
- text: "v0.4.0"
11+
- text: "v0.5.1"
1212
type: default
1313
- text: "Python 3.12+"
1414
type: success
@@ -356,21 +356,28 @@ output = repl.eval_line("afficher(x)")
356356

357357
```bash
358358
# Run a program file
359-
python -m multilingualprogramming run <file.ml> --lang <code>
360359
multilingual run <file.ml> --lang en
361360
multilg run programme.ml --lang fr
362361

363362
# Start REPL
364-
python -m multilingualprogramming repl
365-
python -m multilingualprogramming repl --lang fr
366-
python -m multilingualprogramming repl --show-python
363+
multilingual repl
364+
multilingual repl --lang fr --show-python --show-wat
365+
366+
# Transpile to Python (print output, no execution)
367+
multilingual compile hello.ml --lang en
368+
369+
# Build WASM bundle
370+
multilingual build-wasm-bundle hello.ml --lang en --out-dir ./dist
367371

368372
# Validate a language pack
369-
python -m multilingualprogramming smoke --lang fr
370-
python -m multilingualprogramming smoke --all
373+
multilingual smoke --lang fr
374+
multilingual smoke --all
375+
376+
# Check generated output encoding
377+
multilingual encoding-check-generated hello.ml --lang en
371378

372379
# Show version
373-
python -m multilingualprogramming --version
380+
multilingual --version
374381
```
375382

376383
---
@@ -420,4 +427,15 @@ python -m multilingualprogramming --version
420427
| Localized built-in aliases (41 concepts) ||
421428
| Surface normalization (SOV/RTL languages) ||
422429

423-
**858 tests across 78 test suites** provide the compatibility baseline.
430+
**~1,797 tests across 58 test files** provide the compatibility baseline.
431+
432+
---
433+
434+
## Version History
435+
436+
| Version | Highlights |
437+
|---------|-----------|
438+
| `0.5.1` | Documentation updates |
439+
| `0.5.0` | WAT/WASM OOP object model; class lowering with linear-memory bump allocator; inheritance with C3 MRO; `super()` resolution; WAT execution tests; SemanticAnalyzer plain-assignment fix |
440+
| `0.4.0` | WAT/WASM code generation; browser playground; WASM backend with 25+ Python fallbacks; 20 corpus projects |
441+
| `0.3.0` | Earlier milestone |

wasm/architecture.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The WASM infrastructure is designed around three principles: **transparent selec
2020

2121
```
2222
┌─────────────────────────────────────────────────────────────┐
23-
│ Multilingual Programming Language v0.5
23+
│ Multilingual Programming Language v0.5.1
2424
└─────────────────────────────────────────────────────────────┘
2525
2626
┌─────────────┴──────────────┐
@@ -291,6 +291,81 @@ The WASM bridge handles errors at multiple levels:
291291

292292
---
293293

294+
## OOP Object Model in WAT (v0.5.0+)
295+
296+
Classes with instance attributes use a **linear-memory bump allocator** for object storage. Stateless classes (no `self.attr` assignments) use `f64.const 0` as the `self` value for backward compatibility.
297+
298+
### Heap Allocator
299+
300+
```wat
301+
(global $__heap_ptr (mut i32) (i32.const HEAP_BASE))
302+
```
303+
304+
- Emitted only when at least one stateful class exists.
305+
- `HEAP_BASE` is computed from string data size, rounded up to 8-byte alignment (minimum 64).
306+
- Each constructor advances `$__heap_ptr` by the object's byte size and returns the pointer as `f64`.
307+
308+
### Field Layout
309+
310+
Fields are stored as `f64` values (8 bytes each) in linear memory. Inherited fields come first:
311+
312+
```
313+
Object memory layout:
314+
┌─────────────────────────────────────────────────┐
315+
│ +0 │ field_0 (f64, 8 bytes) │
316+
│ +8 │ field_1 (f64, 8 bytes) │
317+
│ ... │ │
318+
└─────────────────────────────────────────────────┘
319+
```
320+
321+
Field store/load pattern:
322+
323+
```wat
324+
;; self.attr = value (store)
325+
local.get $self
326+
i32.trunc_f64_u
327+
i32.const <field_offset> ;; field_index * 8
328+
i32.add
329+
<value>
330+
f64.store
331+
332+
;; x = self.attr (load)
333+
local.get $self
334+
i32.trunc_f64_u
335+
i32.const <field_offset>
336+
i32.add
337+
f64.load
338+
```
339+
340+
### Inheritance
341+
342+
- `_effective_field_layout(cls)`: merges parent fields before own fields recursively.
343+
- `_mro(cls)`: C3 linearization (same algorithm as CPython, cycle-safe).
344+
- Method resolution: if a subclass does not define a method, the parent's WAT function name is used.
345+
- Constructor inheritance: if a class has no `__init__`, the parent's constructor is inherited.
346+
- `super()` calls: `_resolve_super_call(expr)` detects `super().method(...)` and maps to the parent's WAT function.
347+
348+
### Stub Detection
349+
350+
Unsupported WAT constructs emit comment stubs:
351+
352+
```wat
353+
;; unsupported call: len(mylist)
354+
```
355+
356+
Use `has_stub_calls(wat_text)` to detect stubs programmatically:
357+
358+
```python
359+
from multilingualprogramming.codegen.wat_generator import WATCodeGenerator, has_stub_calls
360+
361+
gen = WATCodeGenerator("en")
362+
wat = gen.generate(ast)
363+
if has_stub_calls(wat):
364+
print("WAT contains unsupported call stubs")
365+
```
366+
367+
---
368+
294369
## Extending WASM with New Functions
295370

296371
To add a new operation to the WAT backend:

wasm/index.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ The multilingual WASM backend provides 50–100x performance improvements for co
5858

5959
<div class="card">
6060
<span class="card-icon">🔧</span>
61-
<h3>Cranelift Backend</h3>
62-
<p>Uses the Cranelift compiler (Rust-based, part of Wasmtime) for native-speed code generation from the multilingual AST.</p>
61+
<h3>WAT Code Generation</h3>
62+
<p>Compiles the Core AST directly to WebAssembly Text (WAT) format. WAT is assembled to binary WASM and executed via wasmtime — no external Rust toolchain required.</p>
6363
</div>
6464

6565
<div class="card">
@@ -146,9 +146,9 @@ multilingual Source (.ml)
146146
│ Core AST
147147
148148
┌─────────────────┐
149-
WASM Generator │ → Rust intermediate code
150-
│ (wasm_generator.py) │ ↓
151-
└─────────────────┘ Cranelift compiler
149+
WAT Generator │ → WAT text (module.wat)
150+
│ (wat_generator.py) │ ↓
151+
└─────────────────┘ wabt / wat2wasm
152152
153153
.wasm binary
154154
@@ -184,6 +184,40 @@ multilingual Source (.ml)
184184

185185
---
186186

187+
## WAT Language Support
188+
189+
The WAT backend supports a rich subset of the multilingual language. Unsupported constructs emit stub comments and fall back to Python.
190+
191+
| Construct | WAT support |
192+
|---|---|
193+
| Variable declaration/assignment ||
194+
| Arithmetic (+, -, *, /) | ✓ (f64) |
195+
| Augmented assignment (+=, -=, *=, /=, //=, %=) ||
196+
| Augmented assignment (&=, \|=, ^=, <<=, >>=) | ✓ i32 round-trip |
197+
| Comparisons and boolean logic ||
198+
| `if` / `elif` / `else` ||
199+
| `while` loop ||
200+
| `for` loop ||
201+
| Function definition and `return` ||
202+
| `async def` / `await` | ✓ best-effort |
203+
| Class definition (OOP) with fields | ✓ linear-memory object model |
204+
| Inheritance and `super()` | ✓ C3 MRO |
205+
| `match`/`case` (numeric/boolean) | ✓ lowered to WAT blocks |
206+
| `match`/`case` (string/complex) | stub |
207+
| `print` | ✓ host import |
208+
| `abs`, `min`, `max` (n-arg) | ✓ native f64 ops |
209+
| `len` (string literal/var, list, tuple) ||
210+
| List/tuple literal allocation | ✓ heap bump-allocator |
211+
| List/tuple index read ||
212+
| `try/except/finally` | ✓ best-effort |
213+
| `with` statement | ✓ best-effort |
214+
| Lambda expressions | ✓ lifted to named WAT functions |
215+
| List/generator comprehension over `range` ||
216+
| String concatenation, indexing, slicing | not supported |
217+
| `async for` / `async with` | not supported |
218+
219+
---
220+
187221
## Supported Operations
188222

189223
All 17 languages support both Python and WASM backends. The WASM backend accelerates:

0 commit comments

Comments
 (0)