Skip to content

Chapter 10: File-Scope Variables and Storage Classes - #17

Merged
johnhringiv merged 7 commits into
mainfrom
chapter_10
Jan 12, 2026
Merged

johnhringiv merged 7 commits into
mainfrom
chapter_10

Conversation

@johnhringiv

Copy link
Copy Markdown
Owner

Release Notes

New Features

File-Scope Variables

  • Global variable declarations at file scope with optional constant initializers
  • Variables placed in .data section (initialized) or .bss section (zero-initialized)
  • RIP-relative addressing for all static/extern variable access

Storage-Class Specifiers

  • static - Internal linkage for functions and variables (file-local visibility)
  • extern - External linkage, resolved by linker at link time
  • Proper tentative definition handling per C semantics

Assembly Output Improvements

  • External variable names now displayed in -S disassembly output
  • Symbol resolver shows RIP-relative data references with their names

Improvements

Code Generation

  • New Data operand type for static/extern variables
  • Operand::is_memory() helper for cleaner instruction fixing
  • Consolidated divide/remainder codegen (removed duplication)
  • Proper .globl directive emission (was incorrectly .global)

Semantic Analysis

  • Separate validation for local vs file-scope variable declarations
  • Linkage conflict detection (static vs non-static redeclarations)
  • Constant expression evaluation for static initializers
  • Redefinition checking for variables with initializers

Object File Emission (iced-x86)

  • undefined_symbol() helper to reduce code duplication
  • Static variables emitted to .data/.bss sections with proper alignment
  • Extern symbols marked as undefined for linker resolution
  • Function and data symbol visibility (Dynamic vs Compilation scope)

Testing

  • ABI compatibility tests: cross-compile client/library between NCC and GCC
  • stdout capture and verification support
  • Test infrastructure updated to chapter 10

Grammar

<program> ::= { <declaration> }
<declaration> ::= <variable-declaration> | <function-declaration>
<variable-declaration> ::= { <specifier> }+ <identifier> [ "=" <exp> ] ";"
<function-declaration> ::= { <specifier> }+ <identifier> "(" <param-list> ")" ( <block> | ";" )
<specifier> ::= "int" | "static" | "extern"

🤖 Generated with Claude Code

@claude

claude Bot commented Jan 11, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@codecov

codecov Bot commented Jan 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.03650% with 123 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/emit_iced.rs 60.24% 99 Missing ⚠️
src/emit.rs 78.57% 18 Missing ⚠️
src/main.rs 89.65% 3 Missing ⚠️
src/parser.rs 97.43% 2 Missing ⚠️
src/codegen.rs 98.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@claude

claude Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@johnhringiv
johnhringiv merged commit 957777c into main Jan 12, 2026
2 of 3 checks passed
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