ECMA-262 in Lean

Reading 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.

def

Spec.program

Implements.lean:32

The 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)
structure

Implementation

Implements.lean:37

An 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) where
def

Implementation.spec

Implements.lean:44

The 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
inductive

Reached

Implements.lean:51

The 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 where
structure

Implements

Implements.lean:65

I implements the specification (§2, sec-conformance; §4.2, sec-hosts-and-implementations; §5.2, sec-algorithm-conventions).

structure Implements (I : Implementation M) : Prop where

each 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).

def

Machine.Ctx.spec

Run.lean:25

The 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 }
def

Machine.Step

Run.lean:29

One transition (§5.2, sec-algorithm-conventions).

def Step (X : Ctx M) (c c' : Cfg M) : Prop := step X c = .inl c'
def

Machine.Ends

Run.lean:32

The 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 f
inductive

Machine.Steps

Run.lean:35

Any number of transitions (§5.2, sec-algorithm-conventions).

inductive Steps (X : Ctx M) : Cfg M → Cfg M → Prop where
def

Machine.Runs

Run.lean:40

A 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' f

Observable 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.

structure

State

State.lean:26

The 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 where

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 M

the execution context whose evaluation a transfer suspends: the running one before the execution context stack last changed

suspended : Val M := .absent

the surrounding agent's Agent Record (§9.7)

agent : Val M

parser invocations so far

parses : Nat := 0

the 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 := 0

the 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)) := []
inductive

Res

State.lean:77

The 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) where

leaving the algorithm with an abrupt completion

| esc (c : Val M) (s : State M)
Auxiliary definition: Run
def

Run

State.lean:84

The state-and-completion monad of leaf and host operations (§5.2, sec-algorithm-conventions).

def Run (α : Type) : Type := State M → Res M α
abbrev

ShapeChange.stamp

State.lean:88

The 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.length
Auxiliary definitions (6): State.suspendedHolds, Run.Res.bind, Run.bind, Run.stop, …
def

State.suspendedHolds

State.lean:108

Values 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
def

Run.Res.bind

State.lean:116

Sequencing; 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
def

Run.bind

State.lean:122

Monadic 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) f
def

Run.stop

State.lean:124

Stop the computation with reason r (§5.2, sec-algorithm-conventions).

@[inline] def stop (r : Stop) : Run M α := fun _ => .stop r
def

Run.Res.boundary

State.lean:135

The 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
def

Run.boundary

State.lean:141

Run 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
def

HostCall.schedulesJob

State.lean:194

A 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
def

HostCall.takes

State.lean:200

A 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
def

alloc

State.lean:242

Allocate 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
def

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
def

listOf

State.lean:554

Allocate 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).

structure

Machine.Ctx

Config.lean:25

What 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) where
inductive

Machine.Call

Config.lean:37

A 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

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)
structure

Machine.Cfg

Config.lean:91

A 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) where
inductive

Machine.Final

Config.lean:97
inductive Final (M : Model) where
| todo (form : String)
abbrev

Machine.Out

Config.lean:104

A step's result (§5.2, sec-algorithm-conventions): the next configuration, or the run's end.

abbrev Out (M : Model) := Cfg M ⊕ Final M
Auxiliary definition: Machine.start
def

Machine.start

Config.lean:107

A 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.

abbrev

Slot

Syntax.lean:23

An algorithm-local variable (§5.2, sec-algorithm-conventions): an index into Alg.vars.

abbrev Slot := Nat
abbrev

FieldId

Syntax.lean:26

A 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 := Nat
abbrev

EnumId

Syntax.lean:28

An enum constant (§5.2, sec-algorithm-conventions): ~normal~.

abbrev EnumId := Nat
abbrev

IntrinsicId

Syntax.lean:31

A 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 := FieldId
abbrev

SdoId

Syntax.lean:33

A syntax-directed operation (§5.2.3, sec-algorithm-conventions-syntax-directed-operations), by name.

abbrev SdoId := Nat
abbrev

ProdId

Syntax.lean:35

A right-hand side of GL (§5.1.6, sec-grammar-notation): alphabetically assigned production ID (Grammar.GL.ids).

abbrev ProdId := Nat
abbrev

NtId

Syntax.lean:37

A nonterminal of GL (§5.1, sec-syntactic-and-lexical-grammars): Grammar.NT's constructor index, sorted alphabetically.

