mirror of https://git.sr.ht/~garritfra/sabre
Garrit Franke
3 years ago
7 changed files with 65 additions and 60 deletions
@ -0,0 +1,27 @@ |
|||||||
|
// Prints the size of an array |
||||||
|
fn len(arr: int[]): int { |
||||||
|
let c: int = 0 |
||||||
|
while arr[c] { |
||||||
|
c += 1 |
||||||
|
} |
||||||
|
|
||||||
|
return c |
||||||
|
} |
||||||
|
|
||||||
|
// Reverses an array |
||||||
|
// TODO: fix me! |
||||||
|
fn rev(arr: int[]): int[] { |
||||||
|
|
||||||
|
let l: int = len(arr) |
||||||
|
let new_arr: int[] = [] |
||||||
|
|
||||||
|
let i: int = 0 |
||||||
|
let j: int = l |
||||||
|
while i < l { |
||||||
|
new_arr[i] = arr[j] |
||||||
|
i = i - 1 |
||||||
|
j = j - 1 |
||||||
|
} |
||||||
|
|
||||||
|
return new_arr |
||||||
|
} |
@ -0,0 +1,6 @@ |
|||||||
|
fn assert(condition: bool) { |
||||||
|
if condition == false { |
||||||
|
println("Assertion failed") |
||||||
|
exit(1) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
// Raw wrapper around _printf builtin function. |
||||||
|
// Writes the given content to stdout |
||||||
|
fn print(arg: string) { |
||||||
|
_printf(arg) |
||||||
|
} |
||||||
|
|
||||||
|
// Like print(), but with an extra newline ('\n') character |
||||||
|
fn println(msg: string) { |
||||||
|
print(msg + "\n") |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
// Exit the program immediately |
||||||
|
fn exit(code: int) { |
||||||
|
_exit(code) |
||||||
|
} |
@ -1,50 +0,0 @@ |
|||||||
// Raw wrapper around _printf builtin function. |
|
||||||
// Writes the given content to stdout |
|
||||||
fn print(arg: string) { |
|
||||||
_printf(arg) |
|
||||||
} |
|
||||||
|
|
||||||
// Like print(), but with an extra newline ('\n') character |
|
||||||
fn println(msg: string) { |
|
||||||
print(msg + "\n") |
|
||||||
} |
|
||||||
|
|
||||||
// Exit the program immediately |
|
||||||
fn exit(code: int) { |
|
||||||
_exit(code) |
|
||||||
} |
|
||||||
|
|
||||||
fn assert(condition: bool) { |
|
||||||
if condition == false { |
|
||||||
println("Assertion failed") |
|
||||||
exit(1) |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Prints the size of an array |
|
||||||
fn len(arr: int[]): int { |
|
||||||
let c: int = 0 |
|
||||||
while arr[c] { |
|
||||||
c += 1 |
|
||||||
} |
|
||||||
|
|
||||||
return c |
|
||||||
} |
|
||||||
|
|
||||||
// Reverses an array |
|
||||||
// TODO: fix me! |
|
||||||
fn rev(arr: int[]): int[] { |
|
||||||
|
|
||||||
let l: int = len(arr) |
|
||||||
let new_arr: int[] = [] |
|
||||||
|
|
||||||
let i: int = 0 |
|
||||||
let j: int = l |
|
||||||
while i < l { |
|
||||||
new_arr[i] = arr[j] |
|
||||||
i = i - 1 |
|
||||||
j = j - 1 |
|
||||||
} |
|
||||||
|
|
||||||
return new_arr |
|
||||||
} |
|
@ -0,0 +1,4 @@ |
|||||||
|
import "array" |
||||||
|
import "assert" |
||||||
|
import "io" |
||||||
|
import "os" |
Loading…
Reference in new issue