quicksort example, I64.parse, IO.write_file
This commit is contained in:
16
src/std.zr
16
src/std.zr
@@ -8,13 +8,13 @@ func print[x: String] : I64
|
||||
func print_i64[x: I64] : I64
|
||||
printf("%ld\n", x)
|
||||
|
||||
func concat[a: String, b: String] : String
|
||||
func String.concat[a: String, b: String] : String
|
||||
let c: String = malloc(strlen(a) + strlen(b) + 1)
|
||||
strcpy(c, a)
|
||||
strcat(c, b)
|
||||
return c
|
||||
|
||||
func substr[s: String, start: I64, length: I64] : String
|
||||
func String.substr[s: String, start: I64, length: I64] : String
|
||||
let out: String = malloc(length + 1)
|
||||
strlcpy(out, s + start, length + 1)
|
||||
return out
|
||||
@@ -42,8 +42,17 @@ func IO.read_file[path: String]: String
|
||||
|
||||
let n: I64 = fread(buffer, 1, size, file)
|
||||
String.set(buffer, n, 0)
|
||||
fclose(file)
|
||||
return buffer
|
||||
|
||||
func IO.write_file[path: String, content: String] : I64
|
||||
let file: Ptr = fopen(path, "wb")
|
||||
if !file
|
||||
panic("failed to open file")
|
||||
|
||||
fwrite(content, 1, strlen(content), file)
|
||||
fclose(file)
|
||||
|
||||
func Char.to_i64[c: Char]: I64
|
||||
return c - 48
|
||||
|
||||
@@ -52,6 +61,9 @@ func I64.to_string[n: I64] : String
|
||||
sprintf(x, "%ld", n)
|
||||
return x
|
||||
|
||||
func I64.parse[s: String] : I64
|
||||
return strtol(s, 0, 0)
|
||||
|
||||
func Math.gcd[a: I64, b: I64] : I64
|
||||
while b != 0
|
||||
let tmp: I64 = b
|
||||
|
||||
Reference in New Issue
Block a user