Skip to content

Add unsafe pointer syntax/runtime support with typed *type and type[n] declarations#89

Merged
DanexCodr merged 8 commits into
mainfrom
copilot/implement-unsafe-modifier
Apr 12, 2026
Merged

Add unsafe pointer syntax/runtime support with typed *type and type[n] declarations#89
DanexCodr merged 8 commits into
mainfrom
copilot/implement-unsafe-modifier

Conversation

Copilot AI commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

The language now supports pointer-style operations inside unsafe contexts while keeping safe code pointer-free by default. This includes typed pointer declarations, fixed-size typed buffers, and core pointer operators with runtime bounds enforcement.

  • Type syntax + parser updates

    • Added unsafe type forms:
      • *type for pointers (e.g. *u8)
      • type[n] for fixed-size arrays (e.g. u8[1024])
    • Extended expression parsing for unary pointer operators:
      • address-of &
      • dereference *
    • Preserved safe-by-default behavior by gating pointer type parsing to unsafe declaration contexts.
  • Unsafe runtime pointer model

    • Introduced a pointer runtime value carrying:
      • backing container
      • current index
      • pointed element type
    • Implemented:
      • &buffer[i] address-of on indexed arrays/lists
      • *ptr dereference
      • ptr +/- int pointer arithmetic
  • Safety constraints in unsafe mode

    • Enforced pointer operations only in unsafe execution contexts (unsafe class/method flow).
    • Added bounds checks for:
      • pointer creation from indexed access
      • pointer arithmetic result
      • pointer dereference
  • Type handling + field initialization

    • Extended type validation/concrete typing for pointer values and sized array signatures.
    • Added default initialization for sized unsafe fields (type[n]) and pointer fields in object construction paths.
  • Feature example

    x: int = 42
    
    unsafe LowLevel {
        ptr: *u8
        buffer: u8[1024]
    
        method() {
            ptr = &buffer[0]
            value := *ptr
            ptr = ptr + 16
        }
    }
    

Copilot AI and others added 8 commits April 12, 2026 11:06
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/73ca2733-a902-400a-8f03-4388d21e2a7e

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/73ca2733-a902-400a-8f03-4388d21e2a7e

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/b476ffd3-a03b-47a2-8df7-6f9f23f27c87

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/b476ffd3-a03b-47a2-8df7-6f9f23f27c87

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
Agent-Logs-Url: https://github.com/DanexCodr/Coderive/sessions/b476ffd3-a03b-47a2-8df7-6f9f23f27c87

Co-authored-by: DanexCodr <216312766+DanexCodr@users.noreply.github.com>
@DanexCodr DanexCodr marked this pull request as ready for review April 12, 2026 12:51
@DanexCodr DanexCodr merged commit 156101e into main Apr 12, 2026
1 check passed
@DanexCodr DanexCodr deleted the copilot/implement-unsafe-modifier branch April 12, 2026 12:51
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.

2 participants