Refactor with new name uclisp

This commit is contained in:
2022-10-28 23:19:19 -04:00
parent 26a0d17074
commit d97be8ec4b
22 changed files with 596 additions and 580 deletions

View File

@@ -1,7 +1,7 @@
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "nihilispm_state.h"
#include "nihilispm_utility.h"
#include "uclisp.h"
#include "internal.h"
#include "state.h"
#include "utility.h"
#include <assert.h>
#include <string.h>
@@ -10,18 +10,18 @@
// Implements state as a giant alist
// TODO: Consider generalizing the alist concept
struct nl_state {
struct nl_object *list;
struct ucl_state {
struct ucl_object *list;
};
#define NAME_POSITION 0
#define DATA_POSITION 1
static struct nl_object *nl_state_get_cell(struct nl_state *state, const char *name) {
static struct ucl_object *ucl_state_get_cell(struct ucl_state *state, const char *name) {
FOREACH_LIST(state->list, iter, item) {
assert(item->type == NL_TYPE_CELL);
const char *item_name = nl_list_nth(item, NAME_POSITION)->string;
assert(item->type == UCL_TYPE_CELL);
const char *item_name = ucl_list_nth(item, NAME_POSITION)->string;
if (!strcmp(name, item_name)) {
return item;
}
@@ -30,18 +30,18 @@ static struct nl_object *nl_state_get_cell(struct nl_state *state, const char *n
return NULL;
}
struct nl_object *nl_state_get(struct nl_state *state, const char *name) {
struct nl_object *cell = nl_state_get_cell(state, name);
NL_COND_OR_RET_ERROR(cell != NULL, "Unknown name");
return nl_list_nth(cell, DATA_POSITION);
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");
return ucl_list_nth(cell, DATA_POSITION);
}
void nl_state_put(struct nl_state *state, const char *name, struct nl_object *obj) {
struct nl_object *cell = nl_state_get_cell(state, name);
void ucl_state_put(struct ucl_state *state, const char *name, struct ucl_object *obj) {
struct ucl_object *cell = ucl_state_get_cell(state, name);
if (cell == NULL) {
nl_list_append(state->list,
nl_tuple_create(
nl_string_create(strdup(name)),
ucl_list_append(state->list,
ucl_tuple_create(
ucl_string_create(strdup(name)),
obj));
} else {
// TODO: Refcounting / cleanup
@@ -49,12 +49,12 @@ void nl_state_put(struct nl_state *state, const char *name, struct nl_object *ob
}
}
struct nl_state *nl_state_create() {
struct nl_state *state = malloc(sizeof(struct nl_state));
state->list = nl_nil_create();
struct ucl_state *ucl_state_create() {
struct ucl_state *state = malloc(sizeof(struct ucl_state));
state->list = ucl_nil_create();
return state;
}
void nl_state_delete(struct nl_state *state) {
nl_object_delete(state->list);
void ucl_state_delete(struct ucl_state *state) {
ucl_object_delete(state->list);
}