GHC.JS.JStg.Monad

ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

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
Safe Haskell | Ignore
Language | GHC2021

GHC.JS.JStg.Monad

Description

- Domain and Purpose

  GHC.JS.JStg.Monad defines the computational environment for the eDSL that we use to write the JS Backend's RTS. Its purpose is to ensure unique identifiers are generated throughout the backend and that we can use the host language to ensure references are not mixed.

- Strategy

  The monad is a straightforward state monad which holds an environment holds a pointer to a prefix to tag identifiers with and an infinite stream of identifiers.

- Usage

  One should almost never need to directly use the functions in this module. Instead one should opt to use the combinators in `Make`, the sole exception to this is the `withTag` function which is used to change the prefix of identifiers for a given computation. For example, the rts uses this function to tag all identifiers generated by the RTS code as RTS_N, where N is some unique.

Synopsis

- runJSM :: JEnv -> JSM a -> a
- type JSM a = State JEnv a
- withTag :: FastString -> JSM a -> JSM a
- newIdent :: JSM Ident
- initJSM :: IO JEnv

# Documentation

runJSM :: JEnv -> JSM a -> a #

type JSM a = State JEnv a #

withTag #

Arguments

:: FastString | new name to tag with
-> JSM a | action to run with new tags
-> JSM a | result

tag the name generater with a prefix for the monadic action.

newIdent :: JSM Ident #

generate a fresh Ident

initJSM :: IO JEnv #