abbrev NtId := Nat
abbrev

ParamId

Syntax.lean:40

A grammatical parameter of GL (§5.1.6, sec-grammar-notation: Yield, Await, …): Grammar.Param's constructor index, sorted alphabetically.

abbrev ParamId := Nat
abbrev

PrimId

Syntax.lean:43

A declared primitive (§5.2, sec-algorithm-conventions; §4.2, sec-hosts-and-implementations): notation-level operations (𝔽, ℝ, ℤ, abs, floor, …) and host choices.

abbrev PrimId := Nat
abbrev

SortId

Syntax.lean:45

A sort name of the type-noun lexicon (§6, sec-ecmascript-data-types-and-values).

abbrev SortId := Nat
abbrev

MethodId

Syntax.lean:47

A concrete-method name (§5.2.2, sec-algorithm-conventions-abstract-operations): _envRec_.HasBinding(…).

abbrev MethodId := Nat
abbrev

ClauseId

Syntax.lean:49

A clause of spec.html (§5.2, sec-algorithm-conventions: its id), sorted alphabetically.

abbrev ClauseId := Nat
abbrev

TableId

Syntax.lean:52

An emu-table (§5.2, sec-algorithm-conventions), by its index in Ecma.Gen.tables flattened, sorted alphabetically.

abbrev TableId := Nat
structure

AlgId

Syntax.lean:55

An algorithm (§5.2, sec-algorithm-conventions): a clause and its position among the clause's algorithms.

structure AlgId where
inductive

Sub

Syntax.lean:61

The 𝔽 or ℤ subscript of a numeric literal (§5.2.6, sec-mathematical-operations).

inductive Sub where
inductive

Numeral

Syntax.lean:69

A 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 where
| dec (n : Nat)
| hex (n : Nat) (digits : String)
| frac (whole : Nat) (fraction : Nat) (places : Nat)
inductive

Sign

Syntax.lean:76

The sign of a numeric literal (§5.2.6, sec-mathematical-operations).

inductive Sign where
inductive

Mag

Syntax.lean:83

A magnitude (§5.2.6, sec-mathematical-operations): a numeral or ∞.

inductive Mag where
inductive

ValLit

Syntax.lean:89

A value literal *…* (§5.2, sec-algorithm-conventions; §6.1, sec-ecmascript-language-types).

inductive ValLit where
| str (s : String)

a BigInt in ECMAScript source notation: ` 1n `

| bigN (n : Numeral)
inductive

Conj

Syntax.lean:106

Logical conjunction or disjunction in a step condition (§5.2, sec-algorithm-conventions).

inductive Conj where
inductive

UnOp

Syntax.lean:112

Unary operator in an algorithm expression (§5.2.6, sec-mathematical-operations).

inductive UnOp where

Boolean negation

| not
inductive

DataLit

Syntax.lean:120

A 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 where
inductive

BinOp

Syntax.lean:127

§5.2.6 (sec-mathematical-operations) arithmetic operators; pow is <sup>.

inductive BinOp where

plus, as the equation SDOs write +

| plus
inductive

RelOp

Syntax.lean:141

Relational comparison operators (§5.2.6, sec-mathematical-operations).

inductive RelOp where
inductive

MathFn

Syntax.lean:151

The functions of §21.3 (sec-math-object) the steps name ("the sine of x", ln(x)): Model.fn's argument.

inductive MathFn where
inductive

Callee

Syntax.lean:175

What 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 where
structure

PrimDoc

Syntax.lean:181

A primitive's documentation (§5.2, sec-algorithm-conventions): its signature and one-line meaning ("" for notation primitives).

structure PrimDoc where
sig : String
inductive

CloKind

Syntax.lean:187

The kinds of Abstract Closure literal (§6.2.8, sec-abstract-closure).

inductive CloKind where
inductive

Expr

Syntax.lean:200

Algorithm expressions (§5.2, sec-algorithm-conventions).

inductive Expr where
43 constructors

a mathematical or extended mathematical value: 2, +∞, -∞

| math (sign : Sign) (m : Mag)

a grammar parameter: Yield, Await, Tagged, …

| param (p : ParamId)

|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)

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)

closure application _c_(args)

