Skip to content
Snippets Groups Projects
Commit 83300433 authored by Wilma Krutrök's avatar Wilma Krutrök
Browse files

Update HOME_EXAM.md

parent 3d7bca66
No related branches found
No related tags found
No related merge requests found
......@@ -597,20 +597,19 @@ Borrow is used at multiple locations, therefor it is mutable from different refe
Below follows the rewritten examples that are accepted by the borrow checker.
```rust
fn a(x: &mut i32) -> () {
*x += 1;
*x = *x + 1;
}
fn main() -> () {
let mut y: i32 = 5;
a(&mut y);
}
```
```rust
fn b(x: &mut i32, y: &mut i32) -> () {
*x += 1;
*y += 1;
*x = *x + 1;
*y = *y + 1;
}
fn main() -> () {
let mut x: i32 = 5;
......@@ -621,16 +620,17 @@ fn main() -> () {
```rust
fn main() -> () {
let mut x = 0;
let y = &mut x;
*y += 1;
x += 1;
let mut x: i32 = 0;
let y: i32 = &mut x;
*y = *y + 1;
x = x + 1;
}
```
The borrowchecker should make sure that:
- One reference can only be mutable at a time.
- Multiple immutable references can be used.
- One mutable reference and multiple immutable references can not exist at the same time
This ensures that a variable can not be changed at the same time that another reference tries to read it.
......@@ -648,5 +648,4 @@ The process of implementing the type checker and the interpreter was similar. Th
- Code optimization and register allocation. Machine code generation for common architectures. [Both LLVM/Crane-Lift does the "dirty work" of backend optimization/register allocation leveraging the SSA form of the LLVM-IR]
Comment on additional things that you have experienced and learned throughout the course.
It has been difficult to write good structured code because this is the first time I worked with Rust. Therefor the rules and structure was new to me which ended up in very messy code. I focused on getting as much as possible to work to get a broad understanding instead. It would be really fun to rewrite everything from the beginning now with the knowledge and insight the course have given!
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment