Skip to content

Commit

Permalink
New snowball syntax (#5738)
Browse files Browse the repository at this point in the history
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE
IT
Thanks for taking the time to improve CE. We really appreciate it.
Before opening the PR, please make sure that the tests & linter pass
their checks,
  by running `make check`.
In the best case scenario, you are also adding tests to back up your
changes,
  but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->
  • Loading branch information
mauro-balades committed Nov 14, 2023
1 parent 77870a3 commit 058dc15
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions examples/snowball/default.sn
Expand Up @@ -11,5 +11,11 @@ import Core::System;
// 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!");

// The return value of the main function is the exit code of the program.
// A value of 0 means that the program exited successfully.
return 0;
}
3 changes: 3 additions & 0 deletions examples/snowball/fib.sn
Expand Up @@ -21,5 +21,8 @@ static func fib(n: i64) i64 {

// 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))
}
7 changes: 5 additions & 2 deletions examples/snowball/testing.sn
@@ -1,13 +1,16 @@
// Snowball compiler (MIT) /l、
// https://github.com/snowball-lang/snowball (゚、 。7
// ⠀ l、゙~ヽ
// Vectors example for the lang じし(_,)ノ
// Testing snowball code example じし(_,)ノ
// Docs: https://snowball-lang.gitbook.io/docs/
// Note: Execute with `snowball test` command

// Give the function the `@test` attribute to make it a test function
// Test functions must return an integer
@test
func should_pass() i32 {
return 1;
}


// Will be overriden by the test function
public func main() i32 {}
13 changes: 11 additions & 2 deletions examples/snowball/vectors.sn
Expand Up @@ -4,12 +4,21 @@
// Vectors example for the lang じし(_,)ノ
// Docs: https://snowball-lang.gitbook.io/docs/

// This example shows how to use vectors in Snowball.
// 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;

public func main() i32 {
let vec = new Vector<String>{};
vec.push("Hello, world!");
// To create a vector, use the `new` keyword.
let mut vec = new Vector<i32>();

// To add an element to the vector, use the `push` method.
vec.push(42);

// 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());
}
2 changes: 1 addition & 1 deletion lib/languages.ts
Expand Up @@ -595,7 +595,7 @@ const definitions: Record<LanguageKey, LanguageDefinition> = {
},
snowball: {
name: 'Snowball',
monaco: 'nim',
monaco: 'swift',
extensions: ['.sn'],
alias: [],
logoUrl: 'snowball.svg',
Expand Down

0 comments on commit 058dc15

Please sign in to comment.