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

internal: use dedicated context type for vmbackend #835

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Aug 9, 2023

Summary

Add and use a dedicated type for the contextual state of the VM code-
generation orchestrator. This removes the hard coupling between
vmbackend and vmdef.TCtx and is another preparation for splitting up
the latter.

Details

The new GenCtx type replaces TCtx as the contextual-state type
for the orchestrator. For now, GenCtx still stores an instance of
TCtx, as the latter currently contains the code generator state.

In preparation for splitting up TCtx, usage of its idgen and
functions fields are removed from vmbackend.nim. The ID generator is
directly passed to procedures that need one, and the function table
(functions) is now stored in GenCtx -- prior to serializing the VM
environment, the function table stored with GenCtx's is moved into the
TCtx instance.

With the new dedicated type for the orchestrator, the collected globals
don't have to be stored in TCtx anymore. The collectedGlobals field
is made part of GenCtx and is renamed to just globals.

Misc

  • add the base template for OrdinalSeq and use it to reduce the
    noise in the OrdinalSeq routines
  • fix the add template for OrdinalSeq

The procedure didn't compile, but since it was never instantiated until
now, the problem never surfaced.
Add the `base` template for accessing the value as the `seq` type.
Don't re-use the `TCtx` type as the orchestrator's context/state type.
Instead, add a dedicated type (`GenCtx`) for this purpose.

This allows for removing the `collectedGlobals` field from `TCtx`, and
it is also a preparation for separating the `vmgen` state from `TCtx`
(the orchestrator needs some place to store the code generator state at,
which it now has with `GenCtx`).

Because it isn't used anywhere else, the `registerProc` procedure is
moved from `vmaux` to `vmbackend` and adjusted for the specific use-
case in the latter.
@zerbina zerbina added refactor Implementation refactor compiler/backend Related to backend system of the compiler labels Aug 9, 2023
@zerbina zerbina added this to the MIR phase milestone Aug 9, 2023
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

good start to the split. :D

@saem
Copy link
Collaborator

saem commented Aug 9, 2023

/merge

@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

  • part of the general TCtx split-up. The short-term goal is to separate the vmgen state from TCtx, which is effectively required for multiple planned CG-IR improvements

@chore-runner chore-runner bot added this pull request to the merge queue Aug 9, 2023
Merged via the queue into nim-works:devel with commit a6e6186 Aug 9, 2023
18 checks passed
@zerbina zerbina deleted the vmbackend-separate-from-tctx branch August 9, 2023 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/backend Related to backend system of the compiler refactor Implementation refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants