extras : AlgId → Option AlgReading page · generated from lean/Ecma/Implements.lean, lean/Ecma/Machine/Run.lean, lean/Ecma/State.lean
What it is to implement the specification
The downstream Lean conformance contract (§2) that bridges the compiled SpecTec specification to the concrete engine, together with the observable state, configuration and §5.2 identifier types in its transitive closure. What is proved reads it field by field.
What it is to implement the specification
From lean/Ecma/Implements.lean
An implementation has values (a Model), a host (a Host), algorithms of its own beside the specification's, and its own transition between the machine's configurations. It implements the specification (Implements) when its values obey the model's laws, its host obeys the host's laws, and each transition it takes from a configuration the specification's machine reaches is some transitions of that machine. Its every run is then a run of the specification's machine.
Both machines run under whether Asserts are checked.
Spec.program
Implements.lean:32The specification's program, with an implementation's own algorithms extras where the specification defines none (sec-conformance: an implementation "may provide additional types, values, objects, properties, and functions beyond those described in this specification").
def Spec.program (extras : AlgId → Option Alg) : Prog' := Prog'.of (Spec.src.expanded extras)Implementation
Implements.lean:37An implementation over the model M (§2, sec-conformance; §4.2, sec-hosts-and-implementations): its own algorithms, its host, and its transition under whether Asserts are checked. A transition may take many of the specification's steps at once, or compute one differently.
structure Implementation (M : Model) whereImplementation.spec
Implements.lean:44The specification's machine for I (§5.2, sec-algorithm-conventions): the specification's program with I's algorithms, and I's host.
def Implementation.spec (I : Implementation M) (chk : Bool) : Ctx M := Ctx.spec (Spec.program I.extras) I.host chk
Reached
Implements.lean:51The configurations the machine X reaches (§5.2, sec-algorithm-conventions; §9.4, sec-execution-contexts; §9.5, sec-jobs): from a call in a state with no suspended execution context, by its transitions, and by a further call from the state a run ended in, whatever else of that state the host changed meanwhile (its suspended execution contexts it may not).
inductive Reached (X : Ctx M) : Cfg M → Prop whereImplements
Implements.lean:65I implements the specification (§2, sec-conformance; §4.2, sec-hosts-and-implementations; §5.2, sec-algorithm-conventions).
structure Implements (I : Implementation M) : Prop whereits values are the specification's: the model's laws (§6, sec-ecmascript-data-types-and-values)
model : Model.Laws M ∧ Model.UnicodeLaws M ∧ Model.ParentLaws Mits host meets every requirement the specification makes of a host (§4.2, sec-hosts-and-implementations)
host : Host.WF I.hosteach transition it takes from a configuration the specification's machine reaches is some transitions of that machine, and where it ends, that machine's run ends so; or it gives up at a limit of its own (§2, sec-conformance; §5.2, sec-algorithm-conventions)
step : ∀ chk c, Reached (I.spec chk) c → match I.step chk c with | .inl c' => Steps (I.spec chk) c c' | .inr f => Runs (I.spec chk) c f ∨ f = .stop .implLimit
Runs
From lean/Ecma/Machine/Run.lean
What it is for the specification's algorithms to run, over any model and host: a relation between configurations, with no bound. Step is one transition of the machine (step), Steps any number of them, and Runs a run that ends. Calls is a call's run from a state to its result. The specification's own context (Ctx.spec) has the program's code, the host, and whether Asserts are checked.
What it is for an implementation to be the specification's is stated over these (Ecma.Implements).
Machine.Ctx.spec
Run.lean:25The specification's context (§4.2, sec-hosts-and-implementations; §5.2, sec-algorithm-conventions): the program's code, the host, and whether Asserts are checked.
def Ctx.spec (prog : Prog') (H : Host M) (chk : Bool) : Ctx M := { prog, H, chk }
Machine.Step
Run.lean:29One transition (§5.2, sec-algorithm-conventions).
def Step (X : Ctx M) (c c' : Cfg M) : Prop := step X c = .inl c'Machine.Ends
Run.lean:32The machine ends at c, with f (§5.2, sec-algorithm-conventions).
def Ends (X : Ctx M) (c : Cfg M) (f : Final M) : Prop := step X c = .inr fMachine.Steps
Run.lean:35Any number of transitions (§5.2, sec-algorithm-conventions).
inductive Steps (X : Ctx M) : Cfg M → Cfg M → Prop whereMachine.Runs
Run.lean:40A run from c that ends with f (§5.2, sec-algorithm-conventions).
def Runs (X : Ctx M) (c : Cfg M) (f : Final M) : Prop := ∃ c', Steps X c c' ∧ Ends X c' fObservable state and step monad
From lean/Ecma/State.lean
The observable state (State), a leaf operation's result and monad (Res, Run), what a leaf operation reads (LeafCtx), environments, and the operations on values that the machine and its primitives share.
State
State.lean:26The observable state across algorithm steps (§5.2, sec-algorithm-conventions): the store of objects, Records, Lists and Environment Records (§6.1.7, sec-object-type; §9.1, sec-environment-records), the execution context stack and suspended evaluations (§9.4, sec-execution-contexts), the surrounding agent (§9.6, sec-agents), and the parser, host-call and object-shape histories over which the specification's invariants and host laws (§9.5, sec-jobs; §14.7.5.9, sec-enumerate-object-properties) are stated.
structure State whereheap : M.Heap (Cell M)the execution context stack, the running execution context last
stack : M.Seq (Val M)the Completion Record with which the running computation was last resumed
resumed : Val Mthe execution context whose evaluation a transfer suspends: the running one before the execution context stack last changed
suspended : Val M := .absentthe surrounding agent's Agent Record (§9.7)
agent : Val Mparser invocations so far
parses : Nat := 0the parser invocations of source text that is strict mode code from outside (§11.2.2)
strictParses : List Nat := []the parser invocations for ParseJSON (§25.5.1)
jsonParses : List Nat := []the parser invocations of eval code processed by a direct eval (§19.2.1.1)
directParses : List Nat := []the parser invocations with the goal symbol Module, and the reparses within them (B.1.1)
moduleParses : List Nat := []the root Parse Node of each parser invocation that gave one, by its stamp
roots : Std.ExtTreeMap Nat M.Node := ∅each cover's reparse (§5.1.5), by its invocation: the covering Parse Node it was a reparse of
covers : List (Nat × M.Node) := []each cover's reparse that gave a Parse Node (§5.1.5): the covering node, the covered nonterminal, the root
covered : List (M.Node × NtId × M.Node) := []Symbols created so far
syms : Nat := 0the agent cluster's store of WaiterList Records: each Record by its Shared Data Block and byte offset
waiterLists : List (M.Addr × M.Math × M.Addr) := []the WaiterList Records whose critical section the surrounding agent is in
critical : List M.Addr := []the Shared Data Blocks: the byte Lists of the store that are shared
shared : List M.Addr := []the Parse Nodes whose SDOs are running (Early Errors aside), innermost first
evalNodes : List M.Node := []the steps that replace a Parse Node's Evaluation (B.3.2), by the node, the latest first
evalSteps : List (M.Node × Val M) := []the arguments Lists the running built-in function calls were passed, innermost first
passed : List (Val M) := []the host's calls so far, the latest first; the position of a call counts from the first
hostLog : List (HostCall M) := []the shape changes of objects so far, the latest first (EnumerateObjectProperties ¶3)
shapeLog : List (ShapeChange M) := []the frames of each suspended execution context (its code evaluation state, §9.4), the latest first
frames : List (M.Addr × List (Machine.Frame M)) := []Res
State.lean:77The result of a step computation (§5.2, sec-algorithm-conventions): a normal value with the updated state, an abrupt completion escaping the algorithm (§6.2.4, sec-completion-record-specification-type), or a machine stop (Stop).
inductive Res (α : Type) whereAuxiliary definition: Run
Run
State.lean:84The state-and-completion monad of leaf and host operations (§5.2, sec-algorithm-conventions).
def Run (α : Type) : Type := State M → Res M αShapeChange.stamp
State.lean:88The number of host calls before a shape change (§14.7.5.9, sec-enumerate-object-properties).
abbrev ShapeChange.stamp {M : Model} (c : ShapeChange M) : Nat := c.before.lengthAuxiliary definitions (6): State.suspendedHolds, Run.Res.bind, Run.bind, Run.stop, …
State.suspendedHolds
State.lean:108Values held by the suspended evaluation ([[CodeEvaluationState]], §9.4, sec-execution-contexts) of the execution context at ctx, which remain live while ctx is reachable (§9.9.2, sec-liveness).
def State.suspendedHolds {M : Model} (s : State M) (ctx : M.Addr) (v : Val M) : Prop := ∃ frs, (ctx, frs) ∈ s.frames ∧ ∃ fr ∈ frs, fr.Holds v
Run.Res.bind
State.lean:116Sequencing; a transfer carries the rest of the computation with it.
def Res.bind : Res M α → (α → State M → Res M β) → Res M β | .ok a s, f => f a s | .esc c s, _ => .esc c s | .stop r, _ => .stop r
Run.bind
State.lean:122Monadic sequencing of Run computations (§5.2, sec-algorithm-conventions).
@[inline] def bind (m : Run M α) (f : α → Run M β) : Run M β := fun s => Res.bind (m s) fRun.stop
State.lean:124Stop the computation with reason r (§5.2, sec-algorithm-conventions).
@[inline] def stop (r : Stop) : Run M α := fun _ => .stop rRun.Res.boundary
State.lean:135The algorithm boundary (§5.2, sec-algorithm-conventions; §6.2.4, sec-completion-record-specification-type): an escaping completion becomes the return value.
def Res.boundary : Res M (Val M) → Res M (Val M) | .esc c s => .ok c s | r => r
Run.boundary
State.lean:141Run m at an algorithm boundary (§6.2.4, sec-completion-record-specification-type): an escaping completion becomes the return value.
@[inline] def boundary (m : Run M (Val M)) : Run M (Val M) := fun s => Res.boundary (m s)Environments: one value per slot, as nested pairs.
Auxiliary definitions (2): HostCall.schedulesJob, HostCall.takes
HostCall.schedulesJob
State.lean:194A logged call schedules a Job (§9.5): a hook whose first argument is an Abstract Closure, as HostEnqueueGenericJob's, HostEnqueuePromiseJob's and HostEnqueueTimeoutJob's are (a cleanup job's is its FinalizationRegistry).
def HostCall.schedulesJob : HostCall M → Bool | .hook _ (.clo .. :: _) _ _ _ => true | _ => false
HostCall.takes
State.lean:200A logged call takes the job scheduled at log position k to run: the job loop's next, or an agent's AgentNextJob.
def HostCall.takes (k : Nat) : HostCall M → Bool | .next (some j) _ => j == k | .choice q _ (.math j) => q == Known.pAgentNextJob && M.eq j (M.ofNat k) | _ => false
The store.
Auxiliary definition: alloc
alloc
State.lean:242Allocate a fresh cell in the store (§6.1.7, sec-object-type; §6.2.2, sec-list-and-record-specification-type).
def alloc (c : Cell M) : Run M M.Addr := fun s => let (a, h) := M.heapAlloc s.heap c .ok a { s with heap := h }
Values.
Auxiliary definitions (2): Val.same, listOf
Val.same
State.lean:346"x is y": the same value.
Lean, 40 lines
def Val.same : Val M → Val M → Bool | .undefined, .undefined => true | .null, .null => true | .bool a, .bool b => a == b | .str a, .str b => M.strEq a b | .sym a, .sym b => M.symEq a b | .num a, .num b => match M.numView a, M.numView b with | .nan, .nan => true | .posInf, .posInf => true | .negInf, .negInf => true | .posZero, .posZero => true | .negZero, .negZero => true | .finite x, .finite y => M.eq x y | _, _ => false | .big a, .big b => M.eq (M.bigVal a) (M.bigVal b) | .obj a, .obj b => M.addrEq a b | .ref a, .ref b => M.addrEq a b | .comp t v g, .comp u w h => t == u && Val.same v w && Val.same g h | .math a, .math b => M.eq a b | .posInf, .posInf => true | .negInf, .negInf => true | .enum a, .enum b => a == b | .field a, .field b => a == b | .nt a as, .nt b bs => a == b && as == bs | .param a, .param b => a == b | .prod a, .prod b => a == b | .node a, .node b => M.nodeEq a b | .leaf a i _, .leaf b j _ => M.nodeStamp a == M.nodeStamp b && M.nodeSpan a == M.nodeSpan b && M.nodeNt a == M.nodeNt b && i == j | .term a, .term b => a == b | .node n, .prod ps => ps.contains (M.nodeProd n) | .prod ps, .node n => ps.contains (M.nodeProd n) | .absent, .absent => true | .missing, .missing => true | .clause a, .clause b => a == b | .alg a, .alg b => a == b | .sort a, .sort b => a == b | .table a, .table b => a == b | .choice a, .choice b => a == b | _, _ => false
listOf
State.lean:554Allocate a new 0-indexed List value holding vs (§6.2.2, sec-list-and-record-specification-type).
def listOf (vs : List (Val M)) : Run M (Val M) := do return .ref (← alloc (.list (vs.foldl M.seqPush M.seqNil) 0))
Configurations and calls
From lean/Ecma/Machine/Config.lean
The machine's state: a frame per call, its kind, Parse Node, slots, step path and continuations. The continuations are generic: a code sequence's rest (seq), an operand list and its use (args, the use a Fin), a short circuit's rest (junct), a List's elements under a type (all), a subject's binding (bind, read by Op.bound), a scoped call's return (scope), a loop's body and test (loop, test) and a table step's key test (tstep). A loop runs one control point (Phase) at a time: its iterator's state (IterSt) and rounds in a Loop. Every leaf operation runs the one leaf table (leaf) over the dispatch (subD).
Machine.Ctx
Config.lean:25What the machine runs (§4.2, sec-hosts-and-implementations; §5.2, sec-algorithm-conventions): the program's code, the host, and whether Asserts are checked.
structure Ctx (M : Model) whereMachine.Call
Config.lean:37A call the machine makes, with its argument values (§5.2.2, sec-algorithm-conventions-abstract-operations; §5.2.3, sec-algorithm-conventions-syntax-directed-operations; §6.1.7, sec-object-type; §6.2.8, sec-abstract-closure; §9.5, sec-jobs): an algorithm, an SDO at a Parse Node, a closure, an internal method, a primitive, a sort's test, a table step, the early errors, a cover test or the host's Jobs.
inductive Call (M : Model) where| alg (a : AlgId) (vs : List (Val M))| sdo (s : SdoId) (nd : M.Node) (vs : List (Val M))| clo (site : CloSite) (caps vs : List (Val M))| cmethod (m : MethodId) (r : Val M) (vs : List (Val M))| callAt (a : AlgId) (nd : M.Node) (vs : List (Val M))| prim (q : PrimId) (vs : List (Val M))| sort (s : SortId) (v : Val M)| tstep (a : AlgId) (nd : Option M.Node) (t : TableId) (key : Val M) (env : List (Val M))the early errors of the rules of ps at nd (tree: of nd and its descendants), a tuple
| early (tree : Bool) (ps : List ProdId) (nd : M.Node)the early errors of rule row i of production prod at nd, a tuple
| earlyRow (prod : ProdId) (i : Nat) (nd : M.Node)whether a rule of nd's production says its child c must cover a nonterminal
| covered (nd : M.Node) (c : Val M)the host's Jobs (§9.5), until it has none or one completes abruptly; clear: ClearKeptObjects
| jobs (clear : Option AlgId)Machine.Cfg
Config.lean:91A configuration (§5.2, sec-algorithm-conventions; §9.4, sec-execution-contexts): the state, the frames (innermost first) and the control. The frame stacks of the execution contexts a transfer suspended are the state's (State.frames).
structure Cfg (M : Model) whereMachine.Final
Config.lean:97How a run ends (§5.2, sec-algorithm-conventions; §6.2.4, sec-completion-record-specification-type).
inductive Final (M : Model) whereMachine.Out
Config.lean:104A step's result (§5.2, sec-algorithm-conventions): the next configuration, or the run's end.
abbrev Out (M : Model) := Cfg M ⊕ Final MAuxiliary definition: Machine.start
Machine.start
Config.lean:107A run of call from state s (§5.2, sec-algorithm-conventions).
def start (s : State M) (call : Call M) : Cfg M := { s := s, frames := [], ctl := .invoke call }Algorithm notation and specification identifiers (§5.2)
From lean/Ecma/Notation/Syntax.lean
A concrete syntax tree of spec.html's algorithm notation (§5.2), with semantic node kinds. lean/SpecTec emits it; Print prints it back byte for byte. Surface variants (Article, AltForm, …) are kept for printing and are ignored by the machine. Names are interned: every reference is a Nat into the declaration tables (Decls), except prose, string literals and attributes.
The tree is untyped and first-order. Sorts are checked separately against the parsed headers; the machine stops with a sort error on ill-sorted data.
Slot
Syntax.lean:23An algorithm-local variable (§5.2, sec-algorithm-conventions): an index into Alg.vars.
abbrev Slot := NatFieldId
Syntax.lean:26A record field, internal slot or method, or execution-context component (§6.1.7, sec-object-type; §6.2.2, sec-list-and-record-specification-type; §9.4, sec-execution-contexts): [[F]].
abbrev FieldId := NatEnumId
Syntax.lean:28An enum constant (§5.2, sec-algorithm-conventions): ~normal~.
abbrev EnumId := NatIntrinsicId
Syntax.lean:31A well-known intrinsic (§6.1.7.4, sec-well-known-intrinsic-objects), %Array.prototype%: interned as a field name of a Realm's [[Intrinsics]].
abbrev IntrinsicId := FieldIdSdoId
Syntax.lean:33A syntax-directed operation (§5.2.3, sec-algorithm-conventions-syntax-directed-operations), by name.
abbrev SdoId := NatProdId
Syntax.lean:35A right-hand side of GL (§5.1.6, sec-grammar-notation): alphabetically assigned production ID (Grammar.GL.ids).
abbrev ProdId := NatNtId
Syntax.lean:37A nonterminal of GL (§5.1, sec-syntactic-and-lexical-grammars): Grammar.NT's constructor index, sorted alphabetically.
abbrev NtId := NatParamId
Syntax.lean:40A grammatical parameter of GL (§5.1.6, sec-grammar-notation: Yield, Await, …): Grammar.Param's constructor index, sorted alphabetically.
abbrev ParamId := NatPrimId
Syntax.lean:43A declared primitive (§5.2, sec-algorithm-conventions; §4.2, sec-hosts-and-implementations): notation-level operations (𝔽, ℝ, ℤ, abs, floor, …) and host choices.
abbrev PrimId := NatSortId
Syntax.lean:45A sort name of the type-noun lexicon (§6, sec-ecmascript-data-types-and-values).
abbrev SortId := NatMethodId
Syntax.lean:47A concrete-method name (§5.2.2, sec-algorithm-conventions-abstract-operations): _envRec_.HasBinding(…).
abbrev MethodId := NatClauseId
Syntax.lean:49A clause of spec.html (§5.2, sec-algorithm-conventions: its id), sorted alphabetically.
abbrev ClauseId := NatTableId
Syntax.lean:52An emu-table (§5.2, sec-algorithm-conventions), by its index in Ecma.Gen.tables flattened, sorted alphabetically.
abbrev TableId := NatAlgId
Syntax.lean:55An algorithm (§5.2, sec-algorithm-conventions): a clause and its position among the clause's algorithms.
structure AlgId whereSub
Syntax.lean:61The 𝔽 or ℤ subscript of a numeric literal (§5.2.6, sec-mathematical-operations).
inductive Sub whereNumeral
Syntax.lean:69A numeral as written (§5.2.6, sec-mathematical-operations): 53, 0x10FFFF (digits kept for width and case), and 0.05 as frac 0 5 2 (whole part, fraction digits as a number, their count).
inductive Numeral whereSign
Syntax.lean:76The sign of a numeric literal (§5.2.6, sec-mathematical-operations).
inductive Sign whereMag
Syntax.lean:83A magnitude (§5.2.6, sec-mathematical-operations): a numeral or ∞.
inductive Mag whereValLit
Syntax.lean:89A value literal *…* (§5.2, sec-algorithm-conventions; §6.1, sec-ecmascript-language-types).
inductive ValLit whereConj
Syntax.lean:106Logical conjunction or disjunction in a step condition (§5.2, sec-algorithm-conventions).
inductive Conj whereUnOp
Syntax.lean:112Unary operator in an algorithm expression (§5.2.6, sec-mathematical-operations).
inductive UnOp whereDataLit
Syntax.lean:120A spec datum without a literal form (§5.2, sec-algorithm-conventions): a sort, the alternative a template's choice takes, or the value of an omitted optional part.
inductive DataLit whereBinOp
Syntax.lean:127§5.2.6 (sec-mathematical-operations) arithmetic operators; pow is <sup>.
inductive BinOp whereRelOp
Syntax.lean:141Relational comparison operators (§5.2.6, sec-mathematical-operations).
inductive RelOp whereMathFn
Syntax.lean:151The functions of §21.3 (sec-math-object) the steps name ("the sine of x", ln(x)): Model.fn's argument.
inductive MathFn whereCallee
Syntax.lean:175What a call names (§5.2.2, sec-algorithm-conventions-abstract-operations): an operation by the clause defining it (idx 0), or a primitive.
inductive Callee wherePrimDoc
Syntax.lean:181A primitive's documentation (§5.2, sec-algorithm-conventions): its signature and one-line meaning ("" for notation primitives).
structure PrimDoc whereCloKind
Syntax.lean:187The kinds of Abstract Closure literal (§6.2.8, sec-abstract-closure).
inductive CloKind where| abstract| job| matcher| matcherContinuation| readModifyWriteExpr
Syntax.lean:200Algorithm expressions (§5.2, sec-algorithm-conventions).
inductive Expr where43 constructors
| var (x : Slot)| val (v : ValLit)a mathematical or extended mathematical value: 2, +∞, -∞
| math (sign : Sign) (m : Mag)| enum (e : EnumId)a grammar parameter: Yield, Await, Tagged, …
| param (p : ParamId)| intrinsic (i : IntrinsicId)a field name used as a value: [[Value]]
| fieldName (f : FieldId)|NT[+P, ~Q]|: a grammar symbol and its parameters (true: +)
| nt (n : NtId) (args : List (ParamId × Bool))inline <emu-grammar>: its GL productions (one per presence of its optional symbols)
| prod (ps : List ProdId)0x002E (FULL STOP)
| codeUnit (n : Nat) (digits : String) (name : Option String)U+002D (HYPHEN-MINUS)
| codePoint (n : Nat) (digits : String) (name : Option String)` code `
| code (s : String)` super ` where a grammar symbol is meant: the terminal symbol of that text
| term (s : String)| call (f : Callee) (args : List Expr)algorithm a on args at the Parse Node the steps run at
| callAt (a : AlgId) (args : List Expr)the SDO of X [with argument(s) …]
| sdo (s : SdoId) (subject : Expr) (args : List Expr)the LexicalEnvironment of _ctx_
| component (c : FieldId) (subject : Expr)_e_.[[F]]
| field (e : Expr) (f : FieldId)_e_.[[M]](args)
| imethod (e : Expr) (m : FieldId) (args : List Expr)_e_.Name(args) (§5.2.2)
| cmethod (e : Expr) (m : MethodId) (args : List Expr)closure application _c_(args)
| apply (f : Expr) (args : List Expr)_l_[_i_]
| index (e : Expr) (i : Expr)? e
| q (e : Expr)! e
| bang (e : Expr)| un (o : UnOp) (e : Expr)| bin (o : BinOp) (a b : Expr)| paren (e : Expr)« a, b »
| list (es : List Expr)Record { [[F]]: e, … }, { }; kind is a sort name
| record (kind : Option SortId) (fs : List (FieldId × Expr))the Completion Record with which _ctx_ was just resumed
| resumedWith (ctx : Expr)this Parse Node: the node an SDO row runs at
| thisNodethe first |X|, …, |X| (k): an occurrence of a nonterminal in this production
| child (k : Nat) (n : NtId)|X| of node e through its unit chain
| childOf (e : Expr) (n : NtId)the *this* value of a built-in function (§10.3.1): its algorithm's hidden slot 0
| thisValueNewTarget of a built-in function: its algorithm's hidden slot 1
| newTarget| xref (c : ClauseId)an Abstract Closure literal: its index in the algorithm's closures
| closure (site : Nat)| table (t : TableId)the definition specified in <clause>: the algorithm of c
| definition (c : ClauseId)the value that k corresponds to in <table t>: the step cell of the row k selects
| tableStep (t : TableId) (key : Expr)a variable read as a bound-variable hole: one not yet bound is .absent
| bnd (x : Slot)| data (d : DataLit)a condition's Boolean as a value
| ofCond (c : Cond)Pred
Syntax.lean:278A predicate of a subject (§5.2, sec-algorithm-conventions): is v, is not either a String or a Symbol, is present.
inductive Pred whereCond
Syntax.lean:285Conditions of If, Assert, Repeat while/until (§5.2, sec-algorithm-conventions).
inductive Cond wherea subject and the predicates it shares: e is finite and is not v
| preds (e : Expr) (p : Pred) (rest : List (Conj × Pred))| rel (o : RelOp) (a b : Expr)| and (cs : List Cond)| or (cs : List Cond)| paren (c : Cond)the following algorithm returns *true*:
| alg (a : AlgId)an expression's value, a Boolean
| expr (e : Expr)an unchecked condition by its key: an Assert passes over it, elsewhere a residue
| pass (key : String)TyExpr
Syntax.lean:301Type expressions (§5.2, sec-algorithm-conventions; §6, sec-ecmascript-data-types-and-values): header types and the type nouns of steps.
inductive TyExpr where| sort (mods : List SortId) (s : SortId)| listOf (t : TyExpr)| seqOf (t : TyExpr)| butNot (base exc : TyExpr)| doc (text : String)| union (ts : List TyExpr)a normal completion containing T
| completion (normal : Option TyExpr)an integer in the inclusive interval from a to b
| interval (t : TyExpr) (lo hi : Expr)| value (v : Expr)| var (x : Slot)| nt (n : NtId)| record (fs : List (FieldId × TyExpr))an Object that has a [[F]] internal slot
| that (t : TyExpr) (p : Pred) (rest : List (Conj × Pred))a predicate as a type: only a pass writes it
| pred (p : Pred)Place
Syntax.lean:323The place Set writes (§5.2, sec-algorithm-conventions).
inductive Place whereBody
Syntax.lean:330A step's body (§5.2, sec-algorithm-conventions): an inline statement (If c, return x.) or nested steps.
inductive Body whereStmt
Syntax.lean:335Statement forms (§5.2, sec-algorithm-conventions).
inductive Stmt where32 constructors
| let_ (x : Slot) (e : Expr)| set (p : Place) (e : Expr)| ret (e : Option Expr)| perform (e : Expr)If c, then / If c, S., with the Else if and Else steps that follow it
| if_ (c : Cond) (b : Body) (arms : List Arm) (els : Option Arm)If c, S1; else S2.
| ifElse (c : Cond) (s1 s2 : Stmt)| assert (c : Cond)| assertAlways (c : Cond)Assert: If c, then d.
| assertIf (c d : Cond)Assert: This step is never reached. and the assert-meta forms
| unreachable (v : Nat)| throwVal (e : Expr)| note (text : String)| repeat_ (b : List Stmt)| repeatWhile (c : Cond) (b : List Stmt)| repeatUntil (c : Cond) (b : List Stmt)For each element e of L, do / For each T e of L, do; ty for the typed form; rev for reverse List order
| forEach (x : Slot) (ty : Option TyExpr) (l : Expr) (rev : Bool) (b : Body)For each Record { [[A]], [[B]] } r of L, do
| forEachRec (fs : List FieldId) (x : Slot) (l : Expr) (b : Body)For each integer i such that lo ≤ i < hi, in ascending order, do
| forRange (x : Slot) (lo : Expr) (loIncl : Bool) (hi : Expr) (hiIncl : Bool) (desc : Bool) (b : Body)For each own property key _P_ of _O_ such that _c_, in … order, do
| forKeys (x : Slot) (o : Expr) (c : Cond) (order : Nat) (b : Body)For each index _i_ of _L_, do
| forIndex (x : Slot) (l : Expr) (b : Body)For each child node _child_ of this Parse Node, do
| forChildren (x : Slot) (b : Body)For each child node _child_ of E, do
| forChildrenOf (x : Slot) (e : Expr) (b : Body)Repeat _n_ times:
| repeatN (n : Expr) (b : List Stmt)Suspend _ctx_. (v 0); Suspend _ctx_ and remove it from the execution context stack. (1)
| suspend (ctx : Expr) (v : Nat)Push _ctx_ onto the execution context stack; _ctx_ is now the running execution context.
| push (ctx : Expr) (v : Nat)Remove _ctx_ from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context.
| remove (ctx : Expr) (v : Nat)Remove _ctx_ from the execution context stack and restore _r_ as the running execution context.
| removeRestore (ctx r : Expr)Resume the context that is now on the top of the execution context stack as the running execution context.
| resumeTopResume the suspended evaluation of _ctx_ passing _c_ as the result of the operation that suspended it. Let _x_ be the Completion Record passed by the resumed computation.
| resumeLet (ctx c : Expr) (x : Slot)Resume _ctx_, passing _c_.
| resume (ctx c : Expr)Set the code evaluation state of _ctx_ such that when evaluation is resumed for that execution context, _clo_ will be called with no arguments.
| setCodeState (ctx clo : Expr)a block of steps (for instance, a macro expansion)
| block (ns : List Stmt)Arm
Syntax.lean:395An Else if c, … step (c present) or an Else, … step (c absent) (§5.2, sec-algorithm-conventions).
inductive Arm whereCloLit
Syntax.lean:409An Abstract Closure literal (§6.2.8, sec-abstract-closure): a new Abstract Closure with parameters (…) that captures … and performs the following steps when called:. Its slots are the algorithm's.
structure CloLit whereAlgKind
Syntax.lean:421An algorithm's kind (§5.2, sec-algorithm-conventions), from its clause's type.
inductive AlgKind where| ao| sdo| builtin| internalMethod| concreteMethod| numericMethod| hostDefined| implDefined| untypedParam
Syntax.lean:435A parameter (§5.2, sec-algorithm-conventions): its variable, type (structured headers only), whether it is optional (optional _x_, [ , _x_ ]) and whether it is a rest parameter (..._args_).
structure Param whereHeader
Syntax.lean:442A parsed structured header (§5.2, sec-algorithm-conventions: <h1> and dl.header).
structure Header whereAlg
Syntax.lean:451One algorithm (§5.2, sec-algorithm-conventions; §5.2.2, sec-algorithm-conventions-abstract-operations): a clause's definition with its header and variable table.
structure Alg whereSortArg
Syntax.lean:486An argument of a SortTest (§6, sec-ecmascript-data-types-and-values): the value itself (subject), or an enum constant.
inductive SortArg whereSortTest
Syntax.lean:492A runtime membership test for a data sort (§6, sec-ecmascript-data-types-and-values): none, an algorithm, or a primitive on SortArgs.
inductive SortTest whereSortDef
Syntax.lean:500A data sort (§6, sec-ecmascript-data-types-and-values): its direct supertypes, and its test (the value is the subject); a Record sort's values are the Records of its kind and of its subsorts'.
structure SortDef whereGTerminal
Syntax.lean:509A terminal of a grammar's right-hand side (§5.1.6, sec-grammar-notation): its source text, or a code point by its name in Tables 34 and 35 (<USP> the Space_Separator class).
inductive GTerminal whereDecls
Syntax.lean:516The declaration tables (§5.1, sec-syntactic-and-lexical-grammars; §5.2, sec-algorithm-conventions): names by id, for printing and resolution.
structure Decls whereclauses : Array Stringper clause, the operation it defines (its aoid or title), or ""
ops : Array Stringfields : Array Stringenums : Array Stringsdos : Array Stringmethods : Array Stringnts : Array StringGL's grammatical parameters, by ParamId
params : Array Stringprods : Array Stringprims : Array Stringper primitive, its documentation
primDocs : Array PrimDocsorts : Array Stringeach sort's definition, by SortId; none for Known's sorts, which the value decides
sortDefs : Array (Option SortDef) := #[]each SDO's header (params and return type), by SDO
sdoHeaders : Array (Option Header)per SDO, the algorithm its clause gives every production it lists no row for, by SdoId
sdoDefaults : Array (Option AlgId) := #[]clauses whose Job completions are checked in every mode (§9.5)
checkedJobs : Array ClauseId := #[]the nonterminals each of whose main-grammar right-hand sides is one terminal, with those terminals in grammar order
alts : Array (NtId × List GTerminal) := #[]per clause a production-in phrase names, the productions defined in it
clauseProds : Array (ClauseId × List ProdId) := #[]