Initial Commit
This commit is contained in:
706 files changed
+135430
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import std::io;
|
||||
struct node { var value: int; var next: *mut node; }
|
||||
type block = *mut u8;
|
||||
def countdown(): int[5] {
|
||||
var head: *mut node = null;
|
||||
var blocks: block[5];
|
||||
for i in 0..5 {
|
||||
val made := raw_allocate(size_of::<node>()) as *mut node;
|
||||
(*made).value = i as int;
|
||||
(*made).next = head;
|
||||
head = made;
|
||||
blocks[i] = made as *mut u8;
|
||||
}
|
||||
var out: int[5];
|
||||
var at := head;
|
||||
var k := 0;
|
||||
while at != null { out[k] = (*at).value; k++; at = (*at).next; }
|
||||
for i in 0..5 { raw_release(blocks[i]); }
|
||||
return out;
|
||||
}
|
||||
def total(first: *int, count: u64): int {
|
||||
var sum := 0;
|
||||
for i in 0..count { sum += first[i]; }
|
||||
val last := first + (count - 1);
|
||||
return sum + (last - first) as int;
|
||||
}
|
||||
def summing(): int {
|
||||
var xs: int[4] = [1, 2, 3, 4];
|
||||
return total((&xs) as *int, 4);
|
||||
}
|
||||
def through_local(): int {
|
||||
var x := 5;
|
||||
val p := &mut x as *mut int;
|
||||
p[0] = 7;
|
||||
return x;
|
||||
}
|
||||
const down := countdown();
|
||||
const summed := summing();
|
||||
const written := through_local();
|
||||
def main(): void { println($"{down} {summed} {written}"); }
|
||||
Reference in new issue
Block a user