Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QBE Structs Overhall #110

Closed
wants to merge 6 commits into from
Closed

QBE Structs Overhall #110

wants to merge 6 commits into from

Conversation

garritfra
Copy link
Collaborator

Builds upon #61

Note: Not properly tested, since I'm currently on an arm machine.

Description

The QBE backend now provides comprehensive support for struct types with proper memory alignment and field access. This implementation handles nested structs, field access, and ensures proper memory layout according to standard alignment rules.

Features

  • Proper struct field alignment
  • Nested field access support
  • Nested struct initialization
  • Memory layout optimization
  • Automatic padding calculation

Memory Layout

Structs are laid out in memory following these rules:

  1. Each field is aligned according to its natural alignment requirements:
    • bool: 1-byte alignment
    • halfword: 2-byte alignment
    • int/word: 4-byte alignment
    • long/pointer: 8-byte alignment
  2. The struct's total size is padded to maintain its largest field's alignment requirement
  3. Nested structs maintain their alignment requirements within parent structs

Usage Example

struct Point {
    x: int
    y: int
}

struct Rectangle {
    origin: Point
    width: int
    height: int
}

fn main() {
    let rect = new Rectangle {
        origin: new Point {
            x: 10
            y: 20
        }
        width: 100
        height: 50
    }
    // Fields can be accessed naturally
    rect.origin.x += 5
}

ToDo

  • Proposed feature/fix is sufficiently tested
  • Proposed feature/fix is sufficiently documented
  • The "Unreleased" section in the changelog has been updated, if applicable

@garritfra
Copy link
Collaborator Author

Redundant

@garritfra garritfra closed this Dec 10, 2024
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