Commit 5566f62
feat(L10): mutable agent state —
The runtime substrate for L10 rung-3b: agent handlers received a *copy* of
agent state with no write-back, so state was effectively immutable and there
was no assignment statement at all. The new `set <field> = <expr>` control
statement assigns to a declared `state` field and persists into the live
`AgentInstance.state`, so a later handler firing observes the new value.
- AST: additive `ControlStmt::SetState { field, value }` (existing untouched).
- Grammar: `grammar.pest` `set_stmt` rule + `set` keyword; `spec/grammar.ebnf`
mirror — both grammar guards exit 0, `set_stmt` is in the shared rule set.
- Eval: write through to `AgentInstance.state` + `Env::update` so in-handler
reads see the new value.
- Typecheck: the target must be a declared agent `state` (new
`agent_state_fields`, mirroring rung-3b's `agent_residue_names` save/restore)
and the value's type must unify with the field's declared type — new
`TypeErrorKind::AssignToNonState` → `agent_api` `SET_NON_STATE`.
- Threaded the additive variant through codegen cranelift/elixir/native,
dual_ast, formatter, metainterpreter, CFG, and the oracle checker.
Tests: 1 parser + 3 typechecker (declared-ok / non-state-error / type-mismatch)
+ 2 evaluator (within-agent `set count = 7` persistence; `set count = count + 1`
accumulating across three `receive` firings, observed as 3 by a separate
`report` handler) — 910 oo7-core lib tests pass, fmt + clippy clean. New
`examples/mutable_agent_state.007` (parse + typecheck + run; full e2e
PASS=55 FAIL=0). Spec: TYPE-SYSTEM-SPEC §11b.7; CHANGELOG; echo-residue-
integration.adoc substrate note.
Note: the pre-existing `oo7-typechecker-oracle` `production_and_oracle_agree`
differential test fails on clean `main` too (verified via git stash, 3/3 runs;
proptest is nondeterministic and can't find its persistence file) — it is a
production-vs-oracle divergence on a trivial total fn, not a regression here.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018CaSgNjNURC7ocsyjYh9Weset <field> = <expr>
1 parent fda2604 commit 5566f62
24 files changed
Lines changed: 469 additions & 7 deletions
File tree
- .machine_readable
- 6a2
- crates
- oo7-core/src
- semantic_analyser
- oo7-typechecker-oracle/src
- docs
- examples
- spec
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
693 | 693 | | |
694 | 694 | | |
695 | 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 | + | |
696 | 721 | | |
697 | 722 | | |
698 | 723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
362 | 368 | | |
363 | 369 | | |
364 | 370 | | |
| |||
0 commit comments