ECMA-262 in Lean

Reading page · generated from lean/Ecma/Implements.lean, lean/Ecma/Machine/Run.lean

What it is to implement the specification

The definition the engine's headline theorem is stated against, in full, with the definitions of a run it uses. 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 the readings of the errata (rd) and whether Asserts are checked, and the statement is of every rd. A definition reading, the overlay's one reading of prose steps, is no choice: the program's code holds its steps (Ins.reading), and rd is asked only at an erratum.

def

Spec.program

Implements.lean:34

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:39

An implementation over the model M: its own algorithms, its host, and its transition under the errata's readings and 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
extras : AlgId → Option Alg
step : (ErratumId → Reading) → Bool → Cfg M → Out M
def

Implementation.spec

Implements.lean:45

The specification's machine for I: the specification's program with I's algorithms, and I's host.

def Implementation.spec (I : Implementation M) (rd : ErratumId → Reading) (chk : Bool) : Ctx M :=  Ctx.spec (Spec.program I.extras) I.host rd chk
inductive

Reached

Implements.lean:51

The configurations the machine X reaches: 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
| first (s : State M) (k : Call M) : s.frames = [] → Reached X (start s k)
| next {c : Cfg M} {v : Val M} {s s' : State M} (k : Call M) :    Reached X c → Ends X c (.ok v s) → s'.frames = s.frames → Reached X (start s' k)
inductive

Implementation.Runs

Implements.lean:58

A run of I from c that ends with f.

inductive Implementation.Runs (I : Implementation M) (rd : ErratumId → Reading) (chk : Bool) :    Cfg M → Final M → Prop where
| ends {c : Cfg M} {f : Final M} : I.step rd chk c = .inr f → I.Runs rd chk c f
| step {c c' : Cfg M} {f : Final M} : I.step rd chk c = .inl c' → I.Runs rd chk c' f → I.Runs rd chk c f
structure

Implements

Implements.lean:64

I implements the specification.

structure Implements (I : Implementation M) : Prop where

its host meets every requirement the specification makes of a host

host : Host.WF I.host

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 (it never answers otherwise than the specification)

step : ∀ rd chk c, Reached (I.spec rd chk) c →  match I.step rd chk c with  | .inl c' => Steps (I.spec rd chk) c c'  | .inr f => Runs (I.spec rd 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 the readings, and nothing else.

What it is for an implementation to be the specification's is stated over these (Ecma.Implements).

def

Machine.Ctx.spec

Run.lean:26

The specification's context: the program's code, the host, the readings chosen for the errata, and whether Asserts are checked. A definition reading is no choice: the code holds its steps (Ins.reading), and rd is not asked of it.

def Ctx.spec (prog : Prog') (H : Host M) (rd : ErratumId → Reading) (chk : Bool) : Ctx M :=  { prog, H, rd, chk }
def

Machine.Step

Run.lean:30

One transition.

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

Machine.Ends

Run.lean:33

The machine ends at c, with f.

def Ends (X : Ctx M) (c : Cfg M) (f : Final M) : Prop := step X c = .inr f
inductive

Machine.Steps

Run.lean:36

Any number of transitions.

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

Machine.Runs

Run.lean:41

A run from c that ends with f.

def Runs (X : Ctx M) (c : Cfg M) (f : Final M) : Prop := ∃ c', Steps X c c' ∧ Ends X c' f
def

Machine.Calls

Run.lean:44

The call k from the state s gives v, leaving the state t.

def Calls (X : Ctx M) (k : Call M) (s : State M) (v : Val M) (t : State M) : Prop := Runs X (start s k) (.ok v t)