Add setq special form
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <string.h>
|
||||
|
||||
struct ucl_object *ucl_evaluate_builtin_form(struct ucl_state *state, struct ucl_object *list) {
|
||||
// TODO: Recursively eval args
|
||||
// TODO: Reasonably split builtin and non-builtin evaluation
|
||||
struct ucl_object *evaluated_list = ucl_nil_create();
|
||||
|
||||
FOREACH_LIST(list, iter, item) {
|
||||
|
||||
@@ -16,6 +16,7 @@ int main(int argc, const char **argv) {
|
||||
ucl_state_put(state, "let", ucl_special_create(ucl_special_let));
|
||||
ucl_state_put(state, "if", ucl_special_create(ucl_special_if));
|
||||
ucl_state_put(state, "defun", ucl_special_create(ucl_special_defun));
|
||||
ucl_state_put(state, "setq", ucl_special_create(ucl_special_setq));
|
||||
|
||||
ucl_state_put(state, "print", ucl_builtin_create(ucl_builtin_print));
|
||||
ucl_state_put(state, "list", ucl_builtin_create(ucl_builtin_list));
|
||||
|
||||
@@ -76,3 +76,17 @@ struct ucl_object *ucl_special_defun(struct ucl_state *state, struct ucl_object
|
||||
return fun_sym;
|
||||
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_special_setq(struct ucl_state *state, struct ucl_object *args) {
|
||||
// TODO: Check arguments
|
||||
struct ucl_object *sym = ucl_car(args);
|
||||
if (sym->type != UCL_TYPE_SYMBOL) {
|
||||
return ucl_error_create("First argument to defun must be a symbol");
|
||||
}
|
||||
|
||||
struct ucl_object *value = ucl_evaluate(state, ucl_list_nth(args, 1));
|
||||
|
||||
ucl_state_put(ucl_state_get_root(state), sym->symbol, value);
|
||||
|
||||
return sym;
|
||||
}
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
struct ucl_object *ucl_special_let(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_special_if(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_special_defun(struct ucl_state *state, struct ucl_object *args);
|
||||
struct ucl_object *ucl_special_setq(struct ucl_state *state, struct ucl_object *args);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user