Clean up
This commit is contained in:
@@ -114,7 +114,7 @@ void *arena_realloc(arena_t *arena, void *ptr, u64 oldsize, u64 newsize)
|
|||||||
// No need to change anything.
|
// No need to change anything.
|
||||||
return ptr;
|
return ptr;
|
||||||
|
|
||||||
bool copy_into_new = true;
|
bool copy_into_new = false;
|
||||||
void *start = NULL;
|
void *start = NULL;
|
||||||
page_t *old_page = NULL, *best_fit = NULL;
|
page_t *old_page = NULL, *best_fit = NULL;
|
||||||
|
|
||||||
@@ -134,12 +134,9 @@ void *arena_realloc(arena_t *arena, void *ptr, u64 oldsize, u64 newsize)
|
|||||||
{
|
{
|
||||||
start = ptr;
|
start = ptr;
|
||||||
old_page->size += newsize - oldsize;
|
old_page->size += newsize - oldsize;
|
||||||
copy_into_new = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!old_page)
|
|
||||||
copy_into_new = false;
|
|
||||||
if (!best_fit)
|
if (!best_fit)
|
||||||
{
|
{
|
||||||
best_fit = page_create(newsize);
|
best_fit = page_create(newsize);
|
||||||
@@ -149,6 +146,7 @@ void *arena_realloc(arena_t *arena, void *ptr, u64 oldsize, u64 newsize)
|
|||||||
|
|
||||||
start = best_fit->data + best_fit->size;
|
start = best_fit->data + best_fit->size;
|
||||||
best_fit->size += newsize;
|
best_fit->size += newsize;
|
||||||
|
copy_into_new = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_into_new)
|
if (copy_into_new)
|
||||||
|
|||||||
1
lib/sv.h
1
lib/sv.h
@@ -27,6 +27,7 @@ typedef struct SV
|
|||||||
#define SV(DATA, SIZE) ((const sv_t){.size = (SIZE), .data = (DATA)})
|
#define SV(DATA, SIZE) ((const sv_t){.size = (SIZE), .data = (DATA)})
|
||||||
#define SV_FMT(SV) (int)(SV).size, (SV).data
|
#define SV_FMT(SV) (int)(SV).size, (SV).data
|
||||||
#define PR_SV "%.*s"
|
#define PR_SV "%.*s"
|
||||||
|
#define PR_DEBUG_SV "%d@%p"
|
||||||
|
|
||||||
sv_t sv_make(arena_t *allocator, const char *data, u64 size);
|
sv_t sv_make(arena_t *allocator, const char *data, u64 size);
|
||||||
sv_t sv_copy(arena_t *allocator, sv_t sv);
|
sv_t sv_copy(arena_t *allocator, sv_t sv);
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ perr_t parse_sym(context_t *ctx, input_t *inp, lisp_t **ret)
|
|||||||
|
|
||||||
sv_t current = sv_cut(inp->str, inp->offset);
|
sv_t current = sv_cut(inp->str, inp->offset);
|
||||||
sv_t sym = sv_chop(current, sv_while(current, is_sym));
|
sv_t sym = sv_chop(current, sv_while(current, is_sym));
|
||||||
debug("`" PR_SV "`\n", SV_FMT(sym));
|
debug("`" PR_SV "` => ", SV_FMT(sym));
|
||||||
|
|
||||||
if (sym.size == 3)
|
if (sym.size == 3)
|
||||||
{
|
{
|
||||||
@@ -174,13 +174,14 @@ perr_t parse_sym(context_t *ctx, input_t *inp, lisp_t **ret)
|
|||||||
if (strncmp(buf, "NIL", 3) == 0)
|
if (strncmp(buf, "NIL", 3) == 0)
|
||||||
{
|
{
|
||||||
input_next(inp, 3);
|
input_next(inp, 3);
|
||||||
return NIL;
|
*ret = NIL;
|
||||||
|
return PERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lisp_t *lsym = make_sym(ctx, sym.data, sym.size);
|
*ret = make_sym(ctx, sym.data, sym.size);
|
||||||
|
debug("%#16lx\n", *ret);
|
||||||
input_next(inp, sym.size);
|
input_next(inp, sym.size);
|
||||||
*ret = lsym;
|
|
||||||
|
|
||||||
return PERR_OK;
|
return PERR_OK;
|
||||||
}
|
}
|
||||||
@@ -293,8 +294,9 @@ perr_t parse_str(context_t *ctx, input_t *inp, lisp_t **ret)
|
|||||||
|
|
||||||
input_next(inp, size + 1); // 1 for that last speechmark
|
input_next(inp, size + 1); // 1 for that last speechmark
|
||||||
sv_t str_content = sv_chop(sv, size);
|
sv_t str_content = sv_chop(sv, size);
|
||||||
debug("\"" PR_SV "\"\n", SV_FMT(str_content));
|
debug("\"" PR_SV "\" => ", SV_FMT(str_content));
|
||||||
*ret = make_str(ctx, str_content.data, str_content.size);
|
*ret = make_str(ctx, str_content.data, str_content.size);
|
||||||
|
debug("%#16lx\n", *ret);
|
||||||
return PERR_OK;
|
return PERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user