Add function evaluation

This commit is contained in:
2022-11-04 09:16:02 -04:00
parent ddb5a8f842
commit d5b1729deb
7 changed files with 108 additions and 58 deletions

View File

@@ -4,8 +4,10 @@
#include "utility.h"
#include <stddef.h>
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
struct ucl_object *ucl_car(struct ucl_object *list) {
UCL_COND_OR_RET_ERROR(
@@ -117,3 +119,50 @@ struct ucl_object *ucl_list_append(struct ucl_object *list, struct ucl_object *o
return list;
}
void ucl_print_obj(struct ucl_object *obj) {
switch (obj->type) {
case UCL_TYPE_SYMBOL:
printf("%s", obj->symbol);
break;
case UCL_TYPE_INT:
printf("%d", obj->integer);
break;
case UCL_TYPE_STRING:
printf("\"%s\"", obj->string);
break;
case UCL_TYPE_ERROR:
printf("(error \"%s\")", obj->error);
break;
case UCL_TYPE_BUILTIN:
printf("<builtin %p>", obj->builtin);
break;
case UCL_TYPE_CELL: {
int first = true;
printf("%s", "(");
FOREACH_LIST(obj, iter, item) {
if (!first) {
printf(" ");
}
ucl_print_obj(item);
first = false;
}
printf("%s", ")");
break;
}
case UCL_TYPE_COUNT:
assert(0);
}
}
struct ucl_object *ucl_progn(struct ucl_state *state, struct ucl_object *forms) {
struct ucl_object *result = NULL;
FOREACH_LIST(forms, iter, form) {
result = ucl_evaluate(state, form);
if (result->type == UCL_TYPE_ERROR) {
return result;
}
}
return (result == NULL) ? ucl_nil_create() : result;
}