-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added implicit destruct to assignment; Updated README.
- Loading branch information
Showing
20 changed files
with
432 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import stdlib.c.cstdlib | ||
import stdlib.string | ||
|
||
struct str_build | ||
str_build_len: int64 | ||
str_build_size: int64 | ||
str_build_cs: c_str | ||
end | ||
|
||
fun str_build(size: int64) | ||
let cs = alloc_size(size, true) | ||
ret str_build(0, size, cs) | ||
end | ||
|
||
fun len(sb: str_build&) | ||
ret sb.str_build_len | ||
end | ||
|
||
fun capacity(sb: str_build&) | ||
ret sb.str_build_size | ||
end | ||
|
||
fun to_str(sb: str_build&) | ||
ret str(sb.str_build_cs) | ||
end | ||
|
||
fun to_cstr(sb: str_build&) | ||
let dupl = alloc_size(sb.len) | ||
let src = sb.str_build_cs | ||
memcpy(src, dupl, sb.str_build_len) | ||
|
||
ret dupl | ||
end | ||
|
||
fun append(sb: str_build&, ch: int8) | ||
if sb.len == sb.capacity | ||
panicf("Attempt to append character %c to max-capacity str_build\n", ch) | ||
end | ||
|
||
sb.str_build_cs[sb.str_build_len] = ch | ||
sb.str_build_len = sb.str_build_len + 1 | ||
|
||
ret sb | ||
end | ||
|
||
fun append(sb: str_build&, cs: int8*) | ||
let cs_len = strlen(cs) | ||
if sb.len + cs_len == sb.capacity | ||
panicf("Attempt to append c string '%s' to max-capacity str_build\n", cs) | ||
end | ||
|
||
for it in range(cs_len) | ||
sb.append(cs[it]) | ||
end | ||
|
||
ret sb | ||
end | ||
|
||
fun append(sb: str_build&, s: str&) | ||
let s_len = s.len | ||
if sb.len + s_len == sb.capacity | ||
panicf("Attempt to append string '%s' to max-capacity str_build\n", c_str(s)) | ||
end | ||
|
||
ret sb.append(c_str(s)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
#ifndef ML_ALLOC_H | ||
#define ML_ALLOC_H | ||
#define ML_ALLOC_GC | ||
|
||
#ifndef ML_ALLOC_GC | ||
GarbageCollector ml_gc; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.