@@ -8,24 +8,7 @@ int main(int argc, char **argv) { | |||||
Arena *arena = arenaAlloc(Megabytes(64)); | Arena *arena = arenaAlloc(Megabytes(64)); | ||||
list<string> args = getArgs(arena, argc, argv); | list<string> args = getArgs(arena, argc, argv); | ||||
log(strSplit(arena, "-"_s, "hallo-world"_s)); | |||||
while (true) { | |||||
string line; | |||||
list<string> 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; | return statusCode; | ||||
} | } |
@@ -1,9 +1,10 @@ | |||||
#include <unistd.h> // TODO(djledda): get outta here | |||||
#include <math.h> | #include <math.h> | ||||
#include <string.h> | #include <string.h> | ||||
#define STB_SPRINTF_IMPLEMENTATION | |||||
#include <unistd.h> | |||||
#include "core.h" | #include "core.h" | ||||
#include "os.cpp" | #include "os.cpp" | ||||
#define STB_SPRINTF_IMPLEMENTATION | |||||
#include "vendor/stb_sprintf.h" | |||||
void *pushSize(Arena *arena, size_t bytes) { | void *pushSize(Arena *arena, size_t bytes) { | ||||
if (arena->capacity - arena->head >= bytes) { | if (arena->capacity - arena->head >= bytes) { | ||||
@@ -30,6 +31,10 @@ void arenaFreeFrom(Arena *arena, size_t position) { | |||||
arena->head = position; | arena->head = position; | ||||
} | } | ||||
void arenaPopTo(Arena *arena, void *position) { | |||||
arena->head = (byte *)position - (byte *)arena->memory; | |||||
} | |||||
Arena *scratchArenas[2]; | Arena *scratchArenas[2]; | ||||
void initialiseCore() { | void initialiseCore() { | ||||
@@ -86,7 +91,7 @@ void zeroList(list<T> *list) { | |||||
memset(list->data, 0, list->head * sizeof(T)); | 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 { | return { | ||||
(char *)cstrLiteral, | (char *)cstrLiteral, | ||||
length, | length, | ||||
@@ -292,6 +297,7 @@ real32 parsePositiveReal32(string str, size_t *lengthPointer) { | |||||
*lengthPointer += 1; | *lengthPointer += 1; | ||||
int fractionalPart = parsePositiveInt(fractionalPartStr, lengthPointer); | int fractionalPart = parsePositiveInt(fractionalPartStr, lengthPointer); | ||||
if (wholePart >= 0 && fractionalPart >= 0) { | if (wholePart >= 0 && fractionalPart >= 0) { | ||||
// TODO(dledda): implement powf with intrinsics? or just custom | |||||
real32 fractionalPartMultiplier = 1.0f / powf(10.0f, (real32)fractionalPartStr.length); | real32 fractionalPartMultiplier = 1.0f / powf(10.0f, (real32)fractionalPartStr.length); | ||||
result = (real32)wholePart + (real32)fractionalPart * (real32)fractionalPartMultiplier; | result = (real32)wholePart + (real32)fractionalPart * (real32)fractionalPartMultiplier; | ||||
} | } | ||||
@@ -60,6 +60,7 @@ void *pushSize(Arena *arena, size_t bytes); | |||||
Arena *arenaAlloc(size_t capacity); | Arena *arenaAlloc(size_t capacity); | ||||
void arenaFree(Arena *arena); | void arenaFree(Arena *arena); | ||||
void arenaFreeFrom(Arena *arena, size_t pos); | void arenaFreeFrom(Arena *arena, size_t pos); | ||||
void arenaPopTo(Arena *arena, void *pos); | |||||
void initialiseCore(); | void initialiseCore(); | ||||
@@ -150,7 +151,7 @@ struct string { | |||||
#define strlit(lit) (string{(char *)(lit), sizeof(lit) - 1}) | #define strlit(lit) (string{(char *)(lit), sizeof(lit) - 1}) | ||||
#define PushString(arena, length) (string{ (char *)pushSize(arena, length), (length) }) | #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 | // C Strings | ||||
const char *cstring(Arena *arena, list<char> buf); | const char *cstring(Arena *arena, list<char> buf); | ||||
@@ -209,8 +210,8 @@ void log(const char *fmt, ...); | |||||
void logError(const char *fmt, ...); | void logError(const char *fmt, ...); | ||||
// ### Loops ### | // ### 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 | #define EachInArray(arr, it) size_t it = 0; it < ArrayCount(arr); ++it | ||||
// ### Misc ### | // ### Misc ### | ||||