diff --git a/docs/language/types/type-fixeds.md b/docs/language/types/type-fixeds.md new file mode 100644 index 00000000..40e4bbaf --- /dev/null +++ b/docs/language/types/type-fixeds.md @@ -0,0 +1,23 @@ +--- +id: type-fixeds +name: fixeds +category: types +kind: type +tokens: fixeds +sig: fixeds +tip: A buffer of fixed-point values — f[i] reads and writes a fixed. +order: 8 +--- + +A fixeds is a raw buffer whose elements are fixed (Q16.16) values: index it with buffer[i] to read or write a fixed directly, with no bounds checking. You obtain one by allocating raw storage with words(n) — each slot is 32 bits — and typing the binding as fixeds so that indexing uses the fixed-point element size. Reach for it when you want a tight, fixed-size numeric array with deterministic math — a table of speeds, per-tile weights, a heightfield — and a growable []fixed slice would be more than you need. + +```ludic +program Heights { + handler Setup phase Start { + let heights: fixeds = words(4) + heights[0] = fx(2) + heights[1] = heights[0] + fx(1) + print(flr(heights[1])) + } +} +``` diff --git a/docs/language/types/type-ptrs.md b/docs/language/types/type-ptrs.md new file mode 100644 index 00000000..106d6e42 --- /dev/null +++ b/docs/language/types/type-ptrs.md @@ -0,0 +1,25 @@ +--- +id: type-ptrs +name: ptrs +category: types +kind: type +tokens: ptrs +sig: ptrs +tip: A buffer of pointers — p[i] reads and writes a ptr. +order: 9 +--- + +A ptrs is a raw buffer whose elements are pointers: index it with buffer[i] to read or write a ptr, with no bounds checking. Allocate the storage with words(n) (a pointer fits in a slot) and type the binding as ptrs so indexing uses the pointer element size. It is the low-level building block for hand-rolled data structures — a table of records made with new, a free list, a bucket array — for when you want manual control instead of a growable []T slice. + +```ludic +program Records { + property Position { column: int = 0, row: int = 0 } + + handler Setup phase Start { + let slots: ptrs = words(2) + slots[0] = new Position + slots[1] = new Position + print(2) + } +} +``` diff --git a/tools/docgen/inventory.json b/tools/docgen/inventory.json index 500acd22..882280e4 100644 --- a/tools/docgen/inventory.json +++ b/tools/docgen/inventory.json @@ -173,15 +173,17 @@ "kw-enum" ], "types": [ - "type-int", - "type-fixed", "type-bool", - "type-str", - "type-entity", - "type-ptr", - "type-words", "type-byte", + "type-entity", + "type-fixed", + "type-fixeds", + "type-int", + "type-ptr", + "type-ptrs", + "type-slices", + "type-str", "type-void", - "type-slices" + "type-words" ] }