Add function evaluation
This commit is contained in:
@@ -19,17 +19,28 @@ struct ucl_object *ucl_evaluate_builtin_form(struct ucl_state *state, struct ucl
|
||||
};
|
||||
|
||||
struct ucl_object *fun = ucl_car(evaluated_list);
|
||||
struct ucl_object *args = ucl_cdr(evaluated_list);
|
||||
struct ucl_object *result = NULL;
|
||||
|
||||
assert(fun->type == UCL_TYPE_BUILTIN);
|
||||
if (fun->type == UCL_TYPE_BUILTIN) {
|
||||
struct ucl_object *args = ucl_cdr(evaluated_list);
|
||||
result = fun->builtin(state, args);
|
||||
} else if (fun->type == UCL_TYPE_CELL) {
|
||||
struct ucl_state *fun_state = ucl_state_create_child(state);
|
||||
struct ucl_object *fun_arg_syms = ucl_car(fun);
|
||||
struct ucl_object *fun_forms = ucl_cdr(fun);
|
||||
int i = 0;
|
||||
FOREACH_LIST(fun_arg_syms, iter, sym) {
|
||||
ucl_state_put(fun_state, sym->symbol, ucl_list_nth(evaluated_list, i + 1));
|
||||
i++;
|
||||
}
|
||||
result = ucl_progn(fun_state, fun_forms);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// TODO: cleanup
|
||||
|
||||
return result;
|
||||
return (result == NULL) ? ucl_nil_create() : result;
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_evaluate_special_form(struct ucl_state *state, struct ucl_object *list) {
|
||||
@@ -45,7 +56,18 @@ struct ucl_object *ucl_evaluate_special_form(struct ucl_state *state, struct ucl
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_evaluate_lisp_form(struct ucl_state *state, struct ucl_object *list) {
|
||||
// TODO: Recursively eval args
|
||||
const char *fun_sym = ucl_car(list)->symbol;
|
||||
|
||||
struct ucl_object *fun = ucl_state_get(state, ucl_car(list)->symbol);
|
||||
struct ucl_object *args = ucl_cdr(list);
|
||||
struct ucl_object *result = NULL;
|
||||
|
||||
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) {
|
||||
@@ -61,7 +83,7 @@ struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object
|
||||
|
||||
if (fun->type == UCL_TYPE_SPECIAL) {
|
||||
return ucl_evaluate_special_form(state, list);
|
||||
} else if (fun->type == UCL_TYPE_BUILTIN) {
|
||||
} else if (fun->type == UCL_TYPE_BUILTIN || fun->type == UCL_TYPE_CELL) {
|
||||
return ucl_evaluate_builtin_form(state, list);
|
||||
} else {
|
||||
assert(0);
|
||||
|
||||
Reference in New Issue
Block a user