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

codegen: don't use PSym for labels #940

Merged

Commits on Oct 4, 2023

  1. codegen: don't use PSym for labels

    Summary
    =======
    
    In the code generators, represent block labels with a dedicated type and
    node, instead of using `PSym` for that. This is an internal-only change,
    and another step towards removing all `PSym` usage from the code
    generators.
    
    Details
    =======
    
    * add the `cnkLabel` node kind to `CgNode`
    * it stores a `BlockId`, and appears as sub-node for both `cnkBlockStmt`
      and `cnkBreakStmt`
    * a `BlockId` is not a unique ID within a `Body` -- instead it
      identifies the enclosing `block` for a `break`. This matches how the
      code generators previously used `skLabel` symbols
    * `cgirgen` now no longer queries or modifies the identifier cache
      (`IdentCache`), so all usages of the type are removed. The `idents`
      import is turned into a narrow import
    
    The code generators are updated accordingly:
    
    * `cgen` uses its `blocks` stack not only for `cnkBlockStmt`s, but for
      C blocks (`{}`) in general. Therefore, `TBlock` stores the  `BlockId`
      offset by 1, leaving '0' to mean "not corresponding to a
      `cnkBlockStmt`"
    * `jsgen` uses the `BlockId` as an index into the `blocks` stack, which
      is now a `seq[int]` (the previously used `TBlock` type had only a
      single field)
    * `vmgen` also uses the `BlockId` as an index into its `blocks` stack,
      making the previous search logic obsolete. The `withBlock` and
      `popBlocks` routines were only used in a single place -- they're
      inlined and removed. In addition, the `blocks` stack embeds the fixup
      list directly, removing the need for the `TBlock` type
    zerbina committed Oct 4, 2023
    Configuration menu
    Copy the full SHA
    746a49b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    78d13a1 View commit details
    Browse the repository at this point in the history