Document structures: a chapter, the architecture, and the differences
docs/16-structures.md is the feature: records, nesting, copy-on-assign, strict pointers, lists, what is checked and what is not, and how a host shares its own C structs. Every example in it is executed by docs_examples and byte-compared, including the refusals -- so a message that changes fails the suite rather than quietly making the chapter wrong. The chapter makes one contrast explicitly, because it is the question a reader will actually have: a misspelled *field* is refused and a misspelled *variable* still prints zero. The rule underneath is that what the program declared gets checked and what it did not gets shrugged at -- a variable's name is never declared, a TYPE's field list is. Structures end up the strictest thing in the language, not from a higher standard but because they are the only named thing whose valid spellings are written down. Chapter 14 gains the layout: an instance is a contiguous run of value slots with a diagram of where the fields sit, the three-pass prescan and why each pass exists, why the copy cannot live in akbasic_value_clone(), and why the render depth bound is four rather than eight. Chapter 3 gains the @ suffix, chapter 13 records that all of this is an addition BASIC 7.0 has nothing like, and the verb reference gains TYPE, POINT and DIM ... AS. MAINTENANCE.md gains the two rules that are on a maintainer rather than on a test: a structure copy must not go through clone, and a field chain gets its own leaf field. TODO.md section 5 records what was invented and the three limits that are ours, and section 8 records the two defects the work exposed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -497,6 +497,27 @@ So: still do it during single-threaded init, before the host game spawns anythin
|
||||
because the call would race, but because there is one operation in the registry that cannot be
|
||||
made safe and this is the discipline that avoids needing it.
|
||||
|
||||
### Structures reuse the array machinery, deliberately
|
||||
|
||||
`TYPE` declares a record, so an instance has a known slot count and takes one contiguous
|
||||
run from the same value pool `DIM A#(10)` draws from. **There is no structure pool**, and
|
||||
adding one would be the wrong instinct: the only new table holds *descriptors* — names and
|
||||
slot offsets — and the data goes where array data already goes.
|
||||
|
||||
Two rules for changing any of it:
|
||||
|
||||
- **A structure copy must not go through `akbasic_value_clone()`.** Clone copies one slot,
|
||||
and one slot holds a *reference* to an instance rather than the instance, so a structure
|
||||
taking that path aliases instead of copying — which is the semantics the language
|
||||
deliberately does not have. `akbasic_environment_assign()` intercepts first and calls
|
||||
`akbasic_struct_copy()`. If you add a place a structure can be assigned, it goes through
|
||||
that, not through clone.
|
||||
- **A field chain gets its own leaf type and its own link field.** `include/akbasic/grammar.h`
|
||||
records three separate defects that came from giving one link field two meanings;
|
||||
`AKBASIC_LEAF_FIELD` keeps its base on `.left`, which nothing else on that leaf type uses.
|
||||
|
||||
`docs/14-architecture.md` has the layout diagram and the three-pass prescan.
|
||||
|
||||
### Nothing calls malloc
|
||||
|
||||
`libakgl`'s hard rule, and ours: obtain objects from `akgl_heap_next_*` and release them back,
|
||||
|
||||
Reference in New Issue
Block a user