Explorar el Código

update

master
Daniel Ledda hace 1 semana
padre
commit
fb29608871
Se han modificado 3 ficheros con 14 adiciones y 24 borrados
  1. +1
    -18
      app.cpp
  2. +9
    -3
      core.cpp
  3. +4
    -3
      core.h

+ 1
- 18
app.cpp Ver fichero

@@ -8,24 +8,7 @@ int main(int argc, char **argv) {
Arena *arena = arenaAlloc(Megabytes(64));
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;
}

+ 9
- 3
core.cpp Ver fichero

@@ -1,9 +1,10 @@
#include <unistd.h> // TODO(djledda): get outta here
#include <math.h>
#include <string.h>
#define STB_SPRINTF_IMPLEMENTATION
#include <unistd.h>
#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<T> *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;
}


+ 4
- 3
core.h Ver fichero

@@ -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<char> 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 ###


Cargando…
Cancelar
Guardar