diff --git a/HOME_EXAM.md b/HOME_EXAM.md index 14563af1090b4e504bf5e14978a7401d91c2f3be..26a73afc0f09848378b25b28f8bb890f532a5e79 100644 --- a/HOME_EXAM.md +++ b/HOME_EXAM.md @@ -261,7 +261,7 @@ assignment: ``` functions: -Given a list of arguments $\overrightarrow{v} = [v_1, \ldots, v_n]$ the call of function $p$ will evaulate to a value $n$ (the return value, if any) according to +Given a list of arguments $`\overrightarrow{v} = [v_1, \ldots, v_n]`$ the call of function $`p`$ will evaulate to a value $`n`$ (the return value, if any) according to ```math \frac{\lang p, \sigma \rang}{\lang p(\overrightarrow{v}), \sigma \rang \ \Darr \ \lang n, \sigma \rang} @@ -355,18 +355,24 @@ Greater than or equals (>=): Equals (==): ```math -\frac{\Gamma \ \vdash \ e1 \ : \ bool \quad \Gamma \ \vdash \ e2 \ : \ bool}{\Gamma \ \vdash (e1 \ == \ e2) \ : \ bool} and +\frac{\Gamma \ \vdash \ e1 \ : \ bool \quad \Gamma \ \vdash \ e2 \ : \ bool}{\Gamma \ \vdash (e1 \ == \ e2) \ : \ bool} +``` +or +```math \frac{\Gamma \ \vdash \ e1 \ : \ i32 \quad \Gamma \ \vdash \ e2 \ : \ i32}{\Gamma \ \vdash (e1 \ == \ e2) \ : \ bool} ``` Not equals (!=): ```math -\frac{\Gamma \ \vdash \ e1 \ : \ bool \quad \Gamma \ \vdash \ e2 \ : \ bool}{\Gamma \ \vdash (e1 \ != \ e2) \ : \ bool} and +\frac{\Gamma \ \vdash \ e1 \ : \ bool \quad \Gamma \ \vdash \ e2 \ : \ bool}{\Gamma \ \vdash (e1 \ != \ e2) \ : \ bool} +``` +or +```math \frac{\Gamma \ \vdash \ e1 \ : \ i32 \quad \Gamma \ \vdash \ e2 \ : \ i32}{\Gamma \ \vdash (e1 \ != \ e2) \ : \ bool} ``` ### Assignment -Given the type $\tau$, variable $x$ and value $n$ +Given the type $`\tau`$, variable $`x`$ and value $`n`$ ```math \frac{\Gamma \ \vdash \ x \ : \ \tau \quad \Gamma \ \vdash \ n \ : \ \tau}{\lang x := n, \sigma \rang \ \Darr \ \Gamma \ \vdash x \ : \ \tau} @@ -378,28 +384,28 @@ Given the type $\tau$, variable $x$ and value $n$ ``` ### **while** statement -The condition, $b$, of the while statement +The condition, $`b`$, of the while statement ```math \frac{}{\Gamma \ \vdash b \ : \ bool} ``` ### **if/elseif** statement -The conditions, $b_i$, of the if- and elseif-statements +The conditions, $`b_i`$, of the if- and elseif-statements ```math \frac{}{\Gamma \ \vdash b_i \ : \ bool} ``` ### Functions -Given the function $p$ with the type of its return type +Given the function $`p`$ with the type of its return type ```math \frac{\Gamma \ \vdash p \ : \ \tau \quad \lang p, \sigma \rang \ \Darr \ n}{\Gamma \ \vdash n \ : \ \tau} ``` #### Parameters and arguments -Given a function with parameters $p1, \dotsb, p_i$ and arguments $a1, \dotsb, a_i$ then for every parameter and argument +Given a function with parameters $`p1, \dotsb, p_i`$ and arguments $`a1, \dotsb, a_i`$ then for every parameter and argument ```math \frac{\Gamma \ \vdash p_i \ : \ \tau}{\Gamma \ \vdash a_i \ : \ \tau} @@ -550,9 +556,9 @@ Error: Mismatched type for operation '==' Note: expected i32, found bool Could not compile 'input.rs' ``` -By this it can be seen that the type checker assumes that the type of ```a``` is correct when checking the assignment of ```b``` which indeed would be correctly typed if the former variable would have been correctly assigned a i32 value. This is done by concluding that `5 * true` would evaluate to a i32 value if it was correctly typed and then the entire expression `5 + 5 * true` will be correctly typed. +By this it can be seen that the type checker assumes that the type of `a` is correct when checking the assignment of `b` which indeed would be correctly typed if the former variable would have been correctly assigned a i32 value. This is done by concluding that `5 * true` would evaluate to a i32 value if it was correctly typed and then the entire expression `5 + 5 * true` will be correctly typed. -Thus by following this pattern the type checker is able to continue type checking and reporting new errors, which can be seen when it reports that the assignment of ```c``` is incorrect (boolean equals requires the same type on each side). +Thus by following this pattern the type checker is able to continue type checking and reporting new errors, which can be seen when it reports that the assignment of `c` is incorrect (boolean equals requires the same type on each side). The type checker also makes sure that functions with a specified return type always returns. This is done by going through each function and making sure that a tailing return statement or a return inside an else-statement exists. If this is not the case the error is reported along with all other type errors found. @@ -567,7 +573,8 @@ It also needs to keep track of the kind of borrow that have been made to a resou # Your LLVM backend - Let your backend produces LLVM-IR for your example program. -```LLVM IR + +```llvm ModuleID = 'program' source_filename = "program" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"