Refactor with new name uclisp
This commit is contained in:
@@ -1,61 +1,61 @@
|
||||
#include "nihilispm.h"
|
||||
#include "nihilispm_internal.h"
|
||||
#include "nihilispm_utility.h"
|
||||
#include "uclisp.h"
|
||||
#include "internal.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
struct nl_object *nl_car(struct nl_object *list) {
|
||||
NL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == NL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'nl_car'");
|
||||
struct ucl_object *ucl_car(struct ucl_object *list) {
|
||||
UCL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == UCL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'ucl_car'");
|
||||
|
||||
struct nl_object *car = list->cell.car;
|
||||
struct ucl_object *car = list->cell.car;
|
||||
if (car == NULL) {
|
||||
return nl_nil_create();
|
||||
return ucl_nil_create();
|
||||
}
|
||||
|
||||
return car;
|
||||
}
|
||||
|
||||
struct nl_object *nl_cdr(struct nl_object *list) {
|
||||
NL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == NL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'nl_cdr'");
|
||||
struct ucl_object *ucl_cdr(struct ucl_object *list) {
|
||||
UCL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == UCL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'ucl_cdr'");
|
||||
|
||||
struct nl_object *cdr = list->cell.cdr;
|
||||
struct ucl_object *cdr = list->cell.cdr;
|
||||
if (cdr == NULL) {
|
||||
return nl_nil_create();
|
||||
return ucl_nil_create();
|
||||
}
|
||||
|
||||
return cdr;
|
||||
}
|
||||
|
||||
struct nl_object *nl_nil_create() {
|
||||
return nl_cell_create(NULL, NULL);
|
||||
struct ucl_object *ucl_nil_create() {
|
||||
return ucl_cell_create(NULL, NULL);
|
||||
}
|
||||
|
||||
struct nl_object *nl_t_create() {
|
||||
return nl_symbol_create(strdup("t"));
|
||||
struct ucl_object *ucl_t_create() {
|
||||
return ucl_symbol_create(strdup("t"));
|
||||
}
|
||||
|
||||
struct nl_object *nl_predicate(bool value) {
|
||||
struct ucl_object *ucl_predicate(bool value) {
|
||||
if (value) {
|
||||
return nl_t_create();
|
||||
return ucl_t_create();
|
||||
} else {
|
||||
return nl_nil_create();
|
||||
return ucl_nil_create();
|
||||
}
|
||||
}
|
||||
|
||||
struct nl_object *nl_list_length(struct nl_object *list) {
|
||||
NL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == NL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'nl_list_length'");
|
||||
struct ucl_object *ucl_list_length(struct ucl_object *list) {
|
||||
UCL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == UCL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'ucl_list_length'");
|
||||
|
||||
struct nl_object *node = list;
|
||||
struct ucl_object *node = list;
|
||||
if (list->cell.car == NULL) {
|
||||
return nl_int_create(0);
|
||||
return ucl_int_create(0);
|
||||
}
|
||||
|
||||
int length = 1;
|
||||
@@ -64,18 +64,18 @@ struct nl_object *nl_list_length(struct nl_object *list) {
|
||||
length++;
|
||||
}
|
||||
|
||||
return nl_int_create(length);
|
||||
return ucl_int_create(length);
|
||||
}
|
||||
|
||||
struct nl_object *nl_list_nth(struct nl_object *list, int n) {
|
||||
NL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == NL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'nl_list_'");
|
||||
struct ucl_object *ucl_list_nth(struct ucl_object *list, int n) {
|
||||
UCL_COND_OR_RET_ERROR(
|
||||
list != NULL && list->type == UCL_TYPE_CELL,
|
||||
"Invalid type of argument 0 to 'ucl_list_'");
|
||||
|
||||
int length = nl_list_length(list)->integer;
|
||||
NL_COND_OR_RET_ERROR(length > n, "Position n >= list length in nl_list_nth");
|
||||
int length = ucl_list_length(list)->integer;
|
||||
UCL_COND_OR_RET_ERROR(length > n, "Position n >= list length in ucl_list_nth");
|
||||
|
||||
struct nl_object *node = list;
|
||||
struct ucl_object *node = list;
|
||||
for (int i = 0; i < n; i++) {
|
||||
node = node->cell.cdr;
|
||||
}
|
||||
@@ -83,19 +83,19 @@ struct nl_object *nl_list_nth(struct nl_object *list, int n) {
|
||||
return node->cell.car;
|
||||
}
|
||||
|
||||
struct nl_object *nl_truthy(struct nl_object *obj) {
|
||||
struct ucl_object *ucl_truthy(struct ucl_object *obj) {
|
||||
// TODO: Implement me
|
||||
return nl_error_create("Unimplemented function 'nl_truthy'");
|
||||
return ucl_error_create("Unimplemented function 'ucl_truthy'");
|
||||
}
|
||||
|
||||
struct nl_object *nl_tuple_create(struct nl_object *obj0, struct nl_object *obj1) {
|
||||
struct nl_object *tuple = nl_cell_create(obj0, NULL);
|
||||
nl_list_append(tuple, obj1);
|
||||
struct ucl_object *ucl_tuple_create(struct ucl_object *obj0, struct ucl_object *obj1) {
|
||||
struct ucl_object *tuple = ucl_cell_create(obj0, NULL);
|
||||
ucl_list_append(tuple, obj1);
|
||||
return tuple;
|
||||
}
|
||||
|
||||
struct nl_object *nl_list_append(struct nl_object *list, struct nl_object *obj) {
|
||||
struct nl_object *iter = list;
|
||||
struct ucl_object *ucl_list_append(struct ucl_object *list, struct ucl_object *obj) {
|
||||
struct ucl_object *iter = list;
|
||||
|
||||
if (list->cell.car == NULL) {
|
||||
list->cell.car = obj;
|
||||
@@ -105,7 +105,7 @@ struct nl_object *nl_list_append(struct nl_object *list, struct nl_object *obj)
|
||||
while (iter->cell.cdr != NULL) {
|
||||
iter = iter->cell.cdr;
|
||||
}
|
||||
iter->cell.cdr = nl_cell_create(obj, NULL);
|
||||
iter->cell.cdr = ucl_cell_create(obj, NULL);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user