HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Moduleghc-10.0.0.20260917GHC2024

GHC.JS.Syntax

  • Domain and Purpose

    GHC.JS.Syntax defines the Syntax for the JS backend in GHC. It comports with the ECMA-262 although not every production rule of the standard is represented. Code in this module is a fork of JMacro (BSD 3 Clause) by Gershom Bazerman, heavily modified to accomodate GHC's constraints.

  • Strategy

    Nothing fancy in this module, this is a classic deeply embedded AST for JS. We define numerous ADTs and pattern synonyms to make pattern matching and constructing ASTs easier.

  • Consumers

    The entire JS backend consumes this module, e.g., the modules in GHC.StgToJS.*. Please see GHC.JS.Make for a module which provides helper functions that use the deeply embedded DSL defined in this module to provide some of the benefits of a shallow embedding.

Contents
  1. Deeply embedded JS datatypes
  2. pattern synonyms over JS operators
  3. Utility
Synopsis

Deeply embedded JS datatypes

datadata JStat

JavaScript statements, see the ECMA262 Reference for details

Constructors

Instances8Eq, Generic, Semigroup, Monoid, Binary, JsToDoc, …
datadata JExpr

JavaScript Expressions

Constructors

Instances7Eq, Generic, Outputable, Binary, JsToDoc, Rep, …
datadata JVal

JavaScript values

Constructors

Instances6Eq, Generic, Outputable, Binary, JsToDoc, Rep
datadata Op

JS Binary Operators. We do not deeply embed the comma operator and the assignment operators

Constructors

Instances9Enum, Eq, Data, Ord, Show, Generic, …
datadata UOp

JS Unary Operators

Constructors

Instances9Enum, Eq, Data, Ord, Show, Generic, …
datadata AOp

JS Unary Operators

Constructors

Instances9Enum, Eq, Data, Ord, Show, Generic, …
newtypenewtype Ident

A newtype wrapper around FastString for JS identifiers.

Constructors

Instances8Eq, Show, Outputable, Uniquable, Binary, JVarMagic, …
  • Eq IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Ident
  • Show IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Ident
  • Outputable IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Ident
  • Uniquable IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Ident
  • Binary IdentDefined in ghc-10.0.0.20260917 · GHC.StgToJS.Object · orphan
  • JVarMagic IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Make
  • ToJExpr IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Make
  • JsToDoc IdentDefined in ghc-10.0.0.20260917 · GHC.JS.Ppr

pattern synonyms over JS operators

patternpattern Var :: Ident -> JExpr

pattern synonym to create a local variable reference

Utility

newtypenewtype SaneDouble

A newtype wrapper around Double to ensure we never generate a Double that becomes a NaN, see instances for details on sanity.

Instances6Eq, Fractional, Num, Ord, Show, Binary