Initial Commit
This commit is contained in:
789 files changed
+149185
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import std::io;
|
||||
struct counter { var count: int; }
|
||||
struct node { var value: int; var next: *node; }
|
||||
struct holder { val target: &mut counter; }
|
||||
def bump(c: &mut counter): void { c.count += 1; }
|
||||
def keep(c: &mut counter): holder { return holder{c}; }
|
||||
def length(list: *node): int {
|
||||
var count := 0;
|
||||
var at := list;
|
||||
while at != null { count++; at = (*at).next; }
|
||||
return count;
|
||||
}
|
||||
def make(given: &mut counter): holder {
|
||||
bump(given);
|
||||
return keep(given);
|
||||
}
|
||||
def main(): void {
|
||||
var n := counter{1};
|
||||
bump(&mut n);
|
||||
var made := counter{40};
|
||||
val h := make(&mut made);
|
||||
h.target.count += 1;
|
||||
var third := node{3, null};
|
||||
var second := node{2, &third as *node};
|
||||
val first := node{1, &second as *node};
|
||||
third.value = 30;
|
||||
val ref: &counter = &n;
|
||||
val alias := &ref;
|
||||
n.count++;
|
||||
println($"{n.count} {h.target.count} {length(&first as *node)} {(*(*first.next).next).value} {ref.count == 3} {alias.count} {h}");
|
||||
}
|
||||
Reference in new issue
Block a user