aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authornickpdemarco <nickpdemarco@gmail.com>2023-10-11 14:43:05 -0400
committernickpdemarco <nickpdemarco@gmail.com>2023-10-11 14:43:05 -0400
commit9cda199e40c920fcc9c53082b0dabb17d31a8b7f (patch)
treea4e9a03a9feea17376f5990e19c12818d32ec95e /examples
parent55a2b1455f823026c78b9219f93799af00ef60ae (diff)
parent10796b3696cf1eef928de8c750b4d3350ee0c2db (diff)
downloadcompiler-explorer-9cda199e40c920fcc9c53082b0dabb17d31a8b7f.tar.gz
compiler-explorer-9cda199e40c920fcc9c53082b0dabb17d31a8b7f.zip
Merge main, resolve conflicts with vala
Diffstat (limited to 'examples')
-rw-r--r--examples/c3/default.c38
-rw-r--r--examples/jakt/default.jakt4
-rw-r--r--examples/javascript/default.mjs13
-rw-r--r--examples/mlir/default.mlir2
-rw-r--r--examples/snowball/default.sn15
-rw-r--r--examples/snowball/fib.sn24
-rw-r--r--examples/snowball/vectors.sn16
-rw-r--r--examples/v/Sum_over_array.v12
-rw-r--r--examples/v/default.v7
-rw-r--r--examples/v/helloworld.v3
-rw-r--r--examples/vala/default.vala7
11 files changed, 108 insertions, 3 deletions
diff --git a/examples/c3/default.c3 b/examples/c3/default.c3
new file mode 100644
index 000000000..5e043ff6f
--- /dev/null
+++ b/examples/c3/default.c3
@@ -0,0 +1,8 @@
+module output; // necessary for compiler explorer
+
+import std::io;
+
+fn void main()
+{
+ io::printfn("hello, world");
+}
diff --git a/examples/jakt/default.jakt b/examples/jakt/default.jakt
index 36108b2bf..0f8e0260e 100644
--- a/examples/jakt/default.jakt
+++ b/examples/jakt/default.jakt
@@ -1,7 +1,7 @@
-function square(num: i32) -> i32 {
+fn square(num: i32) -> i32 {
return num * num
}
-function main() throws -> c_int {
+fn main() throws -> c_int {
return square(num: 3) as! c_int
}
diff --git a/examples/javascript/default.mjs b/examples/javascript/default.mjs
new file mode 100644
index 000000000..ddd829344
--- /dev/null
+++ b/examples/javascript/default.mjs
@@ -0,0 +1,13 @@
+function square(a) {
+ let result = a * a;
+ return result;
+}
+
+// Call function once to fill type information
+square(23);
+
+// Call function again to go from uninitialized -> pre-monomorphic -> monomorphic
+square(13);
+%OptimizeFunctionOnNextCall(square);
+square(71);
+
diff --git a/examples/mlir/default.mlir b/examples/mlir/default.mlir
index 9b32f2ef9..ea63cb14e 100644
--- a/examples/mlir/default.mlir
+++ b/examples/mlir/default.mlir
@@ -2,7 +2,7 @@
// MLIR example code may not always work out of the box because the textual MLIR format is not stable.
// The example tries to be compatible with the latest MLIR version, which may not work on previous versions.
-func @affine_parallel_with_reductions_i64(%arg0: memref<3x3xi64>, %arg1: memref<3x3xi64>) -> (i64, i64) {
+func.func @affine_parallel_with_reductions_i64(%arg0: memref<3x3xi64>, %arg1: memref<3x3xi64>) -> (i64, i64) {
%0:2 = affine.parallel (%kx, %ky) = (0, 0) to (2, 2) reduce ("addi", "muli") -> (i64, i64) {
%1 = affine.load %arg0[%kx, %ky] : memref<3x3xi64>
%2 = affine.load %arg1[%kx, %ky] : memref<3x3xi64>
diff --git a/examples/snowball/default.sn b/examples/snowball/default.sn
new file mode 100644
index 000000000..fc3d208d0
--- /dev/null
+++ b/examples/snowball/default.sn
@@ -0,0 +1,15 @@
+// Snowball compiler (MIT) /l、
+// https://github.com/snowball-lang/snowball (゚、 。7
+// ⠀ l、゙~ヽ
+// Simple example for the lang じし(_,)ノ
+// Docs: https://snowball-lang.gitbook.io/docs/
+
+// Import the core library.
+// This is required for the println function.
+use Core::System;
+
+// The main function is the entry point of the program.
+// It is called when the program is started.
+pub fn main() i32 {
+ System::println("Hello, world!");
+}
diff --git a/examples/snowball/fib.sn b/examples/snowball/fib.sn
new file mode 100644
index 000000000..ef5fbaad4
--- /dev/null
+++ b/examples/snowball/fib.sn
@@ -0,0 +1,24 @@
+// Snowball compiler (MIT) /l、
+// https://github.com/snowball-lang/snowball (゚、 。7
+// ⠀ l、゙~ヽ
+// Fibonacci example for the lang じし(_,)ノ
+// Docs: https://snowball-lang.gitbook.io/docs/
+
+// Import the core library.
+// This is required for the println function.
+use Core::System;
+
+// Define a static function that calculates the nth Fibonacci number.
+// This is a recursive function.
+static fn [[inline]] fib(n: i64) i64 {
+ if n <= 1 {
+ return n
+ }
+
+ return fib(n-1) + fib(n-2)
+}
+
+// Define the main function.
+pub fn main() i32 {
+ System::println(fib(47 as i64))
+}
diff --git a/examples/snowball/vectors.sn b/examples/snowball/vectors.sn
new file mode 100644
index 000000000..1866abaf4
--- /dev/null
+++ b/examples/snowball/vectors.sn
@@ -0,0 +1,16 @@
+// Snowball compiler (MIT) /l、
+// https://github.com/snowball-lang/snowball (゚、 。7
+// ⠀ l、゙~ヽ
+// Vectors example for the lang じし(_,)ノ
+// Docs: https://snowball-lang.gitbook.io/docs/
+
+use Core::System;
+
+pub fn main() i32 {
+ let vec = new Vector<String>{};
+ let str = String::from("Hello, world!");
+ vec.push(str);
+
+ System::println(vec[0]);
+ System::println(vec.size());
+}
diff --git a/examples/v/Sum_over_array.v b/examples/v/Sum_over_array.v
new file mode 100644
index 000000000..96b5b90f8
--- /dev/null
+++ b/examples/v/Sum_over_array.v
@@ -0,0 +1,12 @@
+import arrays
+
+fn sum_array(array []int) !int {
+ return arrays.reduce(array, fn (acc int, i int) int {
+ return acc + i
+ })
+}
+
+fn main() {
+ a := [1, 2, 3, 4, 5]
+ println(sum_array(a) or { 0 })
+}
diff --git a/examples/v/default.v b/examples/v/default.v
new file mode 100644
index 000000000..4f99e15c3
--- /dev/null
+++ b/examples/v/default.v
@@ -0,0 +1,7 @@
+fn square(num int) int {
+ return num * num
+}
+
+fn main() {
+ println(square(3))
+}
diff --git a/examples/v/helloworld.v b/examples/v/helloworld.v
new file mode 100644
index 000000000..88a46c5c4
--- /dev/null
+++ b/examples/v/helloworld.v
@@ -0,0 +1,3 @@
+fn main() {
+ println('Hello, World!')
+}
diff --git a/examples/vala/default.vala b/examples/vala/default.vala
new file mode 100644
index 000000000..a1eb427fa
--- /dev/null
+++ b/examples/vala/default.vala
@@ -0,0 +1,7 @@
+int square (int num) {
+ return num * num;
+}
+
+static int main () {
+ return square (3);
+}