Commit 6a050bd
feat(vm): VM runs the core language + enforces consent (coverage, opcodes, consent) (#92)
## What
Advances the bytecode VM toward being a real compilation target. Before
this, the VM **crashed at runtime** on most real programs (the machine
rejected `MakeOkay`/`MakeOops`/`TryUnwrap`/`Index`/`MakeRecord`/`Len`/…
with "Unimplemented opcode"), the compiler couldn't compile ~10
statement / 4 expression forms, and — most importantly — **consent
blocks were silently bypassed** (the body ran unconditionally). This PR
closes the execution + coverage gaps and makes the VM **enforce
consent**.
Part of the VM-compilation-target roadmap from the repo state audit. Two
commits:
### 1. Full expression coverage + Result/record/index execution
- **Machine** (`vm/machine.rs`): implemented the opcodes the compiler
already emitted but the machine rejected — `MakeOkay`, `MakeOops`,
`IsOkay`, `TryUnwrap`, `Index` (array/string/record), `Len`,
`MakeRecord`, `Concat`, `ToString`, `Nop` — plus a new `Throw` (for
`complain`) and a `VMError::Runtime` variant.
- **Compiler** (`vm/compiler.rs`): `compile_expr` is now **exhaustive
over all 16 `Expr` variants** (added `RecordLiteral`, `FieldAccess`,
`UnitMeasurement`, `GratitudeLiteral`); `compile_statement` adds `While`
(with a loop-context stack for `Break`/`Continue`), `Complain`, and
`EmoteAnnotated`. The statement fallthrough now covers only the 5
worker/concurrency forms.
### 2. Consent enforcement under `#care` (the headline)
- `CompiledProgram` gains a `care` flag; new
`OpCode::CheckConsent(perm)`.
- The compiler detects the `#care` pragma and compiles `only if okay "…"
{ … }` to `CheckConsent; JumpIfFalse(skip); body` — a **denied**
permission now **skips** the body.
- The machine resolves `CheckConsent`: `#care` off ⇒ always granted;
`#care` on ⇒ granted only if pre-granted (**deny-by-default**, matching
the interpreter's non-interactive consent path). A `granted` set is the
seam for future grant sources.
## Verification
- **Full lib test suite green: 181 passed, 0 failed** (was 173; +8 new
VM tests).
- New tests: `while`, `while`+`break`, array index, `complain`→error
(source level); record/index/`Okay`/unwrap and array `len` (bytecode
level); **consent skipped under `#care on` / runs without it**.
- `cargo check` + `cargo test` clean.
## Deferred follow-ups (clearly scoped, noted in code)
- **Closures**: `Lambda`/`CallExpr` emit `MakeClosure`/`Call` which need
a value-call calling convention.
- **Result from surface syntax**: `Okay(x)` parses as a *call*, so it
needs `Okay`/`Oops` VM builtins to be reachable from source (the opcodes
work; the lowering doesn't emit them yet).
- **Consent grant sources**: seed `granted` from `superpower`
declarations / stored consent; capability wildcard matching.
- **Worker statements**, **bytecode serialization** (`.wbc`), and an
**interpreter↔VM parity harness** over the conformance suite.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_013wg3Mtq2QFhYi4XVw1Z6z7
---
_Generated by [Claude
Code](https://claude.ai/code/session_013wg3Mtq2QFhYi4XVw1Z6z7)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b141752 commit 6a050bd
4 files changed
Lines changed: 398 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
| |||
175 | 181 | | |
176 | 182 | | |
177 | 183 | | |
| 184 | + | |
| 185 | + | |
178 | 186 | | |
179 | 187 | | |
180 | 188 | | |
| |||
183 | 191 | | |
184 | 192 | | |
185 | 193 | | |
| 194 | + | |
186 | 195 | | |
187 | 196 | | |
188 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
44 | 52 | | |
45 | 53 | | |
46 | 54 | | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| 67 | + | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
| |||
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
77 | 98 | | |
78 | 99 | | |
79 | 100 | | |
| |||
267 | 288 | | |
268 | 289 | | |
269 | 290 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
280 | 299 | | |
281 | | - | |
282 | 300 | | |
283 | 301 | | |
284 | 302 | | |
285 | 303 | | |
| 304 | + | |
| 305 | + | |
286 | 306 | | |
287 | 307 | | |
288 | 308 | | |
| |||
412 | 432 | | |
413 | 433 | | |
414 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
415 | 501 | | |
416 | 502 | | |
417 | 503 | | |
| |||
605 | 691 | | |
606 | 692 | | |
607 | 693 | | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
612 | 729 | | |
613 | 730 | | |
614 | 731 | | |
| |||
0 commit comments