Add defun without evaluation
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "utility.h"
|
||||
#include "builtins.h"
|
||||
#include "state.h"
|
||||
#include "lisp.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
@@ -24,6 +25,8 @@ LISP_FUNC_1(ucl_builtin_type, state, arg) {
|
||||
return ucl_symbol_create("error");
|
||||
case UCL_TYPE_BUILTIN:
|
||||
return ucl_symbol_create("builtin");
|
||||
case UCL_TYPE_SPECIAL:
|
||||
return ucl_symbol_create("special");
|
||||
case UCL_TYPE_COUNT:
|
||||
assert(0);
|
||||
return NULL;
|
||||
@@ -192,41 +195,6 @@ LISP_FUNC_1(ucl_builtin_print, state, arg0) {
|
||||
return ucl_nil_create();
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_builtin_let(struct ucl_state *state, struct ucl_object *args) {
|
||||
// TODO: Check arguments
|
||||
struct ucl_object *assignments = ucl_car(args);
|
||||
struct ucl_object *expressions = ucl_cdr(args);
|
||||
struct ucl_state *let_state = ucl_state_create_child(state);
|
||||
|
||||
FOREACH_LIST(assignments, iter, item) {
|
||||
// TODO: Check arguments
|
||||
struct ucl_object *sym = ucl_car(item);
|
||||
struct ucl_object *expr = ucl_car(ucl_cdr(item));
|
||||
struct ucl_object *value = ucl_evaluate(let_state, expr);
|
||||
|
||||
assert(sym->type == UCL_TYPE_SYMBOL);
|
||||
//assert(ucl_list_length(expr)->integer == 1);
|
||||
|
||||
if (value->type == UCL_TYPE_ERROR) {
|
||||
// TODO cleanup
|
||||
return value;
|
||||
}
|
||||
ucl_state_put(let_state, sym->symbol, value);
|
||||
}
|
||||
|
||||
struct ucl_object *result = NULL;
|
||||
FOREACH_LIST(expressions, iter, item) {
|
||||
result = ucl_evaluate(let_state, item);
|
||||
if (result->type == UCL_TYPE_ERROR) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ucl_state_delete(let_state);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct ucl_object *ucl_builtin_list(struct ucl_state *state, struct ucl_object *args) {
|
||||
struct ucl_object *head = ucl_nil_create();
|
||||
FOREACH_LIST(args, iter, item) {
|
||||
|
||||
Reference in New Issue
Block a user