WIP: Hack in support for let binds
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "utility.h"
|
||||
#include "state.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object *list) {
|
||||
// TODO: Recursively eval args
|
||||
struct ucl_object *evaluated_list = ucl_nil_create();
|
||||
@@ -21,7 +23,7 @@ struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object
|
||||
|
||||
assert(fun->type == UCL_TYPE_BUILTIN);
|
||||
if (fun->type == UCL_TYPE_BUILTIN) {
|
||||
result = fun->builtin(args);
|
||||
result = fun->builtin(state, args);
|
||||
}
|
||||
|
||||
// TODO: Non-builtins
|
||||
@@ -31,12 +33,33 @@ struct ucl_object *ucl_evaluate_list(struct ucl_state *state, struct ucl_object
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_evaluate_special_form(struct ucl_state *state, struct ucl_object *list) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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_list(state, obj);
|
||||
return ucl_evaluate_special_form(state, obj);
|
||||
case UCL_TYPE_SYMBOL:
|
||||
return ucl_state_get(state, obj->symbol);
|
||||
case UCL_TYPE_INT:
|
||||
|
||||
Reference in New Issue
Block a user