Skip to content

Extract compiler assembly emitter - #61

Merged
katsyoshi merged 13 commits into
mainfrom
refactoring-compiler
Aug 26, 2026
Merged

Extract compiler assembly emitter#61
katsyoshi merged 13 commits into
mainfrom
refactoring-compiler

Conversation

@katsyoshi

@katsyoshi katsyoshi commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • extract GAS Intel assembly serialization from Compiler::Generator into Compiler::Emitter
  • add Compiler::Analyzer and explicit compilation contexts for entry points, methods, parameters, and local variables
  • represent the top-level entry and defined methods as Context::Function instances
  • make the generator consume analyzed function contexts instead of rediscovering method bodies and variable slots
  • resolve required positional parameters and local variables per function
  • add matching RBS declarations and focused analyzer/context coverage
  • add an end-to-end shared-library test that calls a compiled function with Fiddle and verifies its arguments, local assignment, and return value

Pipeline

RubyVM AST -> Analyzer -> Context::Function -> Generator -> Emitter -> AMD64 assembly

This keeps RubyVM-specific analysis out of assembly serialization and establishes explicit function-level state before further lowering work.

Current scope

  • required positional parameters are supported
  • optional, rest, and keyword parameter modeling remain follow-up work
  • the frontend still uses RubyVM::AbstractSyntaxTree; introducing compiler-owned syntax nodes is intentionally deferred

Tests

  • rake test — 65 tests, 293 assertions, 1 environment-dependent omission
  • rake steep:check
  • bundle exec rbs validate

The omitted test requires Ruby::Box, which is not supported in the current environment.

Follow-up

  • separate RubyVM-specific traversal from analysis and AMD64 lowering
  • move label allocation and remaining lowering-only state into the appropriate contexts
  • replace remaining parser-node handling in the generator with compiler-owned syntax nodes

@katsyoshi

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79656d54aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/caotral/compiler/generator.rb Outdated
@katsyoshi

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb95d74017

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/caotral/compiler/generator.rb
@katsyoshi

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb95d74017

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/caotral/compiler/generator.rb
@katsyoshi

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c60bac661

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/caotral/compiler/analyzer.rb
@katsyoshi

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 65e012e714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@katsyoshi
katsyoshi merged commit 2b6067e into main Aug 26, 2026
0 of 2 checks passed
@katsyoshi
katsyoshi deleted the refactoring-compiler branch August 26, 2026 09:17
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