GHC.StgToJS.Ids

ghc-9.10.0.20240426: The GHC API

Copyright | (c) The University of Glasgow 2001
License | BSD-style (see the file LICENSE)
Maintainer | Jeffrey Young <jeffrey.young@iohk.io> Luite Stegeman <luite.stegeman@iohk.io> Sylvain Henry <sylvain.henry@iohk.io> Josh Meredith <josh.meredith@iohk.io>
Stability | experimental Module to deal with JS identifiers
Safe Haskell | None
Language | GHC2021

GHC.StgToJS.Ids

Contents

- Helpers for Idents
- Helpers for variables

Description

Synopsis

- freshUnique :: G Int
- freshIdent :: G Ident
- makeIdentForId :: Id -> Maybe Int -> IdType -> Module -> Ident
- cachedIdentForId :: Id -> Maybe Int -> IdType -> G Ident
- identForId :: Id -> G Ident
- identForIdN :: Id -> Int -> G Ident
- identsForId :: Id -> G [Ident]
- identForEntryId :: Id -> G Ident
- identForDataConEntryId :: Id -> G Ident
- identForDataConWorker :: DataCon -> G Ident
- varForId :: Id -> G JStgExpr
- varForIdN :: Id -> Int -> G JStgExpr
- varsForId :: Id -> G [JStgExpr]
- varForEntryId :: Id -> G JStgExpr
- varForDataConEntryId :: Id -> G JStgExpr
- varForDataConWorker :: DataCon -> G JStgExpr
- declVarsForId :: Id -> G JStgStat

# Documentation

freshUnique :: G Int Source #

Get fresh unique number

freshIdent :: G Ident Source #

Get fresh module-local Ident of the form: h$$unit:module_uniq

makeIdentForId :: Id -> Maybe Int -> IdType -> Module -> Ident Source #

Generate unique Ident for the given ID (uncached!)

The ident has the following forms:

global Id: h$unit:module.name[_num][_type_suffix] local Id: h$$unit:module.name[_num][_type_suffix]_uniq

Note that the string is z-encoded except for "_" delimiters.

Optional "_type_suffix" can be: - "_e" for IdEntry - "_con_e" for IdConEntry

Optional "_num" is passed as an argument to this function. It is used for Haskell Ids that require several JS variables: e.g. 64-bit numbers (Word64#, Int64#), Addr#, StablePtr#, unboxed tuples, etc.

cachedIdentForId :: Id -> Maybe Int -> IdType -> G Ident Source #

Retrieve the cached Ident for the given Id if there is one. Otherwise make a new one with `makeIdentForId` and cache it.

# Helpers for Idents

identForId :: Id -> G Ident Source #

Retrieve default Ident for the given Id

identForIdN :: Id -> Int -> G Ident Source #

Retrieve default Ident for the given Id with sub index

Some types, Word64, Addr#, unboxed tuple have more than one corresponding JS var, hence we use the sub index to identify each subpart / JS variable.

identsForId :: Id -> G [Ident] Source #

Retrieve all the idents for the given Id.

identForEntryId :: Id -> G Ident Source #

Retrieve entry Ident for the given Id

identForDataConEntryId :: Id -> G Ident Source #

Retrieve datacon entry Ident for the given Id

Different name than the datacon wrapper.

identForDataConWorker :: DataCon -> G Ident Source #

Retrieve datacon worker entry variable name for the given datacon

# Helpers for variables

varForId :: Id -> G JStgExpr Source #

Retrieve default variable name for the given Id

varForIdN :: Id -> Int -> G JStgExpr Source #

Retrieve default variable name for the given Id with sub index

varsForId :: Id -> G [JStgExpr] Source #

Retrieve all the JS vars for the given Id

varForEntryId :: Id -> G JStgExpr Source #

Retrieve entry variable name for the given Id

varForDataConEntryId :: Id -> G JStgExpr Source #

Retrieve datacon entry variable name for the given Id

varForDataConWorker :: DataCon -> G JStgExpr Source #

Retrieve datacon worker entry variable name for the given datacon

declVarsForId :: Id -> G JStgStat Source #

Declare all js vars for the id