5.5. Function and program
A function is well typed when its body is, under the context of its parameters and its return type.
\dfrac{[x_1 \mapsto \tau_1, \ldots, x_k \mapsto \tau_k] \vdash c \dashv \Gamma'}{\vdash \tau\ f(\tau_1\,x_1, \ldots, \tau_k\,x_k)\ \{c\}}\;\textsf{(T-Fun)}
Lean code for Definition5.5.1●1 definition
Associated Lean declarations
-
CoreCpp.Typing.fn[complete]
-
CoreCpp.Typing.fn[complete]
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.Typing.fn (p : CoreCpp.Program) (f : CoreCpp.Fun) : CoreCpp.T Unit
def CoreCpp.Typing.fn (p : CoreCpp.Program) (f : CoreCpp.Fun) : CoreCpp.T Unit
A function is well typed when its parameter and return types have values and are well formed, and its body is, under the context of its parameters and its return type. A reference parameter has in Γ the type of its referent, as a local reference does. ``` τ, τᵢ storable and well formed [x₁ ↦ τ₁, …, xₖ ↦ τₖ] ⊢ c ⊣ Γ' ──────────────────────────────────────────────────────────────── (T-Fun) ⊢ τ f (τ₁ x₁, …, τₖ xₖ) { c } ```
-
CoreCpp.Program[complete] -
CoreCpp.check[complete] -
CoreCpp.runWith[complete] -
CoreCpp.run[complete]
A program is a list of functions with distinct names and a function int main(). The initial store is empty, because there are no global variables, and the result is the value of main().
\dfrac{\begin{array}{c} \text{distinct names} \qquad \vdash f_i \ \text{for each } i \\ \mathtt{main} \mapsto \mathtt{int\ main()}\ \{c\} \end{array}}{\vdash p}\;\textsf{(T-Program)}
\dfrac{[\,], \emptyset \vdash \mathtt{main}() \Rightarrow v, \sigma}{p \Rightarrow v}\;\textsf{(Program)}
Lean code for Definition5.5.2●4 definitions
Associated Lean declarations
-
CoreCpp.Program[complete]
-
CoreCpp.check[complete]
-
CoreCpp.runWith[complete]
-
CoreCpp.run[complete]
-
CoreCpp.Program[complete] -
CoreCpp.check[complete] -
CoreCpp.runWith[complete] -
CoreCpp.run[complete]
-
abbrevdefined in CoreCpp/Syntax.leancomplete
abbrev CoreCpp.Program : Type
abbrev CoreCpp.Program : Type
A program is a list of declarations. There are no global variables.
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.check (p₀ : CoreCpp.Program) : Except CoreCpp.TypeError Unit
def CoreCpp.check (p₀ : CoreCpp.Program) : Except CoreCpp.TypeError Unit
A program is well typed when class and function names are distinct up to overloading, every class and function is well typed and `int main()` exists. A template is not checked, only its instantiations are. ``` names distinct up to overloading ⊢ Cᵢ for each class ⊢ fᵢ for each function main ↦ (int main() { c }) ────────────────────────────────────────────────────────────────────────────── (T-Program) ⊢ p ``` -
defdefined in CoreCpp/Eval.leancomplete
def CoreCpp.runWith (trace : Bool) (p : CoreCpp.Program) : Except CoreCpp.Error CoreCpp.Val × Array CoreCpp.TraceEntry
def CoreCpp.runWith (trace : Bool) (p : CoreCpp.Program) : Except CoreCpp.Error CoreCpp.Val × Array CoreCpp.TraceEntry
Program execution. The initial store is empty, because there are no global variables, and the result is the value returned by `main()`. ``` main ↦ (int main() { c }) [], ∅ ⊢ main() ⇒ v, σ ─────────────────────────────────────────────────── (Program) p ⇒ v ``` The objects created with new stay in σ until delete or the end of the program. The locals of main leave σ with the return of the call, so the final store holds objects only. The program is annotated with the static classes of method calls and deletes before it runs, when it is well typed, and otherwise runs as parsed, with every dispatch by the class tag. -
defdefined in CoreCpp/Eval.leancomplete
def CoreCpp.run (p : CoreCpp.Program) : Except CoreCpp.Error CoreCpp.Val
def CoreCpp.run (p : CoreCpp.Program) : Except CoreCpp.Error CoreCpp.Val