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,93 +1,93 @@
#include "nihilispm.h"
#include "nihilispm_internal.h"
#include "uclisp.h"
#include "internal.h"
#include <stddef.h>
#include <stdlib.h>
static struct nl_object *nl_object_alloc();
static struct ucl_object *ucl_object_alloc();
struct nl_object *nl_cell_create(struct nl_object *car, struct nl_object *cdr)
struct ucl_object *ucl_cell_create(struct ucl_object *car, struct ucl_object *cdr)
{
struct nl_object* obj = nl_object_alloc();
obj->type = NL_TYPE_CELL;
struct ucl_object* obj = ucl_object_alloc();
obj->type = UCL_TYPE_CELL;
obj->cell.car = car;
obj->cell.cdr = cdr;
return obj;
}
struct nl_object *nl_int_create(int integer)
struct ucl_object *ucl_int_create(int integer)
{
struct nl_object* obj = nl_object_alloc();
obj->type = NL_TYPE_INT;
struct ucl_object* obj = ucl_object_alloc();
obj->type = UCL_TYPE_INT;
obj->integer = integer;
return obj;
}
struct nl_object *nl_symbol_create(const char *symbol)
struct ucl_object *ucl_symbol_create(const char *symbol)
{
struct nl_object* obj = nl_object_alloc();
obj->type = NL_TYPE_SYMBOL;
struct ucl_object* obj = ucl_object_alloc();
obj->type = UCL_TYPE_SYMBOL;
obj->symbol = symbol;
return obj;
}
struct nl_object *nl_string_create(const char *string)
struct ucl_object *ucl_string_create(const char *string)
{
struct nl_object* obj = nl_object_alloc();
obj->type = NL_TYPE_STRING;
struct ucl_object* obj = ucl_object_alloc();
obj->type = UCL_TYPE_STRING;
obj->string = string;
return obj;
}
struct nl_object *nl_error_create(const char *error)
struct ucl_object *ucl_error_create(const char *error)
{
struct nl_object* obj = nl_object_alloc();
obj->type = NL_TYPE_ERROR;
struct ucl_object* obj = ucl_object_alloc();
obj->type = UCL_TYPE_ERROR;
obj->error = error;
return obj;
}
struct nl_object *nl_builtin_create(nl_builtin builtin)
struct ucl_object *ucl_builtin_create(ucl_builtin builtin)
{
struct nl_object* obj = nl_object_alloc();
obj->type = NL_TYPE_BUILTIN;
struct ucl_object* obj = ucl_object_alloc();
obj->type = UCL_TYPE_BUILTIN;
obj->builtin = builtin;
return obj;
}
static struct nl_object* nl_object_alloc() {
return malloc(sizeof(struct nl_object));
static struct ucl_object* ucl_object_alloc() {
return malloc(sizeof(struct ucl_object));
}
void nl_object_delete(struct nl_object *obj) {
void ucl_object_delete(struct ucl_object *obj) {
if (obj == NULL) {
return;
}
switch (obj->type) {
case NL_TYPE_CELL:
nl_object_delete(obj->cell.car);
case UCL_TYPE_CELL:
ucl_object_delete(obj->cell.car);
obj->cell.car = NULL;
nl_object_delete(obj->cell.cdr);
ucl_object_delete(obj->cell.cdr);
obj->cell.cdr = NULL;
break;
case NL_TYPE_SYMBOL:
case UCL_TYPE_SYMBOL:
free((void *) obj->symbol);
obj->symbol = NULL;
break;
case NL_TYPE_STRING:
case UCL_TYPE_STRING:
free((void *) obj->string);
obj->string = NULL;
break;
case NL_TYPE_ERROR:
case UCL_TYPE_ERROR:
free((void *) obj->error);
obj->error = NULL;
break;
case NL_TYPE_INT:
case NL_TYPE_BUILTIN:
case NL_TYPE_COUNT:
case UCL_TYPE_INT:
case UCL_TYPE_BUILTIN:
case UCL_TYPE_COUNT:
break;
}
free(obj);