Skip to content

Conversation

@DigitalCodeCrafter
Copy link

Closes #3154
This PR introduces a new, fully backward-compatible pointer system for low-level kOS bytecode.
It enables indirect access to stack entries, variables, and nested data structures.

This feature is intended for assembly authors and compiler backends.
It has no effect on normal Kerboscript unless future changes to the compiler are made.

Summary

New PointerValue structure

  • Stores a list of segments describing how to resolve a value.
  • Segment rules:
    • First Segment (root):
      • ScalarIntValue: absolute stack index
      • StringValue beginning with $: variable name
    • Remaining segments:
      • Keys / indices for nested structures (lists, lexicons, etc.)
  • Not enumerable or indexable; only used via dedicated opcodes.

New opcodes

Opcode Stack Input Output Description
CREATEPTR n segN
..
seg1
ptr Builds a pointer from n stack segments
GETPTR ptr value Resolves a pointer and pushes the referenced value
SETPTR value
ptr
-- Writes value to the referenced location
ALLOCATE n -- Null
...
Null
Pushes n nulls onto the stack (reserves stack space)
FREE n ... -- Pops n value from the stack (releases stack space)
STACKPTR -- sp Pushes the current stack pointer (stack length).
INSTPTR -- ip Pushes the current instruction pointer.

These replace the previously proposed PEEK/POKE/STORNAME approach with a more flexible and extensible system.

Compatibility

  • No changes to existing opcodes.
  • No behavioral impact on existing scripts.
  • PointerValue inaccessible to normal Kerboscript
  • Only programs explicitly using the new opcodes are affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new opcodes with pointer functionality

1 participant