diff --git a/app.cpp b/app.cpp index 211f75f..d1a01a3 100644 --- a/app.cpp +++ b/app.cpp @@ -8,24 +8,7 @@ int main(int argc, char **argv) { Arena *arena = arenaAlloc(Megabytes(64)); list args = getArgs(arena, argc, argv); - log(strSplit(arena, "-"_s, "hallo-world"_s)); - - while (true) { - string line; - list split; - - WithScratch(temp) { - line = PushString(temp.arena, 128); - fgets(line.str, (int)line.length, stdin); - split = strSplit(temp.arena, "-"_s, line); - } - - if (line.str[0] == '\n' && line.str[1] == '\0') { - break; - } else { - log(split); - } - } + prinft("%S", strSplit(arena, "-"_s, "hallo-world"_s)); return statusCode; } diff --git a/core.cpp b/core.cpp index 1d85fc4..3e2f774 100644 --- a/core.cpp +++ b/core.cpp @@ -1,9 +1,10 @@ -#include // TODO(djledda): get outta here #include #include -#define STB_SPRINTF_IMPLEMENTATION +#include #include "core.h" #include "os.cpp" +#define STB_SPRINTF_IMPLEMENTATION +#include "vendor/stb_sprintf.h" void *pushSize(Arena *arena, size_t bytes) { if (arena->capacity - arena->head >= bytes) { @@ -30,6 +31,10 @@ void arenaFreeFrom(Arena *arena, size_t position) { arena->head = position; } +void arenaPopTo(Arena *arena, void *position) { + arena->head = (byte *)position - (byte *)arena->memory; +} + Arena *scratchArenas[2]; void initialiseCore() { @@ -86,7 +91,7 @@ void zeroList(list *list) { memset(list->data, 0, list->head * sizeof(T)); } -inline string operator""_s(const char *cstrLiteral, unsigned long length) { +inline string operator""_s(const char *cstrLiteral, size_t length) { return { (char *)cstrLiteral, length, @@ -292,6 +297,7 @@ real32 parsePositiveReal32(string str, size_t *lengthPointer) { *lengthPointer += 1; int fractionalPart = parsePositiveInt(fractionalPartStr, lengthPointer); if (wholePart >= 0 && fractionalPart >= 0) { + // TODO(dledda): implement powf with intrinsics? or just custom real32 fractionalPartMultiplier = 1.0f / powf(10.0f, (real32)fractionalPartStr.length); result = (real32)wholePart + (real32)fractionalPart * (real32)fractionalPartMultiplier; } diff --git a/core.h b/core.h index 60e4dde..5e796e7 100644 --- a/core.h +++ b/core.h @@ -60,6 +60,7 @@ void *pushSize(Arena *arena, size_t bytes); Arena *arenaAlloc(size_t capacity); void arenaFree(Arena *arena); void arenaFreeFrom(Arena *arena, size_t pos); +void arenaPopTo(Arena *arena, void *pos); void initialiseCore(); @@ -150,7 +151,7 @@ struct string { #define strlit(lit) (string{(char *)(lit), sizeof(lit) - 1}) #define PushString(arena, length) (string{ (char *)pushSize(arena, length), (length) }) -string operator""_s(const char *cstrLiteral, unsigned long length); +string operator""_s(const char *cstrLiteral, size_t length); // C Strings const char *cstring(Arena *arena, list buf); @@ -209,8 +210,8 @@ void log(const char *fmt, ...); void logError(const char *fmt, ...); // ### Loops ### -#define EachIn(list, it) size_t it = 0; it < list.length; it++ -#define EachInReversed(list, it) size_t it = list.length - 1; it >= 0 && it < list.length; it-- +#define EachIn(list, it) size_t it = 0; it < (list).head; it++ +#define EachInReversed(list, it) size_t it = (list).head - 1; it >= 0 && it < (list).head; it-- #define EachInArray(arr, it) size_t it = 0; it < ArrayCount(arr); ++it // ### Misc ###