aboutsummaryrefslogtreecommitdiff
path: root/examples/opt_test.zc
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opt_test.zc')
-rw-r--r--examples/opt_test.zc25
1 files changed, 14 insertions, 11 deletions
diff --git a/examples/opt_test.zc b/examples/opt_test.zc
index c581283..e310690 100644
--- a/examples/opt_test.zc
+++ b/examples/opt_test.zc
@@ -1,8 +1,11 @@
+namespace;
+include rt;
+
// a tour of the compiler's optimization hints. the program is valid and runs;
// the hints only show up in the editor (or the lsp cli), never in a normal build.
// each function below triggers one of them.
-fn sink(.d p) { free(d*p); return 0; }
+void sink(.d p) { rt.free(p); return; }
// a variable that is written and never read
fn dead() {
@@ -26,9 +29,9 @@ fn magic(n) { return n + 1234; }
fn looping() {
let i = 0;
while (i < 3) {
- let buf = new(10);
+ let buf = rt.new(10);
buf[0] = i;
- sink(d*buf);
+ sink(buf);
i++;
}
return i;
@@ -36,19 +39,19 @@ fn looping() {
// a small buffer that never leaves the function can live on the stack
fn scratch() {
- let buf = new(8);
+ let buf = rt.new(8);
buf[0] = 7;
return buf[0];
}
// a consuming call takes the object after its allocation
-fn handoff() {
- let tmp = new(4);
- sink(d*tmp);
- return 0;
+void handoff() {
+ let tmp = rt.new(4);
+ sink(tmp);
+ return;
}
-fn main() {
- put_n(dead() + constant() + shifty(2) + magic(0) + looping() + scratch() + handoff()); put_c(10);
- return 0;
+void main() {
+ rt.put_n(dead() + constant() + shifty(2) + magic(0) + looping() + scratch()); handoff(); rt.put_c(10);
+ return;
}