Skip to content

Commit

Permalink
Merge pull request #8 from cs-dust/integration
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
sevenseasofbri authored Apr 11, 2023
2 parents ecb076a + 8ab9524 commit bd38dad
Show file tree
Hide file tree
Showing 25 changed files with 949 additions and 201 deletions.
File renamed without changes.
20 changes: 20 additions & 0 deletions examples/block_expression_primitive_op.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fn main() {
let x = 5;

let y = {
let x_squared = x * x;
let x_cube = x_squared * x;

// This expression will be assigned to `y`
x_cube + x_squared + x
};

let z = {
// The semicolon suppresses this expression and `()` is assigned to `z`
2 * x;
};

println("x is {:?}", x);
println("y is {:?}", y);
println("z is {:?}", z);
}
9 changes: 7 additions & 2 deletions examples/bool_types_with_binop.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
fn main() {
// bool
let a = true;
println("a is ", a);
let b = false;
let bool_expr = a && b;
println("b is ", b);

println("a && b gives ", bool_expr);
let bool_and = a && b;
println("a && b gives ", bool_and);

let bool_or = a || b;
println("a || b gives ", bool_or);
}
15 changes: 15 additions & 0 deletions examples/control_flow_fizzbuzz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
// A counter variable
let mut n = 1;

// Loop while `n` is less than 101
while n < 10 {
if n == 5 || n == 7 {
println("fizz");
} else {
println("buzz");
}
// Increment counter
n = n + 1;
}
}
5 changes: 0 additions & 5 deletions examples/for_loop_example.rs

This file was deleted.

19 changes: 19 additions & 0 deletions examples/function_application_nested_vs_normal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn main() {
fn nested_function(x: i64, y: i64) -> i64 {
x + y
}
println("nested function adds 5 and 10 as", nested_function(five(), ten()));
println("normal function adds 5 and 10 as", add(five(), ten()));
}

fn five() -> i64 {
5
}

fn ten() -> i64 {
10
}

fn add(x: i64, y: i64) -> i64 {
x + y
}
17 changes: 12 additions & 5 deletions examples/numeric_types_with_binop.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
fn main() {
// addition
let sum = 5 + 10;
let x = 5;
let y = 1;
println("x is ", x);
println("y is ", y);

let multiply = 8 * 9;
let sum = x + y;
println("sum = x + y is ", sum);

let divide = 10/4;
let multiply = x * 9;
println("x * 9 is ", multiply);

let subtract = 20 - 10;
let divide = 10/x;
println("10 / x is ", divide);

println("x - y is ", x - y);
}
17 changes: 17 additions & 0 deletions examples/ownership_function_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fn main() {
let number = 1;
makes_copy(number);
println("integer number after function call ", number);

let x = "hello";
takes_ownership(x);
println("string x after function call: ", x);
}

fn takes_ownership(s: String) {
println("Taken ownership of", s);
}

fn makes_copy(i: i64) {
println("Made a copy of ", i);
}
11 changes: 11 additions & 0 deletions examples/primitive_value_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main() {
let a = 2093;
let b = true;
let c = "help i am owned by c :(";
let d = (); // Unassigned
println("a is an integer: ", a);
println("b is a boolean: ", b);
println("c is an owned string: ", c);
println("d is unitliteral: ", d);
println("this is an immutable string");
}
1 change: 1 addition & 0 deletions examples/simple_assignment.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fn main() {
let x = 1;
println("x is ", x);
}
2 changes: 1 addition & 1 deletion examples/simple_binop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
1 + 2;
println("1 + 2 gives", 1 + 2);
}
2 changes: 1 addition & 1 deletion examples/simple_unop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
!true;
println("!true gives: ", !true);
}
8 changes: 8 additions & 0 deletions examples/string_concat_move_example1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let a = "hello";
let b = " world";
let c = a + b;
println("a should have moved: ", a);
println("b should remain since it was borrowed", b);
println("c is the new concatenated string", c);
}
6 changes: 6 additions & 0 deletions examples/string_concat_move_example2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let a = "hello";
let c = a + " world";
println("a should have moved: ", a);
println("c is the new concatenated string", c);
}
4 changes: 4 additions & 0 deletions examples/string_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let str = "bing chillin";
println(str);
}
6 changes: 6 additions & 0 deletions examples/string_move_example.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let a = "hello";
let b = a;
println(a);
println(b);
}
6 changes: 6 additions & 0 deletions examples/string_overwrite.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let a = "sad";
let b = " lol";
a = b;
println("a should have a changed value", a);
}
1 change: 1 addition & 0 deletions examples/while_loop_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fn main() {
while x > 0 {
println("decrementing {}", x);
x = x - 1;
let y = 12;
}
// if x > 0 {
// x = x - 1;
Expand Down
Loading

0 comments on commit bd38dad

Please sign in to comment.