WIP: Hack in support for let binds
This commit is contained in:
17
src/state.c
17
src/state.c
@@ -12,12 +12,12 @@
|
||||
|
||||
struct ucl_state {
|
||||
struct ucl_object *list;
|
||||
struct ucl_state *parent;
|
||||
};
|
||||
|
||||
#define NAME_POSITION 0
|
||||
#define DATA_POSITION 1
|
||||
|
||||
|
||||
static struct ucl_object *ucl_state_get_cell(struct ucl_state *state, const char *name) {
|
||||
FOREACH_LIST(state->list, iter, item) {
|
||||
assert(item->type == UCL_TYPE_CELL);
|
||||
@@ -32,7 +32,13 @@ static struct ucl_object *ucl_state_get_cell(struct ucl_state *state, const char
|
||||
|
||||
struct ucl_object *ucl_state_get(struct ucl_state *state, const char *name) {
|
||||
struct ucl_object *cell = ucl_state_get_cell(state, name);
|
||||
UCL_COND_OR_RET_ERROR(cell != NULL, "Unknown name");
|
||||
if (cell == NULL) {
|
||||
if (state->parent == NULL) {
|
||||
return ucl_error_create(strdup("Unknown error"));
|
||||
} else {
|
||||
return ucl_state_get(state->parent, name);
|
||||
}
|
||||
}
|
||||
return ucl_list_nth(cell, DATA_POSITION);
|
||||
}
|
||||
|
||||
@@ -52,6 +58,13 @@ void ucl_state_put(struct ucl_state *state, const char *name, struct ucl_object
|
||||
struct ucl_state *ucl_state_create() {
|
||||
struct ucl_state *state = malloc(sizeof(struct ucl_state));
|
||||
state->list = ucl_nil_create();
|
||||
state->parent = NULL;
|
||||
return state;
|
||||
}
|
||||
|
||||
struct ucl_state *ucl_state_create_child(struct ucl_state *parent) {
|
||||
struct ucl_state *state = ucl_state_create();
|
||||
state->parent = parent;
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user