-
Notifications
You must be signed in to change notification settings - Fork 241
Open
Description
kOS currently has no built-in mechanism for general pointer-like or indirect data access.
The only workaround is wrapping data inside lists and manually passing references, which is limited and cannot refer to stack positions or nested data structures.
By adding a PointerValue and 3 new opcodes, simple pointer functionality can be achieved:
Proposed new opcodes
CREATEPTR n: constructs a pointer from n stack elementsGETPTR: resolves a pointer and pushes its resolutionSETPTR: writes a value through a pointer
Pointer consist of a list of segments:
- First segment:
- scalar int: absolute stack index
$prefixed string: local variable name
- Remaining segments: keys / indices for nested structures (lists, lexicons, etc.)
This enables pointers to reference:
- Stack values
- variables dynamically by name
- list elements
- nested data structures of arbitrary depth
Optional (quality-of-life):
ALLOCATE n: advances the stack pointer by pushing a known number of nulls.FREE n: quickly pops a known number of elements from the stack.STACKPTR: pushes the current stack pointer (stack length).INSTPTR: pushes the current instruction pointer.
All proposed opcodes are fully backwards-compatible and inert unless explicitly used.
Metadata
Metadata
Assignees
Labels
No labels