Skip to content

feat(struct): add StructDef and dot-access MVP#41

Open
thiremani wants to merge 18 commits intomasterfrom
codex/structdef-on-master
Open

feat(struct): add StructDef and dot-access MVP#41
thiremani wants to merge 18 commits intomasterfrom
codex/structdef-on-master

Conversation

@thiremani
Copy link
Owner

Summary

  • add Phase 1 StructDef support in .pt using header-row + single value row syntax
  • add .spt dot field access (p.name) with parser/type-solver/compiler support
  • store struct constants as LLVM named struct globals and extract fields via extractvalue
  • enforce duplicate struct type rejection and duplicate struct field header rejection
  • keep struct metadata in Code.Struct (parallel to Code.Const and Code.Func)
  • align struct type mangling/demangling to nominal type form (no Struct_ namespace prefix)

Syntax covered

p = Person
    :name age height
    "Tejas" 35 184.5
p.name, p.age, p.height

Implementation notes

  • lexer: . tokenization with .5 float compatibility
  • AST: StructLiteral, DotExpression, StructDef container
  • parser: struct literal parsing in code mode; dot postfix parsing in script mode
  • compiler/types/solver/cfg: struct kind/type handling + field access typing + traversal support
  • formatting: friendlier direct-struct print diagnostic

Tests

  • go test ./...
  • python3 test.py tests/struct
  • python3 test.py

Move reserved type-name source to a shared types package and use it from parser + compiler validations.

Also reject reserved function names (e.g. Int/I64) while keeping such identifiers valid for variables.
…ecks

Introduce StructStatement as a first-class code statement and wire it through parser/codecompiler/compiler flows.

Track immutable names via Code.ConstNames for shared redeclaration and CFG write-protection checks.

Allow repeated struct type definitions when headers match, and reject only conflicting headers across parse and merged compile validation.

Refactor codeparser const-binding validation to operate on identifier lists directly (remove temporary ConstStatement wrapper), and align struct-header comparison helper naming.

Update parser/compiler tests for repeated vs conflicting struct definitions and struct statement expectations.
Update StructLiteral.String to print multiline output with indented header and row blocks.

Add parser assertion for struct statement string rendering.

Validated with go test -race ./parser ./compiler and go test ./...
Remove the defensive nil check when emitting struct row expressions in StructLiteral.String.

Validated with go test -race ./parser ./compiler and go test ./...
Use singular Row for Phase 1 struct literals to reflect single-instance semantics and reduce ambiguity with future struct arrays.

Update parser/compiler/solver/cfg references and struct parser tests accordingly.

Validated with go test -race ./parser ./compiler and go test ./...
Remove trivial isGlobalConst helper and perform ConstNames lookup directly inside isDefined.

No behavior change; validated with go test ./compiler.
Guard unknown-header validation when the first-seen struct entry has empty headers.
Remove dead seenHeaders tracking in codecompiler and drop unreachable lexer dot-number branch.
Add parser regression test for empty init before full struct definition.
Rename validateAndTrackStructHeaders to validateStructHeaders for readability.
No behavior changes.
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.

1 participant