Skip to content
Snippets Groups Projects
Commit fb01e55a authored by Hugo Wangler's avatar Hugo Wangler
Browse files

Update HOME_EXAM.md

parent f8b6a3c6
No related branches found
No related tags found
No related merge requests found
...@@ -261,7 +261,7 @@ assignment: ...@@ -261,7 +261,7 @@ assignment:
``` ```
functions: 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 ```math
\frac{\lang p, \sigma \rang}{\lang p(\overrightarrow{v}), \sigma \rang \ \Darr \ \lang n, \sigma \rang} \frac{\lang p, \sigma \rang}{\lang p(\overrightarrow{v}), \sigma \rang \ \Darr \ \lang n, \sigma \rang}
...@@ -355,18 +355,24 @@ Greater than or equals (>=): ...@@ -355,18 +355,24 @@ Greater than or equals (>=):
Equals (==): Equals (==):
```math ```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} \frac{\Gamma \ \vdash \ e1 \ : \ i32 \quad \Gamma \ \vdash \ e2 \ : \ i32}{\Gamma \ \vdash (e1 \ == \ e2) \ : \ bool}
``` ```
Not equals (!=): Not equals (!=):
```math ```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} \frac{\Gamma \ \vdash \ e1 \ : \ i32 \quad \Gamma \ \vdash \ e2 \ : \ i32}{\Gamma \ \vdash (e1 \ != \ e2) \ : \ bool}
``` ```
### Assignment ### Assignment
Given the type $\tau$, variable $x$ and value $n$ Given the type $`\tau`$, variable $`x`$ and value $`n`$
```math ```math
\frac{\Gamma \ \vdash \ x \ : \ \tau \quad \Gamma \ \vdash \ n \ : \ \tau}{\lang x := n, \sigma \rang \ \Darr \ \Gamma \ \vdash x \ : \ \tau} \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$ ...@@ -378,28 +384,28 @@ Given the type $\tau$, variable $x$ and value $n$
``` ```
### **while** statement ### **while** statement
The condition, $b$, of the while statement The condition, $`b`$, of the while statement
```math ```math
\frac{}{\Gamma \ \vdash b \ : \ bool} \frac{}{\Gamma \ \vdash b \ : \ bool}
``` ```
### **if/elseif** statement ### **if/elseif** statement
The conditions, $b_i$, of the if- and elseif-statements The conditions, $`b_i`$, of the if- and elseif-statements
```math ```math
\frac{}{\Gamma \ \vdash b_i \ : \ bool} \frac{}{\Gamma \ \vdash b_i \ : \ bool}
``` ```
### Functions ### Functions
Given the function $p$ with the type of its return type Given the function $`p`$ with the type of its return type
```math ```math
\frac{\Gamma \ \vdash p \ : \ \tau \quad \lang p, \sigma \rang \ \Darr \ n}{\Gamma \ \vdash n \ : \ \tau} \frac{\Gamma \ \vdash p \ : \ \tau \quad \lang p, \sigma \rang \ \Darr \ n}{\Gamma \ \vdash n \ : \ \tau}
``` ```
#### Parameters and arguments #### 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 ```math
\frac{\Gamma \ \vdash p_i \ : \ \tau}{\Gamma \ \vdash a_i \ : \ \tau} \frac{\Gamma \ \vdash p_i \ : \ \tau}{\Gamma \ \vdash a_i \ : \ \tau}
...@@ -550,9 +556,9 @@ Error: Mismatched type for operation '==' ...@@ -550,9 +556,9 @@ Error: Mismatched type for operation '=='
Note: expected i32, found bool Note: expected i32, found bool
Could not compile 'input.rs' 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. 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 ...@@ -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 # Your LLVM backend
- Let your backend produces LLVM-IR for your example program. - Let your backend produces LLVM-IR for your example program.
```LLVM IR
```llvm
ModuleID = 'program' ModuleID = 'program'
source_filename = "program" source_filename = "program"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment