rewire-frontend-2.8: A Haskell-to-Verilog/VHDL compiler, front end (GHC driver, Eidos, Synolon)
Safe HaskellSafe
LanguageHaskell2010

ReWire.Eidos.Pretty

Description

The Eidos concrete syntax (.eir) pretty-printer, implementing doc/eidos.md §9. ReWire.Eidos.Parse is the other half of the round-trip contract: parse . pretty is the identity on programs modulo annotations (annotations are semantically inert and never printed), and pretty . parse . pretty == pretty is a tested fixpoint.

Conventions (§9): term names, type variables, and labels print with their uniques (x#12, Main.loop#3, a#7); type and data constructor names print bare (Main.CPUState, Vec); primitives print by their builtin name (rwPrimBind) — the rwPrim prefix and absence of # distinguishes them lexically from constructors and variables. Binders print (occ#uniq :: ty) (the case binder, whose type is the scrutinee's, prints bare); Con, Prim, and integer-literal occurrences print in the parenthesized-ascription form (name :: ty); type arguments print @tyatom. The default case alternative, when present, is first in the AST (the Core convention) and prints first, as _ -> e.

Nothing in this module introduces a soft line break: layout is fixed by vsep alone, so signatures (and every type) always print on one line — the defn production's newline between the signature line and the equation line is what terminates the signature's type.

The machine level's process declarations print through ReWire.Synolon.Pretty, which reuses these printers for the expressions, definitions, and datatypes a Synolon program embeds.

Synopsis

Documentation

prettyProgram :: Program -> Text Source #

Render a whole program in the .eir concrete syntax.

ppProgram :: Program -> Doc an Source #

A whole program: datatypes, definitions, and the top designation, separated by blank lines.

ppDataDefn :: DataDefn -> Doc an Source #

data T kind { C1 :: sig1; ... }.

ppDefn :: Defn -> Doc an Source #

A definition: the signature line, then the equation line (attributes, name, parameter telescope) with the body on a continuation line.

ppExp :: Exp -> Doc an Source #

Expression at top level: lambda, let, case, and jump live here; all are parenthesized down at atom level.

ppBind :: Bind -> Doc an Source #

A local binding (the part between let and in).

ppAlt :: Alt -> Doc an Source #

A case alternative. Default and literal alternatives bind no fields (the grammar has no slot for them; the linter enforces emptiness).

ppTy :: Ty -> Doc an Source #

Type, at top (arrow) level: arrows are right-associative and bind loosest; application binds tighter.

ppSig :: Sig -> Doc an Source #

A signature: forall (a#1 :: kind) ... . ty, or bare ty when the quantifier list is empty.

ppKind :: Kind -> Doc an Source #

Kind, at top (arrow) level: arrows are right-associative.

ppId :: Id -> Doc an Source #

A term name occurrence: x#12 (the type is read off the binder).

ppTyVar :: TyVar -> Doc an Source #

A type variable occurrence: a#7.

ppBinder :: Id -> Doc an Source #

A term binder: (occ#uniq :: ty). Local binders are monomorphic (doc/eidos.md §3.2), so only the signature's type is printed.

ppName :: Text -> Uniq -> Doc an Source #

A unique-carrying name occurrence: occ#uniq. Occurrence text that does not lex as an identifier (operator names, reserved words) prints backtick-quoted: &&#5.

ppOcc :: Text -> Doc an Source #

Occurrence text, backtick-quoted unless it lexes as an identifier (the lexer's own predicate and reserved-word table decide).

ppOcc' :: Text -> Doc an Source #

Like ppOcc, but the tuple, unit, and list constructor names print bare (they have their own lexemes in the grammar).

ppAtom :: Exp -> Doc an Source #

Expression at atom level. Con, Prim, integer, list, and vector literals are self-parenthesizing ascription forms; variables and string literals print bare; everything else parenthesizes.

Orphan instances

Pretty Alt Source # 
Instance details

Methods

pretty :: Alt -> Doc ann #

prettyList :: [Alt] -> Doc ann

Pretty Arg Source # 
Instance details

Methods

pretty :: Arg -> Doc ann #

prettyList :: [Arg] -> Doc ann

Pretty Bind Source # 
Instance details

Methods

pretty :: Bind -> Doc ann #

prettyList :: [Bind] -> Doc ann

Pretty DataCon Source # 
Instance details

Methods

pretty :: DataCon -> Doc ann #

prettyList :: [DataCon] -> Doc ann

Pretty DataDefn Source # 
Instance details

Methods

pretty :: DataDefn -> Doc ann #

prettyList :: [DataDefn] -> Doc ann

Pretty Defn Source # 
Instance details

Methods

pretty :: Defn -> Doc ann #

prettyList :: [Defn] -> Doc ann

Pretty Exp Source # 
Instance details

Methods

pretty :: Exp -> Doc ann #

prettyList :: [Exp] -> Doc ann

Pretty Id Source # 
Instance details

Methods

pretty :: Id -> Doc ann #

prettyList :: [Id] -> Doc ann

Pretty Kind Source # 
Instance details

Methods

pretty :: Kind -> Doc ann #

prettyList :: [Kind] -> Doc ann

Pretty Program Source # 
Instance details

Methods

pretty :: Program -> Doc ann #

prettyList :: [Program] -> Doc ann

Pretty Sig Source # 
Instance details

Methods

pretty :: Sig -> Doc ann #

prettyList :: [Sig] -> Doc ann

Pretty Ty Source # 
Instance details

Methods

pretty :: Ty -> Doc ann #

prettyList :: [Ty] -> Doc ann

Pretty TyVar Source # 
Instance details

Methods

pretty :: TyVar -> Doc ann #

prettyList :: [TyVar] -> Doc ann