| apply (f : Expr) (args : 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

| thisNode

the first |X|, …, |X| (k): an occurrence of a nonterminal in this production

| child (k : Nat) (n : NtId)

the *this* value of a built-in function (§10.3.1): its algorithm's hidden slot 0

| thisValue

NewTarget of a built-in function: its algorithm's hidden slot 1

| newTarget

an Abstract Closure literal: its index in the algorithm's closures

| closure (site : Nat)

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)

a condition's Boolean as a value

| ofCond (c : Cond)
inductive

Pred

Syntax.lean:278

A predicate of a subject (§5.2, sec-algorithm-conventions): is v, is not either a String or a Symbol, is present.

inductive Pred where
| isVal (neg neither : Bool) (vs : List Expr)
| isTy (neg neither : Bool) (ts : List TyExpr)

f on args and then the subject, a Boolean; negated when neg

| call (f : Callee) (args : List Expr) (neg : Bool)
inductive

Cond

Syntax.lean:285

Conditions of If, Assert, Repeat while/until (§5.2, sec-algorithm-conventions).

inductive Cond where

a subject and the predicates it shares: e is finite and is not v

| preds (e : Expr) (p : Pred) (rest : List (Conj × Pred))

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)
inductive

TyExpr

Syntax.lean:301

Type expressions (§5.2, sec-algorithm-conventions; §6, sec-ecmascript-data-types-and-values): header types and the type nouns of steps.

inductive TyExpr where
| doc (text : String)

an integer in the inclusive interval from a to b

| interval (t : TyExpr) (lo hi : Expr)

a predicate as a type: only a pass writes it

| pred (p : Pred)
inductive

Place

Syntax.lean:323

The place Set writes (§5.2, sec-algorithm-conventions).

inductive Place where
inductive

Body

Syntax.lean:330

A step's body (§5.2, sec-algorithm-conventions): an inline statement (If c, return x.) or nested steps.

inductive Body where
inductive

Stmt

Syntax.lean:335

Statement forms (§5.2, sec-algorithm-conventions).

inductive Stmt where
32 constructors

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)

Assert: This step is never reached. and the assert-meta forms

| unreachable (v : Nat)
| note (text : String)

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 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 child node _child_ of this Parse Node, do

| forChildren (x : Slot) (b : Body)

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.

| resumeTop

Resume 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)
inductive

Arm

Syntax.lean:395

An Else if c, … step (c present) or an Else, … step (c absent) (§5.2, sec-algorithm-conventions).

inductive Arm where
structure

CloLit

Syntax.lean:409

An 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 where

none: "with no parameters"

params : Option (List Slot)

this, NewTarget, the passed arguments List: slots a built-in call binds

frame : Option (Slot × Slot × Slot) := none
inductive

AlgKind

Syntax.lean:421

An algorithm's kind (§5.2, sec-algorithm-conventions), from its clause's type.

inductive AlgKind where
structure

Param

Syntax.lean:435

A 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 where
structure

Header

Syntax.lean:442

A parsed structured header (§5.2, sec-algorithm-conventions: <h1> and dl.header).

structure Header where
structure

Alg

Syntax.lean:451

One 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 where

variable names by slot, without underscores: the receiver, the parameters, then the rest

vars : Array String

the Abstract Closure literals, in text order

closures : Array CloLit
inductive

SortArg

Syntax.lean:486

An argument of a SortTest (§6, sec-ecmascript-data-types-and-values): the value itself (subject), or an enum constant.

inductive SortArg where
inductive

SortTest

Syntax.lean:492

A runtime membership test for a data sort (§6, sec-ecmascript-data-types-and-values): none, an algorithm, or a primitive on SortArgs.

inductive SortTest where
structure

SortDef

Syntax.lean:500

A 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 where

its values are the Records of this kind

record : Bool := false
inductive

GTerminal

Syntax.lean:509

A 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 where
| text (s : String)
| cp (name : String)
structure

Decls

Syntax.lean:516

The declaration tables (§5.1, sec-syntactic-and-lexical-grammars; §5.2, sec-algorithm-conventions): names by id, for printing and resolution.

structure Decls where

per clause, the operation it defines (its aoid or title), or ""

ops : Array String
enums : Array String
sdos : Array String
nts : Array String

GL's grammatical parameters, by ParamId

params : Array String
prods : Array String
prims : Array String
sorts : Array String

each 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) := #[]