Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #14

Merged
merged 2 commits into from
Jul 29, 2024
Merged

Dev #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ target_sources(paw
${PAW_SOURCE_DIR}/auxlib.h
${PAW_SOURCE_DIR}/call.h
${PAW_SOURCE_DIR}/code.h
${PAW_SOURCE_DIR}/compile.h
${PAW_SOURCE_DIR}/debug.h
${PAW_SOURCE_DIR}/env.h
${PAW_SOURCE_DIR}/gc_aux.h
${PAW_SOURCE_DIR}/hir.h
${PAW_SOURCE_DIR}/lex.h
${PAW_SOURCE_DIR}/lib.h
${PAW_SOURCE_DIR}/map.h
Expand All @@ -71,9 +73,11 @@ target_sources(paw
${PAW_SOURCE_DIR}/check.c
${PAW_SOURCE_DIR}/code.c
${PAW_SOURCE_DIR}/codegen.c
${PAW_SOURCE_DIR}/compile.c
${PAW_SOURCE_DIR}/debug.c
${PAW_SOURCE_DIR}/env.c
${PAW_SOURCE_DIR}/gc_aux.c
${PAW_SOURCE_DIR}/hir.c
#${PAW_SOURCE_DIR}/iolib.c
${PAW_SOURCE_DIR}/lex.c
${PAW_SOURCE_DIR}/lib.c
Expand Down
23 changes: 12 additions & 11 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "lib.h"
#include "map.h"
#include "mem.h"
#include "parse.h"
#include "compile.h"
#include "paw.h"
#include "rt.h"
#include "str.h"
Expand All @@ -29,7 +29,8 @@ static void *default_alloc(void *ud, void *ptr, size_t size0, size_t size)
return GC_MALLOC(size);
// return malloc(size);
} else if (size == 0) {
free(ptr);
GC_FREE(ptr);
// free(ptr);
return NULL;
}
return GC_REALLOC(ptr, size);
Expand Down Expand Up @@ -252,29 +253,29 @@ void paw_pop(paw_Env *P, int n)
pawC_stkdec(P, n);
}

struct ParseState {
struct CompileState {
paw_Reader input;
ParseMemory mem;
struct DynamicMem dm;
const char *name;
void *ud;
};

static void parse_aux(paw_Env *P, void *arg)
static void compile_aux(paw_Env *P, void *arg)
{
struct ParseState *p = arg;
pawP_parse(P, p->input, &p->mem, p->name, p->ud);
struct CompileState *p = arg;
pawP_compile(P, p->input, &p->dm, p->name, p->ud);
}

int paw_load(paw_Env *P, paw_Reader input, const char *name, void *ud)
{
struct ParseState p = {
struct CompileState p = {
.input = input,
.name = name,
.ud = ud,
};
const int status = pawC_try(P, parse_aux, &p);
pawM_free_vec(P, p.mem.scratch.data, p.mem.scratch.alloc);
pawM_free_vec(P, p.mem.labels.values, p.mem.labels.capacity);
const int status = pawC_try(P, compile_aux, &p);
pawM_free_vec(P, p.dm.scratch.data, p.dm.scratch.alloc);
pawM_free_vec(P, p.dm.labels.values, p.dm.labels.capacity);
return status;
}

Expand Down
Loading
Loading