From b4ca920fa5644994cacec18e736cfa4796f4145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mauro=20Balad=C3=A9s?= Date: Mon, 15 Jan 2024 22:18:59 +0100 Subject: [PATCH] Updated examples and changed to snowball 0.1.0 (#5969) --- etc/config/snowball.amazon.properties | 8 ++++---- etc/config/snowball.default.properties | 8 ++++---- examples/snowball/class.sn | 28 ++++++++++++++++++++++++++ examples/snowball/default.sn | 4 ++-- examples/snowball/fib.sn | 28 -------------------------- examples/snowball/num_hex.sn | 10 ++++----- examples/snowball/vectors.sn | 6 +++--- 7 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 examples/snowball/class.sn delete mode 100644 examples/snowball/fib.sn diff --git a/etc/config/snowball.amazon.properties b/etc/config/snowball.amazon.properties index 0308842d9..9ecdecf28 100644 --- a/etc/config/snowball.amazon.properties +++ b/etc/config/snowball.amazon.properties @@ -1,7 +1,7 @@ compilers=&snowball objdumper=/opt/compiler-explorer/gcc-11.1.0/bin/objdump -defaultCompiler=snowball08 +defaultCompiler=snowballv010 supportsExecute=true # TODO: @@ -11,7 +11,7 @@ supportsDemangler=false #buildenvsetup=ceconan #buildenvsetup.host=https://conan.compiler-explorer.com -group.snowball.compilers=snowball08 +group.snowball.compilers=snowballv010 group.snowball.compilerType=snowball group.snowball.isSemVer=true group.snowball.baseName=snowball @@ -22,5 +22,5 @@ group.snowball.supportsBinary=true group.snowball.supportsBinaryObject=true # \_0_/ -compiler.snowball08.exe=/opt/compiler-explorer/snowball-0.0.8/bin/snowball -compiler.snowball08.semver=0.0.8 +compiler.snowballv010.exe=/opt/compiler-explorer/snowball-0.1.0/bin/snowball +compiler.snowballv010.semver=0.0.8 diff --git a/etc/config/snowball.default.properties b/etc/config/snowball.default.properties index e1ca0180c..7a1542be3 100644 --- a/etc/config/snowball.default.properties +++ b/etc/config/snowball.default.properties @@ -9,7 +9,7 @@ supportsBinaryObject=true supportsExecute=true supportsDemangler=false -group.snowball.compilers=snowball08 +group.snowball.compilers=snowballv010 group.snowball.compilerType=snowball group.snowball.isSemVer=true group.snowball.baseName=snowball @@ -24,6 +24,6 @@ group.snowball.supportsBinaryObject=true # Installed libs (See c++.amazon.properties for a scheme of libs group) libs= -compiler.snowball08.exe=/opt/compiler-explorer/snowball-0.0.8/bin/snowball -compiler.snowball08.semver=0.0.8 -compiler.snowball08.name=snowball 0.0.8 +compiler.snowballv010.exe=/opt/compiler-explorer/snowball-0.1.0/bin/snowball +compiler.snowballv010.semver=0.1.0 +compiler.snowballv010.name=snowball 0.1.0 diff --git a/examples/snowball/class.sn b/examples/snowball/class.sn new file mode 100644 index 000000000..82b9f7491 --- /dev/null +++ b/examples/snowball/class.sn @@ -0,0 +1,28 @@ +// Snowball compiler (MIT) /l、 +// https://github.com/snowball-lang/snowball (゚、 。7 +// ⠀ l、゙~ヽ +// Classes example for the snowball じし(_,)ノ +// Docs: https://snowball-lang.gitbook.io/docs/ + +// Import the core library. +// This is required for the println function. +import std::io; + +// Defining a simple class with a constructor, +// a member and a method +class User { + let name: String; // < user name (private) + public: + User(name: String) : name(name) {} + + @inline + func getName() String { + return self.name; + } +} + +// Define the main function. +public func main() i32 { + let user = new User("goofy-dog-123"); + io::println(user.getName()); +} diff --git a/examples/snowball/default.sn b/examples/snowball/default.sn index 20e0ff7b5..c705eac7c 100644 --- a/examples/snowball/default.sn +++ b/examples/snowball/default.sn @@ -6,14 +6,14 @@ // Import the core library. // This is required for the println function. -import Core::System; +import std::io; // The main function is the entry point of the program. // It is called when the program is started. public func main() i32 { // This is a function from the standard library. // It prints the given string to the console. - System::println("Hello, world!"); + io::println("Hello, world!"); // The return value of the main function is the exit code of the program. // A value of 0 means that the program exited successfully. diff --git a/examples/snowball/fib.sn b/examples/snowball/fib.sn deleted file mode 100644 index 3bb3a05e0..000000000 --- a/examples/snowball/fib.sn +++ /dev/null @@ -1,28 +0,0 @@ -// 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. -import Core::System; - -// Define a static function that calculates the nth Fibonacci number. -// This is a recursive function. -@inline -static func fib(n: i64) i64 { - if n <= 1 { - return n - } - - return fib(n-1) + fib(n-2) -} - -// Define the main function. -public func main() i32 { - // Print the 47th Fibonacci number. - // Note: This will take a while to execute. - // Snowball converts automatically between i64 to string. - System::println(fib(47 as i64)) -} diff --git a/examples/snowball/num_hex.sn b/examples/snowball/num_hex.sn index b3262f863..b6a0d2c5c 100644 --- a/examples/snowball/num_hex.sn +++ b/examples/snowball/num_hex.sn @@ -6,7 +6,7 @@ // Import the core library. // This is required for the println function. -import Core::System; +import std::io; // The main function is the entry point of the program. // It is called when the program is started. @@ -15,8 +15,8 @@ public func main() i32 { // It prints the given string to the console. // Let's convert the some numbers to hexadecimal. - System::println(87612.hex()); - System::println(0x1234.hex()); - System::println(0b10101010.hex()); - System::println(0XFFAA.hex()); + io::println(87612.hex()); + io::println(0x1234.hex()); + io::println(0b10101010.hex()); + io::println(0XFFAA.hex()); } diff --git a/examples/snowball/vectors.sn b/examples/snowball/vectors.sn index 2e9488a1d..6389647b5 100644 --- a/examples/snowball/vectors.sn +++ b/examples/snowball/vectors.sn @@ -8,7 +8,7 @@ // Vectors are dynamic arrays that can be resized at runtime. // They are generic, so you can store any type of data in them. -import Core::System; +import std::io; public func main() i32 { let mut vec = new Vector(); @@ -18,6 +18,6 @@ public func main() i32 { // To get the size of the vector, use the `size` method. // To get an element from the vector, use the `[]` operator. - System::println(vec[0]); - System::println(vec.size()); + io::println(vec[0]); + io::println(vec.size()); }