aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMustafa Quraish <[email protected]>2022-02-01 04:08:59 -0500
committerMustafa Quraish <[email protected]>2022-02-01 04:08:59 -0500
commitd471a41369690a9d2d9b8862ea5ff0ae9cbe40fc (patch)
tree9399d12700c3d975a95b0946833dc419b3268419 /examples
parentTesting: Add support for testing stdout results, check builtins (diff)
downloadcup-d471a41369690a9d2d9b8862ea5ff0ae9cbe40fc.tar.xz
cup-d471a41369690a9d2d9b8862ea5ff0ae9cbe40fc.zip
Add basic `defer` implementation.
We don't have any closures yet, so it's essentially the same as just moving the statement after the `defer` keyword to the end of the block/ right before returning from the function.
Diffstat (limited to 'examples')
-rw-r--r--examples/defer.cup13
1 files changed, 13 insertions, 0 deletions
diff --git a/examples/defer.cup b/examples/defer.cup
new file mode 100644
index 0000000..e8e4778
--- /dev/null
+++ b/examples/defer.cup
@@ -0,0 +1,13 @@
+fn main() {
+ defer print(1);
+ {
+ defer print(2);
+ {
+ defer print(3);
+ print(4);
+ }
+ print(5);
+ return 0;
+ }
+ print(10);
+} \ No newline at end of file