diff --git a/README b/README index 3eb0a6c..a51e527 100644 --- a/README +++ b/README @@ -1 +1 @@ -A LISP implementation that simply is. +A LISP implementation which aspires to target microcontrollers. diff --git a/SConstruct b/SConstruct index 95a53c7..87d874c 100644 --- a/SConstruct +++ b/SConstruct @@ -36,7 +36,7 @@ test_env.Append(CPPPATH=test_lib_includes) lib_objs = [env.Object(p) for p in lib_srcs] -env.Program(build_dir + "nihilispm", lib_objs + program_sources) +env.Program(build_dir + "uclisp", lib_objs + program_sources) # Generate unit test executables diff --git a/src/builtins.c b/src/builtins.c index 872cd0d..c78eeee 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1,6 +1,6 @@ -#include "nihilispm.h" -#include "nihilispm_internal.h" -#include "nihilispm_utility.h" +#include "uclisp.h" +#include "internal.h" +#include "utility.h" #include "builtins.h" #include @@ -8,131 +8,131 @@ #include #include -LISP_FUNC_0(nl_builtin_hello_world) { - return nl_string_create(strdup("Hello, world!")); +LISP_FUNC_0(ucl_builtin_hello_world) { + return ucl_string_create(strdup("Hello, world!")); } -LISP_FUNC_1(nl_builtin_type, arg) { +LISP_FUNC_1(ucl_builtin_type, arg) { switch (arg->type) { - case NL_TYPE_CELL: - return nl_symbol_create(strdup("list")); - case NL_TYPE_SYMBOL: - return nl_symbol_create(strdup("symbol")); - case NL_TYPE_INT: - return nl_symbol_create(strdup("int")); - case NL_TYPE_STRING: - return nl_symbol_create(strdup("string")); - case NL_TYPE_ERROR: - return nl_symbol_create(strdup("error")); - case NL_TYPE_COUNT: + case UCL_TYPE_CELL: + return ucl_symbol_create(strdup("list")); + case UCL_TYPE_SYMBOL: + return ucl_symbol_create(strdup("symbol")); + case UCL_TYPE_INT: + return ucl_symbol_create(strdup("int")); + case UCL_TYPE_STRING: + return ucl_symbol_create(strdup("string")); + case UCL_TYPE_ERROR: + return ucl_symbol_create(strdup("error")); + case UCL_TYPE_COUNT: assert(0); return NULL; } } -LISP_FUNC_1(nl_builtin_error, arg) { - if (arg->type != NL_TYPE_STRING) { - return nl_error_create("Expected type string passed to 'error'"); +LISP_FUNC_1(ucl_builtin_error, arg) { + if (arg->type != UCL_TYPE_STRING) { + return ucl_error_create("Expected type string passed to 'error'"); } - return nl_error_create(strdup(arg->error)); + return ucl_error_create(strdup(arg->error)); } -LISP_FUNC_1(nl_builtin_symbol_p, arg) { - return nl_predicate(arg->type == NL_TYPE_SYMBOL); +LISP_FUNC_1(ucl_builtin_symbol_p, arg) { + return ucl_predicate(arg->type == UCL_TYPE_SYMBOL); } -LISP_FUNC_1(nl_builtin_string_p, arg) { - return nl_predicate(arg->type == NL_TYPE_STRING); +LISP_FUNC_1(ucl_builtin_string_p, arg) { + return ucl_predicate(arg->type == UCL_TYPE_STRING); } -LISP_FUNC_1(nl_builtin_int_p, arg) { - return nl_predicate(arg->type == NL_TYPE_INT); +LISP_FUNC_1(ucl_builtin_int_p, arg) { + return ucl_predicate(arg->type == UCL_TYPE_INT); } -LISP_FUNC_1(nl_builtin_list_p, arg) { - return nl_predicate(arg->type == NL_TYPE_CELL); +LISP_FUNC_1(ucl_builtin_list_p, arg) { + return ucl_predicate(arg->type == UCL_TYPE_CELL); } -LISP_FUNC_1(nl_builtin_error_p, arg) { - return nl_predicate(arg->type == NL_TYPE_ERROR); +LISP_FUNC_1(ucl_builtin_error_p, arg) { + return ucl_predicate(arg->type == UCL_TYPE_ERROR); } -LISP_FUNC_1(nl_builtin_car, arg) { - return nl_car(arg); +LISP_FUNC_1(ucl_builtin_car, arg) { + return ucl_car(arg); } -LISP_FUNC_1(nl_builtin_cdr, arg) { - return nl_cdr(arg); +LISP_FUNC_1(ucl_builtin_cdr, arg) { + return ucl_cdr(arg); } -LISP_FUNC_2(nl_builtin_add, arg0, arg1) { - if (arg0->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 0 to 'add'"); +LISP_FUNC_2(ucl_builtin_add, arg0, arg1) { + if (arg0->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 0 to 'add'"); } - if (arg1->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 1 to 'add'"); + if (arg1->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 1 to 'add'"); } - return nl_int_create(arg0->integer + arg1->integer); + return ucl_int_create(arg0->integer + arg1->integer); } -LISP_FUNC_2(nl_builtin_sub, arg0, arg1) { - if (arg0->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 0 to 'sub'"); +LISP_FUNC_2(ucl_builtin_sub, arg0, arg1) { + if (arg0->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 0 to 'sub'"); } - if (arg1->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 1 to 'sub'"); + if (arg1->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 1 to 'sub'"); } - return nl_int_create(arg0->integer - arg1->integer); + return ucl_int_create(arg0->integer - arg1->integer); } -LISP_FUNC_2(nl_builtin_mul, arg0, arg1) { - if (arg0->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 0 to 'mul'"); +LISP_FUNC_2(ucl_builtin_mul, arg0, arg1) { + if (arg0->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 0 to 'mul'"); } - if (arg1->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 1 to 'mul'"); + if (arg1->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 1 to 'mul'"); } - return nl_int_create(arg0->integer * arg1->integer); + return ucl_int_create(arg0->integer * arg1->integer); } -LISP_FUNC_2(nl_builtin_div, arg0, arg1) { - if (arg0->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 0 to 'div'"); +LISP_FUNC_2(ucl_builtin_div, arg0, arg1) { + if (arg0->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 0 to 'div'"); } - if (arg1->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 1 to 'div'"); + if (arg1->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 1 to 'div'"); } - return nl_int_create(arg0->integer / arg1->integer); + return ucl_int_create(arg0->integer / arg1->integer); } -LISP_FUNC_2(nl_builtin_mod, arg0, arg1) { - if (arg0->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 0 to 'mod'"); +LISP_FUNC_2(ucl_builtin_mod, arg0, arg1) { + if (arg0->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 0 to 'mod'"); } - if (arg1->type != NL_TYPE_INT) { - return nl_error_create("Invalid type of argument 1 to 'mod'"); + if (arg1->type != UCL_TYPE_INT) { + return ucl_error_create("Invalid type of argument 1 to 'mod'"); } - return nl_int_create(arg0->integer % arg1->integer); + return ucl_int_create(arg0->integer % arg1->integer); } -LISP_FUNC_2(nl_builtin_concat, arg0, arg1) { - if (arg0->type != NL_TYPE_STRING) { - return nl_error_create("Invalid type of argument 0 to 'concat'"); +LISP_FUNC_2(ucl_builtin_concat, arg0, arg1) { + if (arg0->type != UCL_TYPE_STRING) { + return ucl_error_create("Invalid type of argument 0 to 'concat'"); } - if (arg1->type != NL_TYPE_STRING) { - return nl_error_create("Invalid type of argument 1 to 'concat'"); + if (arg1->type != UCL_TYPE_STRING) { + return ucl_error_create("Invalid type of argument 1 to 'concat'"); } int len = strlen(arg0->string) + strlen(arg1->string); @@ -141,10 +141,10 @@ LISP_FUNC_2(nl_builtin_concat, arg0, arg1) { strcat(outstr, arg0->string); strcat(outstr, arg1->string); - return nl_string_create(outstr); + return ucl_string_create(outstr); } -LISP_FUNC_0(nl_builtin_now_millis_mono) { +LISP_FUNC_0(ucl_builtin_now_millis_mono) { // TODO: Implement and move to a 'platform' file return NULL; } diff --git a/src/builtins.h b/src/builtins.h index e180201..fe2ce5e 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -1,61 +1,66 @@ -#include "nihilispm_utility.h" +#ifndef _UCLISP_BUILTINS_H_ +#define _UCLISP_BUILTINS_H_ + +#include "utility.h" #define LISP_FUNC_0(func_name) \ - static struct nl_object *func_name##_impl(); \ - struct nl_object *func_name(struct nl_object *args) { \ + static struct ucl_object *func_name##_impl(); \ + struct ucl_object *func_name(struct ucl_object *args) { \ if (args->cell.car != NULL) { \ return NULL; \ } \ return func_name##_impl(); \ } \ - static struct nl_object *func_name##_impl() + static struct ucl_object *func_name##_impl() #define LISP_FUNC_1(func_name, arg0_name) \ - static struct nl_object *func_name##_impl(struct nl_object *arg0_name); \ - struct nl_object *func_name(struct nl_object *args) { \ - struct nl_object *len_obj = nl_list_length(args); \ - if (len_obj->type != NL_TYPE_INT) { \ + static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name); \ + struct ucl_object *func_name(struct ucl_object *args) { \ + struct ucl_object *len_obj = ucl_list_length(args); \ + if (len_obj->type != UCL_TYPE_INT) { \ return NULL; \ } \ if (len_obj->integer != 1) { \ return NULL; \ } \ - struct nl_object *arg0 = nl_car(args); \ + struct ucl_object *arg0 = ucl_car(args); \ return func_name##_impl(arg0); \ } \ - static struct nl_object *func_name##_impl(struct nl_object *arg0_name) + static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name) // TODO: Unroll the args more efficiently, this is O(n^2) #define LISP_FUNC_2(func_name, arg0_name, arg1_name) \ - static struct nl_object *func_name##_impl(struct nl_object *arg0_name, struct nl_object *arg1_name); \ - struct nl_object *func_name(struct nl_object *args) { \ - struct nl_object *len_obj = nl_list_length(args); \ - if (len_obj->type != NL_TYPE_INT) { \ + static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name, struct ucl_object *arg1_name); \ + struct ucl_object *func_name(struct ucl_object *args) { \ + struct ucl_object *len_obj = ucl_list_length(args); \ + if (len_obj->type != UCL_TYPE_INT) { \ return NULL; \ } \ if (len_obj->integer != 2) { \ return NULL; \ } \ - struct nl_object *arg0 = nl_list_nth(args, 0); \ - struct nl_object *arg1 = nl_list_nth(args, 1); \ + struct ucl_object *arg0 = ucl_list_nth(args, 0); \ + struct ucl_object *arg1 = ucl_list_nth(args, 1); \ return func_name##_impl(arg0, arg1); \ } \ - static struct nl_object *func_name##_impl(struct nl_object *arg0_name, struct nl_object *arg1_name) + static struct ucl_object *func_name##_impl(struct ucl_object *arg0_name, struct ucl_object *arg1_name) -struct nl_object *nl_builtin_hello_world(struct nl_object *args); -struct nl_object *nl_builtin_error(struct nl_object *args); -struct nl_object *nl_builtin_type(struct nl_object *args); -struct nl_object *nl_builtin_symbol_p(struct nl_object *args); -struct nl_object *nl_builtin_string_p(struct nl_object *args); -struct nl_object *nl_builtin_int_p(struct nl_object *args); -struct nl_object *nl_builtin_list_p(struct nl_object *args); +struct ucl_object *ucl_builtin_hello_world(struct ucl_object *args); +struct ucl_object *ucl_builtin_error(struct ucl_object *args); +struct ucl_object *ucl_builtin_type(struct ucl_object *args); +struct ucl_object *ucl_builtin_symbol_p(struct ucl_object *args); +struct ucl_object *ucl_builtin_string_p(struct ucl_object *args); +struct ucl_object *ucl_builtin_int_p(struct ucl_object *args); +struct ucl_object *ucl_builtin_list_p(struct ucl_object *args); -struct nl_object *nl_builtin_add(struct nl_object *args); -struct nl_object *nl_builtin_sub(struct nl_object *args); -struct nl_object *nl_builtin_mul(struct nl_object *args); -struct nl_object *nl_builtin_div(struct nl_object *args); -struct nl_object *nl_builtin_mod(struct nl_object *args); -struct nl_object *nl_builtin_concat(struct nl_object *args); +struct ucl_object *ucl_builtin_add(struct ucl_object *args); +struct ucl_object *ucl_builtin_sub(struct ucl_object *args); +struct ucl_object *ucl_builtin_mul(struct ucl_object *args); +struct ucl_object *ucl_builtin_div(struct ucl_object *args); +struct ucl_object *ucl_builtin_mod(struct ucl_object *args); +struct ucl_object *ucl_builtin_concat(struct ucl_object *args); -struct nl_object *nl_builtin_now_millis_mono(struct nl_object *args); +struct ucl_object *ucl_builtin_now_millis_mono(struct ucl_object *args); + +#endif diff --git a/src/evaluate.c b/src/evaluate.c index 45c69e7..746a66c 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -1,26 +1,26 @@ #include #include -#include "nihilispm.h" -#include "nihilispm_internal.h" -#include "nihilispm_utility.h" -#include "nihilispm_state.h" +#include "uclisp.h" +#include "internal.h" +#include "utility.h" +#include "state.h" -struct nl_object *nl_evaluate_list(struct nl_state *state, struct nl_object *list) { +struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object *list) { // TODO: Recursively eval args - struct nl_object *evaluated_list = nl_nil_create(); + struct ucl_object *evaluated_list = ucl_nil_create(); FOREACH_LIST(list, iter, item) { - struct nl_object *obj = nl_evaluate(state, item); - nl_list_append(evaluated_list, obj); + struct ucl_object *obj = ucl_evaluate(state, item); + ucl_list_append(evaluated_list, obj); }; - struct nl_object *fun = nl_car(evaluated_list); - struct nl_object *args = nl_cdr(evaluated_list); - struct nl_object *result = NULL; + struct ucl_object *fun = ucl_car(evaluated_list); + struct ucl_object *args = ucl_cdr(evaluated_list); + struct ucl_object *result = NULL; - assert(fun->type == NL_TYPE_BUILTIN); - if (fun->type == NL_TYPE_BUILTIN) { + assert(fun->type == UCL_TYPE_BUILTIN); + if (fun->type == UCL_TYPE_BUILTIN) { result = fun->builtin(args); } @@ -31,20 +31,20 @@ struct nl_object *nl_evaluate_list(struct nl_state *state, struct nl_object *lis return result; } -struct nl_object *nl_evaluate(struct nl_state *state, struct nl_object *obj) { +struct ucl_object *ucl_evaluate(struct ucl_state *state, struct ucl_object *obj) { assert(obj != NULL); switch (obj->type) { - case NL_TYPE_CELL: - return nl_evaluate_list(state, obj); - case NL_TYPE_SYMBOL: - return nl_state_get(state, obj->symbol); - case NL_TYPE_INT: - case NL_TYPE_STRING: - case NL_TYPE_ERROR: + case UCL_TYPE_CELL: + return ucl_evaluate_list(state, obj); + case UCL_TYPE_SYMBOL: + return ucl_state_get(state, obj->symbol); + case UCL_TYPE_INT: + case UCL_TYPE_STRING: + case UCL_TYPE_ERROR: return obj; - case NL_TYPE_BUILTIN: - case NL_TYPE_COUNT: + case UCL_TYPE_BUILTIN: + case UCL_TYPE_COUNT: assert(0); return NULL; } diff --git a/src/internal.h b/src/internal.h new file mode 100644 index 0000000..9ff9d04 --- /dev/null +++ b/src/internal.h @@ -0,0 +1,29 @@ +#ifndef _UCLISP_INTERNAL_H_ +#define _UCLISP_INTERNAL_H_ + +#include "uclisp.h" +#include + +#define ARRAY_SIZE(x) sizeof(x) / sizeof(x[0]) +#define FOREACH_LIST(list, iter_name, item_name) \ + FOREACH_LIST_COND(list, iter_name, item_name, true) + +#define FOREACH_LIST_COND(list, iter_name, item_name, cond) \ + for (struct ucl_object *iter_name = (list), *item_name = iter_name->cell.car; \ + item_name != NULL && iter_name != NULL && (cond); \ + iter_name = iter_name->cell.cdr, item_name = (iter_name == NULL) ? NULL : iter_name->cell.car) + +struct ucl_object *ucl_cell_create(struct ucl_object *car, struct ucl_object *cdr); +struct ucl_object *ucl_int_create(int integer); +struct ucl_object *ucl_symbol_create(const char* symbol); +struct ucl_object *ucl_string_create(const char* string); +struct ucl_object *ucl_error_create(const char* error); +struct ucl_object *ucl_builtin_create(ucl_builtin builtin); + +void ucl_object_delete(struct ucl_object *obj); + +// For testing +struct ucl_object *ucl_token_next(const char **curr_src); +struct ucl_object *ucl_parse_token_atom(struct ucl_object *maybe_atom); + +#endif diff --git a/src/main.c b/src/main.c index 2a0abc6..385d5fe 100644 --- a/src/main.c +++ b/src/main.c @@ -1,27 +1,27 @@ #include #include -#include "nihilispm.h" -#include "nihilispm_state.h" -#include "nihilispm_internal.h" -#include "nihilispm_utility.h" +#include "uclisp.h" +#include "state.h" +#include "internal.h" +#include "utility.h" #include "builtins.h" int main(int argc, const char **argv) { (void) argc, (void) argv; - struct nl_state *state = nl_state_create(); + struct ucl_state *state = ucl_state_create(); - nl_state_put(state, "+", nl_builtin_create(nl_builtin_add)); - nl_state_put(state, "-", nl_builtin_create(nl_builtin_sub)); - nl_state_put(state, "*", nl_builtin_create(nl_builtin_mul)); - nl_state_put(state, "/", nl_builtin_create(nl_builtin_div)); - nl_state_put(state, "%", nl_builtin_create(nl_builtin_mod)); + ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add)); + ucl_state_put(state, "-", ucl_builtin_create(ucl_builtin_sub)); + ucl_state_put(state, "*", ucl_builtin_create(ucl_builtin_mul)); + ucl_state_put(state, "/", ucl_builtin_create(ucl_builtin_div)); + ucl_state_put(state, "%", ucl_builtin_create(ucl_builtin_mod)); - struct nl_object *sexp = nl_parse(argv[1]); - struct nl_object *result = nl_evaluate(state, nl_car(sexp)); + struct ucl_object *sexp = ucl_parse(argv[1]); + struct ucl_object *result = ucl_evaluate(state, ucl_car(sexp)); assert(result != NULL); - assert(result->type == NL_TYPE_INT); + assert(result->type == UCL_TYPE_INT); printf("%d\n", result->integer); diff --git a/src/memory.c b/src/memory.c index fe90691..82e9527 100644 --- a/src/memory.c +++ b/src/memory.c @@ -1,93 +1,93 @@ -#include "nihilispm.h" -#include "nihilispm_internal.h" +#include "uclisp.h" +#include "internal.h" #include #include -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); diff --git a/src/nihilispm.h b/src/nihilispm.h deleted file mode 100644 index b92c111..0000000 --- a/src/nihilispm.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _NIHILISPM_H_ -#define _NIHILISPM_H_ - -enum nl_type { - NL_TYPE_CELL = 0, - NL_TYPE_SYMBOL = 1, - NL_TYPE_INT = 2, - NL_TYPE_STRING = 3, - NL_TYPE_ERROR = 4, - NL_TYPE_BUILTIN = 5, - NL_TYPE_COUNT = 6, -}; - -struct nl_cell { - struct nl_object *car; - struct nl_object *cdr; -}; - -typedef struct nl_object *(*nl_builtin)(struct nl_object *args); - -struct nl_object { - enum nl_type type; - union { - struct nl_cell cell; - const char *symbol; - int integer; - const char *string; - const char *error; - nl_builtin builtin; - }; -}; - - - -struct nl_parse_result { - int result; - struct nl_cell *statement; -}; - -struct nl_state; // TODO - -struct nl_object *nl_tokenize(const char *source); -struct nl_object *nl_parse(const char *sexp); -struct nl_object *nl_evaluate(struct nl_state *state, struct nl_object *sexp); - -#endif diff --git a/src/nihilispm_internal.h b/src/nihilispm_internal.h deleted file mode 100644 index e1412dc..0000000 --- a/src/nihilispm_internal.h +++ /dev/null @@ -1,24 +0,0 @@ -#include "nihilispm.h" -#include - -#define ARRAY_SIZE(x) sizeof(x) / sizeof(x[0]) -#define FOREACH_LIST(list, iter_name, item_name) \ - FOREACH_LIST_COND(list, iter_name, item_name, true) - -#define FOREACH_LIST_COND(list, iter_name, item_name, cond) \ - for (struct nl_object *iter_name = (list), *item_name = iter_name->cell.car; \ - item_name != NULL && iter_name != NULL && (cond); \ - iter_name = iter_name->cell.cdr, item_name = (iter_name == NULL) ? NULL : iter_name->cell.car) - -struct nl_object *nl_cell_create(struct nl_object *car, struct nl_object *cdr); -struct nl_object *nl_int_create(int integer); -struct nl_object *nl_symbol_create(const char* symbol); -struct nl_object *nl_string_create(const char* string); -struct nl_object *nl_error_create(const char* error); -struct nl_object *nl_builtin_create(nl_builtin builtin); - -void nl_object_delete(struct nl_object *obj); - -// For testing -struct nl_object *nl_token_next(const char **curr_src); -struct nl_object *nl_parse_token_atom(struct nl_object *maybe_atom); diff --git a/src/nihilispm_state.h b/src/nihilispm_state.h deleted file mode 100644 index 8d1fddf..0000000 --- a/src/nihilispm_state.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _NIHILISPM_STATE_H_ -#define _NIHILISPM_STATE_H_ -struct nl_state; - -struct nl_state *nl_state_create(); -void nl_state_delete(struct nl_state *state); - -struct nl_object *nl_state_get(struct nl_state *state, const char *name); -void nl_state_put(struct nl_state *state, const char *name, struct nl_object *obj); - -#endif diff --git a/src/nihilispm_utility.h b/src/nihilispm_utility.h deleted file mode 100644 index 0093aff..0000000 --- a/src/nihilispm_utility.h +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#include "nihilispm.h" - -struct nl_object *nl_nil_create(); -struct nl_object *nl_t_create(); -struct nl_object *nl_predicate(bool value); -struct nl_object *nl_truthy(struct nl_object *arg); - -struct nl_object* nl_car(struct nl_object *list); -struct nl_object* nl_cdr(struct nl_object *list); - -struct nl_object* nl_list_length(struct nl_object *list); -struct nl_object* nl_list_nth(struct nl_object *list, int n); -struct nl_object* nl_list_append(struct nl_object *list, struct nl_object *obj); -struct nl_object* nl_tuple_create(struct nl_object *obj0, struct nl_object *obj1); - - -#define NL_RET_IF_ERROR(obj) \ - do { \ - if ((obj)->type == NL_TYPE_ERROR) { \ - return obj; \ - } while(0) - -#define NL_COND_OR_RET_ERROR(cond, msg) \ - do { \ - if (!(cond)) { \ - return nl_error_create(strdup(msg)); \ - } \ - } while(0) diff --git a/src/parse.c b/src/parse.c index 2c7a533..091cdca 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1,5 +1,5 @@ -#include "nihilispm.h" -#include "nihilispm_internal.h" +#include "uclisp.h" +#include "internal.h" // TODO: remove these #include @@ -21,19 +21,19 @@ static const char *reserved_symbols[] = { // TODO: remove malloc and strndup calls -static bool nl_is_whitespace(char c) { +static bool ucl_is_whitespace(char c) { return c == ' ' || c == '\n' || c == '\t'; } -static bool nl_is_token(char c) { +static bool ucl_is_token(char c) { return c == START_LIST_CHAR || c == END_LIST_CHAR || c == QUOTE_CHAR; } -static bool nl_is_delimiter(char c) { - return nl_is_whitespace(c) || nl_is_token(c) || c == '\0'; +static bool ucl_is_delimiter(char c) { + return ucl_is_whitespace(c) || ucl_is_token(c) || c == '\0'; } -struct nl_object *nl_token_next(const char **curr_src) { +struct ucl_object *ucl_token_next(const char **curr_src) { assert(*curr_src != NULL); const char *start = *curr_src; @@ -54,7 +54,7 @@ struct nl_object *nl_token_next(const char **curr_src) { str[0] = **curr_src; str[1] = '\0'; (*curr_src)++; - return nl_cell_create(nl_symbol_create(str), NULL); + return ucl_cell_create(ucl_symbol_create(str), NULL); case QUOTE_CHAR: // skip beginning quote (*curr_src)++; @@ -66,19 +66,19 @@ struct nl_object *nl_token_next(const char **curr_src) { (*curr_src)++; // -2 for removing start/end quotes str = strndup(start + 1, *curr_src - start - 2); - return nl_cell_create(nl_string_create(str), NULL); + return ucl_cell_create(ucl_string_create(str), NULL); case '0'...'9': { char *end = NULL; long value = strtol(*curr_src, &end, 0); *curr_src = end; - return nl_cell_create(nl_int_create(value), NULL); + return ucl_cell_create(ucl_int_create(value), NULL); } default: - while (!nl_is_delimiter(**curr_src)) { + while (!ucl_is_delimiter(**curr_src)) { (*curr_src)++; } str = strndup(start, *curr_src - start); - return nl_cell_create(nl_symbol_create(str), NULL); + return ucl_cell_create(ucl_symbol_create(str), NULL); } } @@ -87,11 +87,11 @@ struct nl_object *nl_token_next(const char **curr_src) { return NULL; } -struct nl_object *nl_tokenize(const char *source) { - struct nl_object *tokens = NULL, *curr_token = NULL, **next_token = &tokens; +struct ucl_object *ucl_tokenize(const char *source) { + struct ucl_object *tokens = NULL, *curr_token = NULL, **next_token = &tokens; const char *curr_src = source; - while ((curr_token = nl_token_next(&curr_src)) != NULL) { + while ((curr_token = ucl_token_next(&curr_src)) != NULL) { *next_token = curr_token; next_token = &curr_token->cell.cdr; } @@ -99,78 +99,78 @@ struct nl_object *nl_tokenize(const char *source) { return tokens; } -struct nl_object *nl_parse_token_atom(struct nl_object *maybe_atom) { - struct nl_object *atom = NULL; +struct ucl_object *ucl_parse_token_atom(struct ucl_object *maybe_atom) { + struct ucl_object *atom = NULL; switch (maybe_atom->type) { - case NL_TYPE_CELL: + case UCL_TYPE_CELL: // Cell types currently are not valid for tokens assert(false); break; - case NL_TYPE_SYMBOL: { + case UCL_TYPE_SYMBOL: { // Check for reserved tokens first, which indicate special, non-atom behavior for (int i = 0; i < ARRAY_SIZE(reserved_symbols); i++) { if (!strcmp(maybe_atom->string, reserved_symbols[i])) { return NULL; } } - atom = nl_symbol_create(strdup(maybe_atom->symbol)); + atom = ucl_symbol_create(strdup(maybe_atom->symbol)); break; } - case NL_TYPE_STRING: - atom = nl_string_create(strdup(maybe_atom->string)); + case UCL_TYPE_STRING: + atom = ucl_string_create(strdup(maybe_atom->string)); break; - case NL_TYPE_INT: - atom = nl_int_create(maybe_atom->integer); + case UCL_TYPE_INT: + atom = ucl_int_create(maybe_atom->integer); break; - case NL_TYPE_COUNT: + case UCL_TYPE_COUNT: assert(false); } return atom; } -static struct nl_object *nl_parse_tokens_recursive(struct nl_object **token_iter) { +static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_iter) { // Invariants: // - This function returns NULL if it encounters the first unmatched END_LIST_CHAR // - This function returns NULL if it encounters end-of-list without first finding a START_LIST_CHAR - // - This function returns an nl_object of the atom or list at **token_iter + // - This function returns an ucl_object of the atom or list at **token_iter assert(token_iter != NULL); if (*token_iter == NULL) { return NULL; } - assert((*token_iter)->type == NL_TYPE_CELL); + assert((*token_iter)->type == UCL_TYPE_CELL); - struct nl_object *token = (*token_iter)->cell.car; - struct nl_object *next_sexp = nl_parse_token_atom(token); + struct ucl_object *token = (*token_iter)->cell.car; + struct ucl_object *next_sexp = ucl_parse_token_atom(token); if (next_sexp != NULL) { *token_iter = (*token_iter)->cell.cdr; return next_sexp; } - assert(token->type == NL_TYPE_SYMBOL); + assert(token->type == UCL_TYPE_SYMBOL); if (token->symbol[0] == START_LIST_CHAR) { - struct nl_object *list = NULL; - struct nl_object **next_node = &list; + struct ucl_object *list = NULL; + struct ucl_object **next_node = &list; // Consume the START_LIST_CHAR *token_iter = (*token_iter)->cell.cdr; while (1) { token = (*token_iter)->cell.car; - if (token->type == NL_TYPE_SYMBOL && token->symbol[0] == END_LIST_CHAR) { + if (token->type == UCL_TYPE_SYMBOL && token->symbol[0] == END_LIST_CHAR) { *token_iter = (*token_iter)->cell.cdr; if (list == NULL) { - list = nl_cell_create(NULL, NULL); + list = ucl_cell_create(NULL, NULL); } return list; } - next_sexp = nl_parse_tokens_recursive(token_iter); + next_sexp = ucl_parse_tokens_recursive(token_iter); if (next_sexp == NULL) { // Error somewhere in the recursive parsing - nl_object_delete(list); + ucl_object_delete(list); return NULL; } - *next_node = nl_cell_create(next_sexp, NULL); + *next_node = ucl_cell_create(next_sexp, NULL); next_node = &(*next_node)->cell.cdr; } } else if (token->symbol[0] == END_LIST_CHAR) { @@ -185,42 +185,42 @@ static struct nl_object *nl_parse_tokens_recursive(struct nl_object **token_iter // parse_tokens -> doesn't care about quotes, terminates on EOF // parse_tokens_recursive -> error on EOF) -struct nl_object *nl_parse_tokens(struct nl_object *tokens) { - struct nl_object* resultl = NULL; - struct nl_object** token_iter = &tokens; - struct nl_object** next_cell = &resultl; +struct ucl_object *ucl_parse_tokens(struct ucl_object *tokens) { + struct ucl_object* resultl = NULL; + struct ucl_object** token_iter = &tokens; + struct ucl_object** next_cell = &resultl; while (*token_iter != NULL) { - struct nl_object *new_sexp = nl_parse_tokens_recursive(token_iter); + struct ucl_object *new_sexp = ucl_parse_tokens_recursive(token_iter); if (new_sexp == NULL) { goto error; } - *next_cell = nl_cell_create(new_sexp, NULL); + *next_cell = ucl_cell_create(new_sexp, NULL); next_cell = &(*next_cell)->cell.cdr; } if (resultl == NULL) { - return nl_cell_create(NULL, NULL); + return ucl_cell_create(NULL, NULL); } return resultl; error: - nl_object_delete(resultl); + ucl_object_delete(resultl); return NULL; } // TODO: Should the parse a single sexp (return the last-parsed position), or // all sexps in the source (return a list of sexps)? -struct nl_object *nl_parse(const char *source) { - struct nl_object *tokens = nl_tokenize(source); - struct nl_object *sexp = nl_parse_tokens(tokens); - nl_object_delete(tokens); +struct ucl_object *ucl_parse(const char *source) { + struct ucl_object *tokens = ucl_tokenize(source); + struct ucl_object *sexp = ucl_parse_tokens(tokens); + ucl_object_delete(tokens); return sexp; } -/* struct ParseResult *nl_parse(const char *source) { */ -/* struct Cell *tokens = nl_tokenize(source); */ +/* struct ParseResult *ucl_parse(const char *source) { */ +/* struct Cell *tokens = ucl_tokenize(source); */ /* struct Cell *sexp = n */ /* } */ diff --git a/src/state.c b/src/state.c index 5166240..bf6149c 100644 --- a/src/state.c +++ b/src/state.c @@ -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 #include @@ -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); } diff --git a/src/state.h b/src/state.h new file mode 100644 index 0000000..3b8ed3f --- /dev/null +++ b/src/state.h @@ -0,0 +1,12 @@ +#ifndef _UCLISP_STATE_H_ +#define _UCLISP_STATE_H_ + +struct ucl_state; + +struct ucl_state *ucl_state_create(); +void ucl_state_delete(struct ucl_state *state); + +struct ucl_object *ucl_state_get(struct ucl_state *state, const char *name); +void ucl_state_put(struct ucl_state *state, const char *name, struct ucl_object *obj); + +#endif diff --git a/src/uclisp.h b/src/uclisp.h new file mode 100644 index 0000000..f28a9b9 --- /dev/null +++ b/src/uclisp.h @@ -0,0 +1,46 @@ +#ifndef _UCLISP_H_ +#define _UCLISP_H_ + +enum ucl_type { + UCL_TYPE_CELL = 0, + UCL_TYPE_SYMBOL = 1, + UCL_TYPE_INT = 2, + UCL_TYPE_STRING = 3, + UCL_TYPE_ERROR = 4, + UCL_TYPE_BUILTIN = 5, + UCL_TYPE_COUNT = 6, +}; + +struct ucl_cell { + struct ucl_object *car; + struct ucl_object *cdr; +}; + +typedef struct ucl_object *(*ucl_builtin)(struct ucl_object *args); + +struct ucl_object { + enum ucl_type type; + union { + struct ucl_cell cell; + const char *symbol; + int integer; + const char *string; + const char *error; + ucl_builtin builtin; + }; +}; + + + +struct ucl_parse_result { + int result; + struct ucl_cell *statement; +}; + +struct ucl_state; // TODO + +struct ucl_object *ucl_tokenize(const char *source); +struct ucl_object *ucl_parse(const char *sexp); +struct ucl_object *ucl_evaluate(struct ucl_state *state, struct ucl_object *sexp); + +#endif diff --git a/src/utility.c b/src/utility.c index 969d09e..b5a242a 100644 --- a/src/utility.c +++ b/src/utility.c @@ -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 #include #include -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; } diff --git a/src/utility.h b/src/utility.h new file mode 100644 index 0000000..4151760 --- /dev/null +++ b/src/utility.h @@ -0,0 +1,35 @@ +#ifndef _UCLISP_UTILITY_H_ +#define _UCLISP_UTILITY_H_ + +#include + +#include "uclisp.h" + +struct ucl_object *ucl_nil_create(); +struct ucl_object *ucl_t_create(); +struct ucl_object *ucl_predicate(bool value); +struct ucl_object *ucl_truthy(struct ucl_object *arg); + +struct ucl_object* ucl_car(struct ucl_object *list); +struct ucl_object* ucl_cdr(struct ucl_object *list); + +struct ucl_object* ucl_list_length(struct ucl_object *list); +struct ucl_object* ucl_list_nth(struct ucl_object *list, int n); +struct ucl_object* ucl_list_append(struct ucl_object *list, struct ucl_object *obj); +struct ucl_object* ucl_tuple_create(struct ucl_object *obj0, struct ucl_object *obj1); + + +#define UCL_RET_IF_ERROR(obj) \ + do { \ + if ((obj)->type == UCL_TYPE_ERROR) { \ + return obj; \ + } while(0) + +#define UCL_COND_OR_RET_ERROR(cond, msg) \ + do { \ + if (!(cond)) { \ + return ucl_error_create(strdup(msg)); \ + } \ + } while(0) + +#endif diff --git a/test/test_parse.c b/test/test_parse.c index 1a917be..e124054 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -2,25 +2,25 @@ #include #include -#include "nihilispm.h" -#include "nihilispm_internal.h" +#include "uclisp.h" +#include "internal.h" -/* static struct nl_parse_result *result; */ -static struct nl_object *response; +/* static struct ucl_parse_result *result; */ +static struct ucl_object *response; void setUp(void) { response = NULL; } void tearDown(void) { - nl_object_delete(response); + ucl_object_delete(response); } static void test_token_next_empty_str(void) { const char *input = ""; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NULL(response); TEST_ASSERT_EQUAL('\0', *curr); @@ -30,7 +30,7 @@ static void test_token_next_only_whitespace(void) { const char *input = " \n"; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NULL(response); TEST_ASSERT_EQUAL('\0', *curr); @@ -40,11 +40,11 @@ static void test_token_next_lparen(void) { const char *input = "("; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("(", response->cell.car->string); TEST_ASSERT_EQUAL('\0', *curr); } @@ -53,11 +53,11 @@ static void test_token_next_rparen(void) { const char *input = ")"; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING(")", response->cell.car->string); TEST_ASSERT_EQUAL('\0', *curr); } @@ -66,20 +66,20 @@ static void test_token_next_lrparen(void) { const char *input = "()"; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("(", response->cell.car->string); TEST_ASSERT_EQUAL(')', *curr); - nl_object_delete(response); - response = nl_token_next(&curr); + ucl_object_delete(response); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING(")", response->cell.car->string); TEST_ASSERT_EQUAL('\0', *curr); } @@ -88,11 +88,11 @@ static void test_token_next_string(void) { const char *input = "\"foo\""; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string); TEST_ASSERT_EQUAL('\0', *curr); } @@ -101,11 +101,11 @@ static void test_token_next_string_w_whitespace(void) { const char *input = " \"foo\" "; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string); TEST_ASSERT_EQUAL_STRING(" ", curr); } @@ -114,11 +114,11 @@ static void test_token_next_symbol(void) { const char *input = "foo"; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string); TEST_ASSERT_EQUAL_STRING("", curr); } @@ -127,206 +127,206 @@ static void test_token_next_symbol_w_whitespace(void) { const char *input = " foo "; const char *curr = input; - response = nl_token_next(&curr); + response = ucl_token_next(&curr); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string); TEST_ASSERT_EQUAL_STRING(" ", curr); } static void test_tokenize_empty_str(void) { - response = nl_tokenize(""); + response = ucl_tokenize(""); TEST_ASSERT_NULL(response); } static void test_tokenize_nil(void) { - response = nl_tokenize("()"); + response = ucl_tokenize("()"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); - const struct nl_object *token1 = response; - const struct nl_object *token2 = response->cell.cdr; + const struct ucl_object *token1 = response; + const struct ucl_object *token2 = response->cell.cdr; - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token1->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token1->cell.car->type); TEST_ASSERT_EQUAL_STRING("(", token1->cell.car->string); TEST_ASSERT_NOT_NULL(token2); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, token2->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token2->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, token2->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token2->cell.car->type); TEST_ASSERT_EQUAL_STRING(")", token2->cell.car->string); TEST_ASSERT_NULL(token2->cell.cdr); } static void test_tokenize_statement(void) { - response = nl_tokenize("(foo)"); + response = ucl_tokenize("(foo)"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); - const struct nl_object *token1 = response; - const struct nl_object *token2 = response->cell.cdr; + const struct ucl_object *token1 = response; + const struct ucl_object *token2 = response->cell.cdr; - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token1->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token1->cell.car->type); TEST_ASSERT_EQUAL_STRING("(", token1->cell.car->string); TEST_ASSERT_NOT_NULL(token2); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, token2->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token2->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, token2->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token2->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", token2->cell.car->string); - const struct nl_object *token3 = token2->cell.cdr; + const struct ucl_object *token3 = token2->cell.cdr; TEST_ASSERT_NOT_NULL(token3); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, token3->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, token3->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, token3->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, token3->cell.car->type); TEST_ASSERT_EQUAL_STRING(")", token3->cell.car->string); } static void test_parse_atom_symbol(void) { - response = nl_parse_token_atom(nl_symbol_create(strdup("foo"))); + response = ucl_parse_token_atom(ucl_symbol_create(strdup("foo"))); - TEST_ASSERT_EQUAL(response->type, NL_TYPE_SYMBOL); + TEST_ASSERT_EQUAL(response->type, UCL_TYPE_SYMBOL); TEST_ASSERT_EQUAL_STRING(response->symbol, "foo"); } static void test_parse_atom_lparen(void) { - response = nl_parse_token_atom(nl_symbol_create(strdup("("))); + response = ucl_parse_token_atom(ucl_symbol_create(strdup("("))); TEST_ASSERT_NULL(response); } static void test_parse_atom_rparen(void) { - response = nl_parse_token_atom(nl_symbol_create(strdup(")"))); + response = ucl_parse_token_atom(ucl_symbol_create(strdup(")"))); TEST_ASSERT_NULL(response); } static void test_parse_empty_str(void) { - response = nl_parse(""); + response = ucl_parse(""); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NULL(response->cell.car); TEST_ASSERT_NULL(response->cell.cdr); } static void test_parse_symbol(void) { - response = nl_parse("foo"); + response = ucl_parse("foo"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); - TEST_ASSERT_EQUAL(response->cell.car->type, NL_TYPE_SYMBOL); + TEST_ASSERT_EQUAL(response->cell.car->type, UCL_TYPE_SYMBOL); TEST_ASSERT_EQUAL_STRING(response->cell.car->symbol, "foo"); } static void test_parse_nil(void) { - response = nl_parse("()"); + response = ucl_parse("()"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); TEST_ASSERT_NULL(response->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type); TEST_ASSERT_NULL(response->cell.car->cell.car); TEST_ASSERT_NULL(response->cell.car->cell.cdr); } static void test_parse_list_1elem(void) { - response = nl_parse("(foo)"); + response = ucl_parse("(foo)"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); TEST_ASSERT_NULL(response->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type); TEST_ASSERT_NULL(response->cell.car->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->cell.car->symbol); } static void test_parse_list_2elem(void) { - response = nl_parse("(foo bar)"); + response = ucl_parse("(foo bar)"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); TEST_ASSERT_NULL(response->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type); TEST_ASSERT_NOT_NULL(response->cell.car->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->cell.car->symbol); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->cell.cdr->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.cdr->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->cell.cdr->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.cdr->cell.car->type); TEST_ASSERT_EQUAL_STRING("bar", response->cell.car->cell.cdr->cell.car->string); } static void test_parse_2elem(void) { - response = nl_parse("foo bar"); + response = ucl_parse("foo bar"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->symbol); TEST_ASSERT_NOT_NULL(response->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.cdr->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.cdr->type); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.cdr->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.cdr->cell.car->type); TEST_ASSERT_EQUAL_STRING("bar", response->cell.cdr->cell.car->symbol); } static void test_parse_2elem_str(void) { - response = nl_parse("\"foo\" \"bar\""); + response = ucl_parse("\"foo\" \"bar\""); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); - TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->string); TEST_ASSERT_NOT_NULL(response->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.cdr->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.cdr->type); - TEST_ASSERT_EQUAL(NL_TYPE_STRING, response->cell.cdr->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_STRING, response->cell.cdr->cell.car->type); TEST_ASSERT_EQUAL_STRING("bar", response->cell.cdr->cell.car->string); } static void test_parse_nested(void) { - response = nl_parse("((foo))"); + response = ucl_parse("((foo))"); TEST_ASSERT_NOT_NULL(response); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->type); TEST_ASSERT_NOT_NULL(response->cell.car); TEST_ASSERT_NULL(response->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->type); TEST_ASSERT_NULL(response->cell.car->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_CELL, response->cell.car->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_CELL, response->cell.car->cell.car->type); TEST_ASSERT_NULL(response->cell.car->cell.car->cell.cdr); - TEST_ASSERT_EQUAL(NL_TYPE_SYMBOL, response->cell.car->cell.car->cell.car->type); + TEST_ASSERT_EQUAL(UCL_TYPE_SYMBOL, response->cell.car->cell.car->cell.car->type); TEST_ASSERT_EQUAL_STRING("foo", response->cell.car->cell.car->cell.car->symbol); } diff --git a/test/test_state.c b/test/test_state.c index 8b01977..11f6703 100644 --- a/test/test_state.c +++ b/test/test_state.c @@ -2,57 +2,57 @@ #include #include -#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 "testing_helpers.h" -/* static struct nl_parse_result *result; */ -static struct nl_state *state; -static struct nl_object *response; +/* static struct ucl_parse_result *result; */ +static struct ucl_state *state; +static struct ucl_object *response; void setUp(void) { - state = nl_state_create(); + state = ucl_state_create(); } void tearDown(void) { - nl_state_delete(state); + ucl_state_delete(state); state = NULL; } static void test_get_empty(void) { - response = nl_state_get(state, "foo"); + response = ucl_state_get(state, "foo"); TEST_ASSERT_OBJ_ERROR(response); } static void test_put_get(void) { - nl_state_put(state, "foo", nl_t_create()); - response = nl_state_get(state, "foo"); + ucl_state_put(state, "foo", ucl_t_create()); + response = ucl_state_get(state, "foo"); TEST_ASSERT_T(response); } static void test_put2_get(void) { - nl_state_put(state, "foo1", nl_t_create()); - nl_state_put(state, "foo2", nl_nil_create()); - response = nl_state_get(state, "foo1"); + ucl_state_put(state, "foo1", ucl_t_create()); + ucl_state_put(state, "foo2", ucl_nil_create()); + response = ucl_state_get(state, "foo1"); TEST_ASSERT_T(response); } static void test_put_modify_get(void) { - struct nl_object *obj = nl_tuple_create( - nl_string_create(strdup("bar")), - nl_string_create(strdup("baz"))); + struct ucl_object *obj = ucl_tuple_create( + ucl_string_create(strdup("bar")), + ucl_string_create(strdup("baz"))); - nl_state_put(state, "foo", obj); - nl_list_append(obj, nl_string_create(strdup("quux"))); - response = nl_state_get(state, "foo"); + ucl_state_put(state, "foo", obj); + ucl_list_append(obj, ucl_string_create(strdup("quux"))); + response = ucl_state_get(state, "foo"); - TEST_ASSERT_OBJ_STRING(nl_list_nth(response, 2)); - TEST_ASSERT_EQUAL_STRING(nl_list_nth(response, 2)->string, "quux"); + TEST_ASSERT_OBJ_STRING(ucl_list_nth(response, 2)); + TEST_ASSERT_EQUAL_STRING(ucl_list_nth(response, 2)->string, "quux"); - TEST_ASSERT_OBJ_STRING(nl_list_nth(obj, 2)); - TEST_ASSERT_EQUAL_STRING(nl_list_nth(obj, 2)->string, "quux"); + TEST_ASSERT_OBJ_STRING(ucl_list_nth(obj, 2)); + TEST_ASSERT_EQUAL_STRING(ucl_list_nth(obj, 2)->string, "quux"); } diff --git a/test/test_utility.c b/test/test_utility.c index ee0d39b..78f0a5c 100644 --- a/test/test_utility.c +++ b/test/test_utility.c @@ -2,13 +2,13 @@ #include #include -#include "nihilispm.h" -#include "nihilispm_internal.h" -#include "nihilispm_utility.h" +#include "uclisp.h" +#include "internal.h" +#include "utility.h" #include "testing_helpers.h" -static struct nl_object *input; -static struct nl_object *response; +static struct ucl_object *input; +static struct ucl_object *response; void setUp(void) { input = NULL; @@ -17,99 +17,99 @@ void setUp(void) { void tearDown(void) { // TODO: Implement GC so we can clean these both up - //nl_object_delete(input); + //ucl_object_delete(input); input = NULL; - nl_object_delete(response); + ucl_object_delete(response); response = NULL; } static void test_nil_create(void) { - response = nl_nil_create(); + response = ucl_nil_create(); TEST_ASSERT_NIL(response); } static void test_t_create(void) { - response = nl_t_create(); + response = ucl_t_create(); TEST_ASSERT_T(response); } static void test_predicate_true(void) { - response = nl_predicate(true); + response = ucl_predicate(true); TEST_ASSERT_T(response); } static void test_predicate_false(void) { - response = nl_predicate(false); + response = ucl_predicate(false); TEST_ASSERT_NIL(response); } static void test_car_nil(void) { - response = nl_car(nl_nil_create()); + response = ucl_car(ucl_nil_create()); TEST_ASSERT_NIL(response); } static void test_cdr_nil(void) { - response = nl_cdr(nl_nil_create()); + response = ucl_cdr(ucl_nil_create()); TEST_ASSERT_NIL(response); } static void test_car_t(void) { - response = nl_car(nl_t_create()); + response = ucl_car(ucl_t_create()); TEST_ASSERT_OBJ_ERROR(response); } static void test_cdr_t(void) { - response = nl_car(nl_t_create()); + response = ucl_car(ucl_t_create()); TEST_ASSERT_OBJ_ERROR(response); } static void test_car_list(void) { - input = nl_tuple_create( - nl_string_create(strdup("foo")), - nl_t_create()); - response = nl_car(input); + input = ucl_tuple_create( + ucl_string_create(strdup("foo")), + ucl_t_create()); + response = ucl_car(input); TEST_ASSERT_OBJ_STRING(response); } static void test_cdr_list(void) { - input = nl_tuple_create( - nl_t_create(), - nl_string_create(strdup("foo"))); - response = nl_cdr(input); + input = ucl_tuple_create( + ucl_t_create(), + ucl_string_create(strdup("foo"))); + response = ucl_cdr(input); - TEST_ASSERT_OBJ_STRING(nl_car(response)); + TEST_ASSERT_OBJ_STRING(ucl_car(response)); } static void test_list_length_nil() { - response = nl_list_length(nl_nil_create()); + response = ucl_list_length(ucl_nil_create()); TEST_ASSERT_OBJ_INT(response); TEST_ASSERT_EQUAL(response->integer, 0); } static void test_list_length_1() { - response = nl_list_length( - nl_cell_create( - nl_t_create(), NULL)); + response = ucl_list_length( + ucl_cell_create( + ucl_t_create(), NULL)); TEST_ASSERT_OBJ_INT(response); TEST_ASSERT_EQUAL(response->integer, 1); } static void test_list_length_2() { - response = nl_list_length( - nl_tuple_create( - nl_t_create(), - nl_t_create())); + response = ucl_list_length( + ucl_tuple_create( + ucl_t_create(), + ucl_t_create())); TEST_ASSERT_OBJ_INT(response); TEST_ASSERT_EQUAL(response->integer, 2); @@ -117,67 +117,67 @@ static void test_list_length_2() { static void test_list_append_nil() { - input = nl_nil_create(); - nl_list_append(input, nl_t_create()); + input = ucl_nil_create(); + ucl_list_append(input, ucl_t_create()); - TEST_ASSERT_EQUAL(nl_list_length(input)->integer, 1); + TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 1); } static void test_list_append_list() { - input = nl_tuple_create(nl_t_create(), nl_t_create()); - nl_list_append(input, nl_t_create()); + input = ucl_tuple_create(ucl_t_create(), ucl_t_create()); + ucl_list_append(input, ucl_t_create()); - TEST_ASSERT_EQUAL(nl_list_length(input)->integer, 3); + TEST_ASSERT_EQUAL(ucl_list_length(input)->integer, 3); } static void test_list_nth_nil_0() { - response = nl_list_nth(nl_nil_create(), 0); + response = ucl_list_nth(ucl_nil_create(), 0); TEST_ASSERT_OBJ_ERROR(response); } static void test_list_nth_nil_1() { - response = nl_list_nth(nl_nil_create(), 1); + response = ucl_list_nth(ucl_nil_create(), 1); TEST_ASSERT_OBJ_ERROR(response); } static void test_list_nth_list_0() { - response = nl_list_nth( - nl_tuple_create( - nl_t_create(), - nl_string_create(strdup("foo"))), + response = ucl_list_nth( + ucl_tuple_create( + ucl_t_create(), + ucl_string_create(strdup("foo"))), 0); TEST_ASSERT_T(response); } static void test_list_nth_list_1() { - response = nl_list_nth( - nl_tuple_create( - nl_t_create(), - nl_string_create(strdup("foo"))), + response = ucl_list_nth( + ucl_tuple_create( + ucl_t_create(), + ucl_string_create(strdup("foo"))), 1); TEST_ASSERT_OBJ_STRING(response); } static void test_list_nth_t_0() { - response = nl_list_nth(nl_t_create(), 1); + response = ucl_list_nth(ucl_t_create(), 1); TEST_ASSERT_OBJ_ERROR(response); } static void test_list_nth_bounds_0() { - response = nl_list_nth(nl_nil_create(), 0); + response = ucl_list_nth(ucl_nil_create(), 0); TEST_ASSERT_OBJ_ERROR(response); } static void test_list_nth_bounds_1() { - response = nl_list_nth( - nl_cell_create( - nl_nil_create(), + response = ucl_list_nth( + ucl_cell_create( + ucl_nil_create(), NULL), 1); @@ -185,10 +185,10 @@ static void test_list_nth_bounds_1() { } static void test_list_nth_bounds_2() { - response = nl_list_nth( - nl_tuple_create( - nl_nil_create(), - nl_nil_create()), + response = ucl_list_nth( + ucl_tuple_create( + ucl_nil_create(), + ucl_nil_create()), 2); TEST_ASSERT_OBJ_ERROR(response); diff --git a/test/testing_helpers.h b/test/testing_helpers.h index 8049fbd..bf24627 100644 --- a/test/testing_helpers.h +++ b/test/testing_helpers.h @@ -3,27 +3,27 @@ #include -#include "nihilispm.h" +#include "uclisp.h" #define TEST_ASSERT_OBJ_ERROR(obj) \ - TEST_ASSERT_EQUAL(obj->type, NL_TYPE_ERROR) + TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_ERROR) #define TEST_ASSERT_OBJ_SYMBOL(obj) \ - TEST_ASSERT_EQUAL(obj->type, NL_TYPE_SYMBOL) + TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_SYMBOL) #define TEST_ASSERT_OBJ_STRING(obj) \ - TEST_ASSERT_EQUAL(obj->type, NL_TYPE_STRING) + TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_STRING) #define TEST_ASSERT_OBJ_INT(obj) \ - TEST_ASSERT_EQUAL(obj->type, NL_TYPE_INT) + TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_INT) #define TEST_ASSERT_OBJ_LIST(obj) \ - TEST_ASSERT_EQUAL(obj->type, NL_TYPE_CELL) + TEST_ASSERT_EQUAL(obj->type, UCL_TYPE_CELL) #define TEST_ASSERT_LIST_LEN(list, len) \ do { \ TEST_ASSERT_OBJ_LIST(list); \ - TEST_ASSERT_EQUAL(nl_list_length(list)->integer, len); \ + TEST_ASSERT_EQUAL(ucl_list_length(list)->integer, len); \ } while(0) #define TEST_ASSERT_NIL(obj) \