Skip to content

Compiler: simplify word size testing#508

Open
chqrlie wants to merge 1 commit intoc2lang:masterfrom
chqrlie:word-size
Open

Compiler: simplify word size testing#508
chqrlie wants to merge 1 commit intoc2lang:masterfrom
chqrlie:word-size

Conversation

@chqrlie
Copy link
Copy Markdown
Contributor

@chqrlie chqrlie commented Apr 18, 2026

  • add native_kind in ast_builder.Builder
  • group allocation stuff in TailAllocator as a member of ast_context.Context
  • add wordsize in ast_context.Context
  • move compiler sub-object creation after target analysis
  • use gen.targetInfo for word size in C Generator
  • add align member in Type.typebits, use for builtins, pointers and functions
  • initialize dummy slot 0 in pointer pool
  • move getWordSize() and getNativeKind() from global to ast_context
  • simplify size_analyser.sizeOfType: no reference to global needed
  • conversion_checker gets native_kind from builder/context
  • simplify getUnaryOpWidth, no global reference anymore

@bvdberg
Copy link
Copy Markdown
Member

bvdberg commented Apr 19, 2026

What's the purpose of splitting Context into a TailAllocator and a Context?

@chqrlie
Copy link
Copy Markdown
Contributor Author

chqrlie commented Apr 19, 2026

The TailAllocator belongs in ast_utils and should only deal with allocation

The ast_context.Context should hold the core ast data, such as the builtins, the string and pointer pool, and some ancillary data such as the wordsize. It should be moved to the ast module as ast.AstContext and passed to the different modules.

This PR performs an initial step in this direction but it might be better to make a more radical move, for which I have a larger patch in progress.

* add `native_kind` in `ast_builder.Builder`
* group allocation stuff in `TailAllocator` as a member of `ast_context.Context`
* add `wordsize` in `ast_context.Context`
* move compiler sub-object creation after target analysis
* use `gen.targetInfo` for word size in C Generator
* add `align` member in `Type.typebits`, use for builtins, pointers and functions
* initialize dummy slot 0 in pointer pool
* move `getWordSize()` and `getNativeKind()` from global to ast_context
* simplify `size_analyser.sizeOfType`: no reference to `global` needed
* conversion_checker gets `native_kind` from builder/context
* simplify `getUnaryOpWidth`, no global reference anymore
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