Lean2Js.Js
The AST of the JavaScript to emit, and the ESM and .d.ts printers #
The AST of the JavaScript to emit, and the ESM / .d.ts printers.
Parentheses are always written, without consulting precedence. A precedence table would go on the compiler's trusted base and buy only prettier output.
Lean2Js.Js.TyDesc
sourceA type expanded into what the generated code needs in order to check a value against it at runtime.
Ty.named is resolved away here rather than emitting a table of type definitions, so a function carries
only the shapes it actually accepts and a bundler can still drop the ones nobody imported.
Instances For
Used by
Lean2Js.Js.instInhabitedTyDesc
sourceEquations
Used by
Lean2Js.Js.instBEqTyDesc
sourceEquations
Used by
Lean2Js.Js.instBEqTyDesc.beq
sourceUsed by
Lean2Js.Js.TyAlts
sourceA declared type's constructors as the descriptor carries them: the constructor's name, and its fields in declared order.
Equations
Instances For
Used by
Lean2Js.Js.TyEnv
sourceWhat the mu nodes a walk is inside have bound, nearest first: the key a constructor's name is
carried under, and the alternatives.
A ref continues at an entry of this rather than at a descriptor read out of it, which is what keeps
the walk measured by the value: the entry is fed back as a ctors node, which descends into fields, so
no step can land on another ref.
Equations
Instances For
Used by
Lean2Js.Js.FoldKind
sourceHow a fold carries one of a constructor's fields: the declared type coming round, a list of it
coming round, or neither. It is what EncDeriving.kindOf already computes at the deriving, written
where the generated code reads it.
Instances For
Used by
Lean2Js.Js.instBEqFoldKind
sourceEquations
Used by
Lean2Js.Js.instBEqFoldKind.beq
sourceEquations
- Lean2Js.Js.instBEqFoldKind.beq x✝ y✝ = (x✝.ctorIdx == y✝.ctorIdx)
Instances For
Used by
Lean2Js.Js.instReprFoldKind.repr
sourceEquations
- Lean2Js.Js.instReprFoldKind.repr Lean2Js.Js.FoldKind.self prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Lean2Js.Js.FoldKind.self")).group prec✝
- Lean2Js.Js.instReprFoldKind.repr Lean2Js.Js.FoldKind.list prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Lean2Js.Js.FoldKind.list")).group prec✝
- Lean2Js.Js.instReprFoldKind.repr Lean2Js.Js.FoldKind.plain prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "Lean2Js.Js.FoldKind.plain")).group prec✝
Instances For
Used by
Lean2Js.Js.instReprFoldKind
sourceEquations
- Lean2Js.Js.instReprFoldKind = { reprPrec := Lean2Js.Js.instReprFoldKind.repr }
Used by
Lean2Js.Js.instInhabitedFoldKind
sourceEquations
Used by
Lean2Js.Js.instDecidableEqFoldKind
sourceEquations
Used by
Lean2Js.Js.FoldKind.render
sourceEquations
- Lean2Js.Js.FoldKind.self.render = "self"
- Lean2Js.Js.FoldKind.list.render = "list"
- Lean2Js.Js.FoldKind.plain.render = "plain"
Instances For
Used by
Lean2Js.Js.FoldFields
sourceA constructor's fields in declared order, each with the way the fold carries it.
Equations
Instances For
Used by
Lean2Js.Js.FoldSpec
sourceWhat a fold is given about a declared type: its constructors by name, each with its fields.
Apart from TyAlts, which carries the same names, because the two say different things: one is what a
value is checked against, this is which of a node's fields the walk goes into. A fold reads it at the
constructor the value carries, so a name it does not hold is a value the walk declines to answer for.
Equations
Instances For
Used by
Lean2Js.Js.renderFoldFields
sourceA constructor's fields as the generated code reads them: each field's name beside the way the fold
carries it, in declared order. Written as a recursion rather than through List.map, for the reason the
rest of the printer is: the text the artifact carries has to be something a proof can unfold.
Equations
Instances For
Used by
Lean2Js.Js.renderFoldSpec
sourceThe spec __fold reads, printed as the object it indexes by the constructor's name. Spelled { and
} the way Expr.objLit is, so that the reader tells the end of an empty one from the start of an
entry by the same one character of lookahead.
Equations
- Lean2Js.Js.renderFoldSpec [] = ""
- Lean2Js.Js.renderFoldSpec [(c, fs)] = "\"" ++ Lean2Js.escapeString c ++ "\": [" ++ Lean2Js.Js.renderFoldFields fs ++ "]"
- Lean2Js.Js.renderFoldSpec ((c, fs) :: rest) = "\"" ++ Lean2Js.escapeString c ++ "\": [" ++ Lean2Js.Js.renderFoldFields fs ++ "], " ++ Lean2Js.Js.renderFoldSpec rest
Instances For
Used by
Lean2Js.Js.TyDesc.render
sourceThe descriptor the entry check reads. Total for the reason Expr.render is: the text the artifact
carries has to be something a proof can unfold.
Equations
- Lean2Js.Js.TyDesc.bool.render = "[\"bool\"]"
- Lean2Js.Js.TyDesc.int53.render = "[\"int53\"]"
- Lean2Js.Js.TyDesc.uint32.render = "[\"uint32\"]"
- Lean2Js.Js.TyDesc.string.render = "[\"string\"]"
- Lean2Js.Js.TyDesc.bigint.render = "[\"bigint\"]"
- t.option.render = "[\"option\", " ++ t.render ++ "]"
- (ok.result err).render = "[\"result\", " ++ ok.render ++ ", " ++ err.render ++ "]"
- t.array.render = "[\"array\", " ++ t.render ++ "]"
- v.dict.render = "[\"dict\", " ++ v.render ++ "]"
- v.dictObj.render = "[\"dictObj\", " ++ v.render ++ "]"
- (Lean2Js.Js.TyDesc.ctors key alts).render = "[\"ctors\", \"" ++ Lean2Js.escapeString key ++ "\", [" ++ Lean2Js.Js.TyDesc.renderAlts alts ++ "]]"
- (Lean2Js.Js.TyDesc.mu key alts).render = "[\"mu\", \"" ++ Lean2Js.escapeString key ++ "\", [" ++ Lean2Js.Js.TyDesc.renderAlts alts ++ "]]"
- (Lean2Js.Js.TyDesc.ref up).render = "[\"ref\", " ++ Lean2Js.renderNat up ++ "]"
Instances For
Used by
Lean2Js.Js.TyDesc.renderFields
sourceEquations
Instances For
Used by
Lean2Js.Js.TyDesc.renderAlts
sourceEquations
- Lean2Js.Js.TyDesc.renderAlts [] = ""
- Lean2Js.Js.TyDesc.renderAlts [(c, fields)] = "[\"" ++ Lean2Js.escapeString c ++ "\", [" ++ Lean2Js.Js.TyDesc.renderFields fields ++ "]]"
- Lean2Js.Js.TyDesc.renderAlts ((c, fields) :: rest) = "[\"" ++ Lean2Js.escapeString c ++ "\", [" ++ Lean2Js.Js.TyDesc.renderFields fields ++ "]], " ++ Lean2Js.Js.TyDesc.renderAlts rest
Instances For
Used by
Descriptors that reach no dictionary crossing as an object #
A dictionary declared to cross as a plain object is the one node a declaration's walk out moves, so a
return type whose expanded descriptor reaches none needs no walk at all: the entry hands the body's
result straight back and is byte-for-byte what it was before a dictionary could cross as an object. A
ref says nothing on its own — it resolves against the environment — so envNoDictObj is the other
half of the reading.
Lean2Js.Js.descNoDictObj
sourceEquations
- Lean2Js.Js.descNoDictObj Lean2Js.Js.TyDesc.bool = true
- Lean2Js.Js.descNoDictObj Lean2Js.Js.TyDesc.int53 = true
- Lean2Js.Js.descNoDictObj Lean2Js.Js.TyDesc.uint32 = true
- Lean2Js.Js.descNoDictObj Lean2Js.Js.TyDesc.string = true
- Lean2Js.Js.descNoDictObj Lean2Js.Js.TyDesc.bigint = true
- Lean2Js.Js.descNoDictObj (Lean2Js.Js.TyDesc.ref up) = true
- Lean2Js.Js.descNoDictObj t.option = Lean2Js.Js.descNoDictObj t
- Lean2Js.Js.descNoDictObj t.array = Lean2Js.Js.descNoDictObj t
- Lean2Js.Js.descNoDictObj t.dict = Lean2Js.Js.descNoDictObj t
- Lean2Js.Js.descNoDictObj (ok.result err) = (Lean2Js.Js.descNoDictObj ok && Lean2Js.Js.descNoDictObj err)
- Lean2Js.Js.descNoDictObj value.dictObj = false
- Lean2Js.Js.descNoDictObj (Lean2Js.Js.TyDesc.ctors key alts) = Lean2Js.Js.altsNoDictObj alts
- Lean2Js.Js.descNoDictObj (Lean2Js.Js.TyDesc.mu key alts) = Lean2Js.Js.altsNoDictObj alts
Instances For
Used by
Lean2Js.Js.fieldsNoDictObj
sourceEquations
- Lean2Js.Js.fieldsNoDictObj [] = true
- Lean2Js.Js.fieldsNoDictObj ((fst, d) :: rest) = (Lean2Js.Js.descNoDictObj d && Lean2Js.Js.fieldsNoDictObj rest)
Instances For
Used by
Lean2Js.Js.altsNoDictObj
sourceEquations
- Lean2Js.Js.altsNoDictObj [] = true
- Lean2Js.Js.altsNoDictObj ((fst, fields) :: rest) = (Lean2Js.Js.fieldsNoDictObj fields && Lean2Js.Js.altsNoDictObj rest)
Instances For
Used by
Lean2Js.Js.envNoDictObj
sourceEquations
- Lean2Js.Js.envNoDictObj [] = true
- Lean2Js.Js.envNoDictObj ((fst, alts) :: rest) = (Lean2Js.Js.altsNoDictObj alts && Lean2Js.Js.envNoDictObj rest)
Instances For
Used by
Lean2Js.Js.renderNames
sourceA comma-separated list of names. Written as a recursion rather than String.intercalate, which walks
an accumulator and does not unfold in a proof, for the reason the rest of the printer is: the file the
compiler writes has to be something a proof can read back.
Equations
- Lean2Js.Js.renderNames [] = ""
- Lean2Js.Js.renderNames [n] = n
- Lean2Js.Js.renderNames (n :: rest) = n ++ ", " ++ Lean2Js.Js.renderNames rest
Instances For
Used by
Lean2Js.Js.Expr
sourceInstances For
Used by
Lean2Js.Js.instInhabitedExpr
sourceEquations
Used by
Lean2Js.Js.instBEqExpr
sourceEquations
Used by
Lean2Js.Js.instBEqExpr.beq
sourceUsed by
Lean2Js.Js.Stmt
sourceInstances For
Used by
Lean2Js.Js.instInhabitedStmt
sourceEquations
Used by
Lean2Js.Js.instBEqStmt.beq
sourceEquations
- Lean2Js.Js.instBEqStmt.beq (Lean2Js.Js.Stmt.const a a_1) (Lean2Js.Js.Stmt.const b b_1) = (a == b && a_1 == b_1)
- Lean2Js.Js.instBEqStmt.beq (Lean2Js.Js.Stmt.ret a) (Lean2Js.Js.Stmt.ret b) = (a == b)
- Lean2Js.Js.instBEqStmt.beq x✝¹ x✝ = false
Instances For
Used by
Lean2Js.Js.instBEqStmt
sourceEquations
Used by
Lean2Js.Js.Func
sourceInstances For
Used by
Lean2Js.Js.instInhabitedFunc
sourceEquations
Used by
Lean2Js.Js.instBEqFunc
sourceEquations
Used by
Lean2Js.Js.instBEqFunc.beq
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Js.instBEqFunc.beq x✝¹ x✝ = false
Instances For
Used by
Lean2Js.Js.Module
sourceInstances For
Used by
Lean2Js.Js.instInhabitedModule
sourceEquations
Used by
Lean2Js.Js.instBEqModule
sourceEquations
Used by
Lean2Js.Js.instBEqModule.beq
sourceEquations
- Lean2Js.Js.instBEqModule.beq { funcs := a } { funcs := b } = (a == b)
- Lean2Js.Js.instBEqModule.beq x✝¹ x✝ = false
Instances For
Used by
Lean2Js.Js.Expr.render
sourceThe text the module carries. Written as a mutual recursion over the lists rather than partial, so
a proof about the file the compiler writes can unfold it.
Equations
- One or more equations did not get rendered due to their size.
- (Lean2Js.Js.Expr.num i).render = Lean2Js.renderInt i
- (Lean2Js.Js.Expr.bigLit i).render = Lean2Js.renderInt i ++ "n"
- (Lean2Js.Js.Expr.str s).render = "\"" ++ Lean2Js.escapeString s ++ "\""
- (Lean2Js.Js.Expr.bool b).render = if b = true then "true" else "false"
- (Lean2Js.Js.Expr.ident name).render = name
- (Lean2Js.Js.Expr.unary op e).render = "(" ++ op ++ e.render ++ ")"
- (Lean2Js.Js.Expr.binary op lhs rhs).render = "(" ++ lhs.render ++ " " ++ op ++ " " ++ rhs.render ++ ")"
- (c.cond t e).render = "(" ++ c.render ++ " ? " ++ t.render ++ " : " ++ e.render ++ ")"
- (Lean2Js.Js.Expr.call callee args).render = callee ++ "(" ++ Lean2Js.Js.Expr.renderList args ++ ")"
- (Lean2Js.Js.Expr.arrowCall params body args).render = "((" ++ Lean2Js.Js.renderNames params ++ ") => (" ++ body.render ++ "))(" ++ Lean2Js.Js.Expr.renderList args ++ ")"
- (Lean2Js.Js.Expr.objLit fields).render = "{ " ++ Lean2Js.Js.Expr.renderFields fields ++ " }"
- (obj.member field).render = "(" ++ obj.render ++ ")." ++ field
- (Lean2Js.Js.Expr.arrayLit items).render = "[" ++ Lean2Js.Js.Expr.renderList items ++ "]"
- (Lean2Js.Js.Expr.dictLit entries).render = "new Map([" ++ Lean2Js.Js.Expr.renderEntries entries ++ "])"
- (Lean2Js.Js.Expr.check d e).render = "__ck(" ++ e.render ++ ", " ++ d.render ++ ")"
- (arr.mapJs binder body).render = "__map(" ++ arr.render ++ ", (" ++ binder ++ ") => (" ++ body.render ++ "))"
- (arr.filterJs binder body).render = "__filter(" ++ arr.render ++ ", (" ++ binder ++ ") => (" ++ body.render ++ "))"
- (arr.findJs binder body).render = "__find(" ++ arr.render ++ ", (" ++ binder ++ ") => (" ++ body.render ++ "))"
- (Lean2Js.Js.Expr.quantJs op arr binder body).render = "__" ++ op.name ++ "(" ++ arr.render ++ ", (" ++ binder ++ ") => (" ++ body.render ++ "))"
- (arr.reduceJs init accName elemName body).render = "__reduce(" ++ arr.render ++ ", " ++ init.render ++ ", (" ++ accName ++ ", " ++ elemName ++ ") => (" ++ body.render ++ "))"
- (arr.sortByJs binder body).render = "__sortBy(" ++ arr.render ++ ", (" ++ binder ++ ") => (" ++ body.render ++ "))"
- (Lean2Js.Js.Expr.out d e).render = "__out(" ++ e.render ++ ", " ++ d.render ++ ", [])"
Instances For
Used by
Lean2Js.Js.Expr.renderList
sourceEquations
- Lean2Js.Js.Expr.renderList [] = ""
- Lean2Js.Js.Expr.renderList [e] = e.render
- Lean2Js.Js.Expr.renderList (e :: rest) = e.render ++ ", " ++ Lean2Js.Js.Expr.renderList rest
Instances For
Used by
Lean2Js.Js.Expr.renderFields
sourceEquations
- Lean2Js.Js.Expr.renderFields [] = ""
- Lean2Js.Js.Expr.renderFields [(k, v)] = "\"" ++ Lean2Js.escapeString k ++ "\": " ++ v.render
- Lean2Js.Js.Expr.renderFields ((k, v) :: rest) = "\"" ++ Lean2Js.escapeString k ++ "\": " ++ v.render ++ ", " ++ Lean2Js.Js.Expr.renderFields rest
Instances For
Used by
Lean2Js.Js.Expr.renderEntries
sourceEquations
Instances For
Used by
Lean2Js.Js.Stmt.render
sourceEquations
Instances For
Used by
Lean2Js.Js.Stmt.renderAll
sourceEquations
- Lean2Js.Js.Stmt.renderAll [] = ""
- Lean2Js.Js.Stmt.renderAll [s] = s.render
- Lean2Js.Js.Stmt.renderAll (s :: rest) = s.render ++ "\n" ++ Lean2Js.Js.Stmt.renderAll rest
Instances For
Used by
Lean2Js.Js.Func.render
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Js.runtime
sourceThe runtime helpers the generated code calls, printed from Helper.defs.
Equations
Instances For
Used by
Lean2Js.Js.Func.renderAll
sourceEquations
- Lean2Js.Js.Func.renderAll [] = ""
- Lean2Js.Js.Func.renderAll (f :: rest) = f.render ++ "\n\n" ++ Lean2Js.Js.Func.renderAll rest
Instances For
Used by
Lean2Js.Js.preambleComment
sourceNamed apart from the preamble, and the preamble associated to the right, so a proof can read the length of what the file opens with without unfolding the runtime behind it.
Equations
- Lean2Js.Js.preambleComment = "// Generated by lean2js. Do not edit.\n\n"
Instances For
Used by
Lean2Js.Js.preamble
sourceNamed rather than spelled out at the use site: a proof about the file has to unfold the printer around them, and the runtime is four thousand characters the elaborator would otherwise carry.
Equations
Instances For
Used by
Lean2Js.Js.Module.render
sourceThe text of the file the compiler writes.
Equations
Instances For
Used by
Lean2Js.Js.tsType
sourceThe type the .d.ts gives a value of this type. Total for the reason the renderers are: the file the
compiler writes has to be something a proof can unfold.
Equations
- Lean2Js.Js.tsType Lean2Js.Core.Ty.bool = "boolean"
- Lean2Js.Js.tsType Lean2Js.Core.Ty.int53 = "number"
- Lean2Js.Js.tsType Lean2Js.Core.Ty.uint32 = "number"
- Lean2Js.Js.tsType Lean2Js.Core.Ty.string = "string"
- Lean2Js.Js.tsType Lean2Js.Core.Ty.bigint = "bigint"
- Lean2Js.Js.tsType (Lean2Js.Core.Ty.var n) = n
- Lean2Js.Js.tsType (Lean2Js.Core.Ty.named n []) = n
- Lean2Js.Js.tsType (Lean2Js.Core.Ty.named n args) = n ++ "<" ++ Lean2Js.Js.tsTypeList args ++ ">"
- Lean2Js.Js.tsType t.option = "Option<" ++ Lean2Js.Js.tsType t ++ ">"
- Lean2Js.Js.tsType (ok.result err) = "Result<" ++ Lean2Js.Js.tsType ok ++ ", " ++ Lean2Js.Js.tsType err ++ ">"
- Lean2Js.Js.tsType t.array = "readonly " ++ Lean2Js.Js.parenElem✝ t (Lean2Js.Js.tsType t) ++ "[]"
- Lean2Js.Js.tsType v.dict = "ReadonlyMap<string, " ++ Lean2Js.Js.tsType v ++ ">"
- Lean2Js.Js.tsType v.dictObj = "ReadonlyMap<string, " ++ Lean2Js.Js.tsType v ++ "> | { readonly [key: string]: " ++ Lean2Js.Js.tsType v ++ " }"
- Lean2Js.Js.tsType (Lean2Js.Core.Ty.fn params ret) = "(" ++ Lean2Js.Js.tsParams 0 params ++ ") => " ++ Lean2Js.Js.tsType ret
Instances For
Used by
Lean2Js.Js.tsTypeList
sourceEquations
- Lean2Js.Js.tsTypeList [] = ""
- Lean2Js.Js.tsTypeList [t] = Lean2Js.Js.tsType t
- Lean2Js.Js.tsTypeList (t :: rest) = Lean2Js.Js.tsType t ++ ", " ++ Lean2Js.Js.tsTypeList rest
Instances For
Used by
Lean2Js.Js.tsParams
sourceEquations
- Lean2Js.Js.tsParams i [] = ""
- Lean2Js.Js.tsParams i [t] = toString "a" ++ toString i ++ toString ": " ++ toString (Lean2Js.Js.tsType t)
- Lean2Js.Js.tsParams i (t :: rest) = toString "a" ++ toString i ++ toString ": " ++ toString (Lean2Js.Js.tsType t) ++ toString ", " ++ Lean2Js.Js.tsParams (i + 1) rest
Instances For
Used by
Lean2Js.Js.tsTypeOut
sourceThe type the .d.ts gives a value of this type where it is being handed back. A Dict.Obj V
parameter is printed as the union above because the entry takes either spelling; a Dict.Obj V return
is the plain object alone, because the entry walked it out to one and nothing else can come back.
Stops at a declared type: one interface is printed for both directions, so a Dict.Obj field there
keeps the union.
Equations
- Lean2Js.Js.tsTypeOut t.option = "Option<" ++ Lean2Js.Js.tsTypeOut t ++ ">"
- Lean2Js.Js.tsTypeOut (ok.result err) = "Result<" ++ Lean2Js.Js.tsTypeOut ok ++ ", " ++ Lean2Js.Js.tsTypeOut err ++ ">"
- Lean2Js.Js.tsTypeOut t.array = "readonly " ++ Lean2Js.Js.parenElem✝ t (Lean2Js.Js.tsTypeOut t) ++ "[]"
- Lean2Js.Js.tsTypeOut v.dict = "ReadonlyMap<string, " ++ Lean2Js.Js.tsTypeOut v ++ ">"
- Lean2Js.Js.tsTypeOut v.dictObj = "{ readonly [key: string]: " ++ Lean2Js.Js.tsTypeOut v ++ " }"
- Lean2Js.Js.tsTypeOut x✝ = Lean2Js.Js.tsType x✝
Instances For
Used by
Lean2Js.Js.declareFunc
sourceThe .d.ts is the only thing a consumer reads before calling, so it carries what the author wrote
about the function and the one fact the types cannot say: the call throws rather than returning a value
the semantics would not stand behind.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Js.renderDts
sourceOnly the types a consumer can name. A declaration that takes a function does not cross the boundary,
and neither does a type that only ever holds an intermediate value -- an accumulator a foldl carries
appears in no public signature, and printing it would invite a consumer to build one.