summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJohnny Richard <johnny@johnnyrichard.com>2023-05-17 15:31:24 +0200
committerJohnny Richard <johnny@johnnyrichard.com>2023-05-17 15:31:24 +0200
commit15196aa56339d34af9f74b019e6aeff5816e8dcc (patch)
treeffe7d6ec48bc6018b5eea7e9ef573cd1bbd57c2f /examples
parentad54ee1182b1549880eddc8b1969d3992d9f7f1d (diff)
parentea7f65fe1250be8f49edcaaedd3410aed1401648 (diff)
Merge commit 'ea7f65fe1250be8f49edcaaedd3410aed1401648' of https://git.sr.ht/~carlosmaniero/pipac-clone
Diffstat (limited to 'examples')
-rw-r--r--examples/fibbonacci.pipa10
-rw-r--r--examples/function_call.pipa11
-rw-r--r--examples/if.pipa78
3 files changed, 96 insertions, 3 deletions
diff --git a/examples/fibbonacci.pipa b/examples/fibbonacci.pipa
new file mode 100644
index 0000000..c19e65d
--- /dev/null
+++ b/examples/fibbonacci.pipa
@@ -0,0 +1,10 @@
+fn main(): i32 {
+ return fib(13);
+}
+
+fn fib(n: i32): i32 {
+ if n <= 1 {
+ return n;
+ }
+ return fib(n - 1) + fib(n - 2);
+}
diff --git a/examples/function_call.pipa b/examples/function_call.pipa
new file mode 100644
index 0000000..833c195
--- /dev/null
+++ b/examples/function_call.pipa
@@ -0,0 +1,11 @@
+fn add(n: i32, n2: i32): i32 {
+ return n + n2;
+}
+
+fn id(n: i32): i32 {
+ return n;
+}
+
+fn main(): i32 {
+ return id(add(40, 44)) / 2;
+}
diff --git a/examples/if.pipa b/examples/if.pipa
index 2c5578d..79f5724 100644
--- a/examples/if.pipa
+++ b/examples/if.pipa
@@ -1,8 +1,80 @@
fn main(): i32 {
- let n: i32 = 42;
+ let n: i32 = 11;
- if n > 42 {
- return 42;
+ let falsy: bool = false || n == 11 && n > 11;
+ let truth: bool = n + 1 > 11 && n - 1 < 11;
+ let literal_falsy: bool = false;
+
+ if falsy {
+ return 201;
+ }
+
+ if literal_falsy {
+ return 200;
+ }
+
+ if (n == 11) {
+ if n != 12 {
+ if n < 12 {
+ if n <= 11 {
+ if n > 10 {
+ if n >= 11 {
+ if n >= 11 || n < 11 {
+ if n > 11 || n < 11 {
+ return 199;
+ }
+ if n > 11 || n <= 11 {
+ if false || false {
+ return 199;
+ }
+ if true || false {
+ if false || true {
+ if true && false {
+ return 197;
+ }
+ if false && true {
+ return 196;
+ }
+ if true && true {
+ if n >= 11 && n < 11 || n == 11 {
+ if false || n == 11 && n > 11 {
+ return 195;
+ }
+ if false || n >= 11 && n <= 11 {
+ if false || false && false && false || true {
+ if n + 1 > 11 && n - 1 < 11 {
+ if truth {
+ return 42;
+ }
+ return 14;
+ }
+ return 13;
+ }
+ return 12;
+ }
+ return 11;
+ }
+ return 10;
+ }
+ return 9;
+ }
+ return 8;
+ }
+ return 7;
+ }
+ return 6;
+ }
+ return 5;
+ }
+ return 4;
+ }
+ return 3;
+ }
+ return 2;
+ }
+ return 1;
+ }
+ return 0;
}
return n;