Add defun without evaluation
This commit is contained in:
@@ -9,11 +9,7 @@
|
||||
// TODO: remove string.h
|
||||
#include <string.h>
|
||||
|
||||
struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object *list) {
|
||||
if (list->cell.car == NULL) {
|
||||
return list;
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_evaluate_builtin_form(struct ucl_state *state, struct ucl_object *list) {
|
||||
// TODO: Recursively eval args
|
||||
struct ucl_object *evaluated_list = ucl_nil_create();
|
||||
|
||||
@@ -31,8 +27,6 @@ struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object
|
||||
result = fun->builtin(state, args);
|
||||
}
|
||||
|
||||
// TODO: Non-builtins
|
||||
|
||||
// TODO: cleanup
|
||||
|
||||
return result;
|
||||
@@ -42,29 +36,45 @@ struct ucl_object *ucl_evaluate_special_form(struct ucl_state *state, struct ucl
|
||||
// TODO: Recursively eval args
|
||||
const char *fun_sym = ucl_car(list)->symbol;
|
||||
|
||||
if (strcmp(fun_sym, "let")) {
|
||||
return ucl_evaluate_list(state, list);
|
||||
}
|
||||
|
||||
struct ucl_object *fun = ucl_state_get(state, ucl_car(list)->symbol);
|
||||
struct ucl_object *args = ucl_cdr(list);
|
||||
struct ucl_object *result = NULL;
|
||||
|
||||
assert(fun->type == UCL_TYPE_BUILTIN);
|
||||
if (fun->type == UCL_TYPE_BUILTIN) {
|
||||
// TODO: check for errors
|
||||
result = fun->builtin(state, args);
|
||||
}
|
||||
result = fun->special(state, args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object *list) {
|
||||
if (list->cell.car == NULL) {
|
||||
return list;
|
||||
}
|
||||
|
||||
struct ucl_object *fun_sym = ucl_car(list);
|
||||
if (fun_sym->type != UCL_TYPE_SYMBOL) {
|
||||
return ucl_error_create("Unknown function symbol");
|
||||
}
|
||||
struct ucl_object *fun = ucl_state_get(state, fun_sym->symbol);
|
||||
UCL_RET_IF_ERROR(fun);
|
||||
|
||||
if (fun->type == UCL_TYPE_SPECIAL) {
|
||||
return ucl_evaluate_special_form(state, list);
|
||||
} else if (fun->type == UCL_TYPE_BUILTIN) {
|
||||
return ucl_evaluate_builtin_form(state, list);
|
||||
} else {
|
||||
assert(0);
|
||||
// TODO: Lisp functions and other errors
|
||||
}
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_evaluate(struct ucl_state *state, struct ucl_object *obj) {
|
||||
assert(obj != NULL);
|
||||
|
||||
switch (obj->type) {
|
||||
case UCL_TYPE_CELL:
|
||||
return ucl_evaluate_special_form(state, obj);
|
||||
return ucl_evaluate_list(state, obj);
|
||||
case UCL_TYPE_SYMBOL:
|
||||
return ucl_state_get(state, obj->symbol);
|
||||
case UCL_TYPE_INT:
|
||||
@@ -72,6 +82,7 @@ struct ucl_object *ucl_evaluate(struct ucl_state *state, struct ucl_object *obj)
|
||||
case UCL_TYPE_ERROR:
|
||||
return obj;
|
||||
case UCL_TYPE_BUILTIN:
|
||||
case UCL_TYPE_SPECIAL:
|
||||
case UCL_TYPE_COUNT:
|
||||
assert(0);
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user