Rename 'state' to 'scope'

This commit is contained in:
2022-11-14 22:49:02 -05:00
parent 706b4a586d
commit af88471b3a
21 changed files with 320 additions and 321 deletions

View File

@@ -2,7 +2,7 @@
#include "internal.h"
#include "utility.h"
#include "builtins.h"
#include "state.h"
#include "scope.h"
#include "lisp.h"
#include <assert.h>
@@ -11,7 +11,7 @@
#include <stdlib.h>
#include <stdio.h>
LISP_FUNC_1(ucl_builtin_type, state, arg) {
LISP_FUNC_1(ucl_builtin_type, scope, arg) {
switch (arg->type) {
case UCL_TYPE_CELL:
return ucl_symbol_create("list");
@@ -33,7 +33,7 @@ LISP_FUNC_1(ucl_builtin_type, state, arg) {
}
}
LISP_FUNC_1(ucl_builtin_error, state, arg) {
LISP_FUNC_1(ucl_builtin_error, scope, arg) {
if (arg->type != UCL_TYPE_STRING) {
return ucl_error_create("Expected type string passed to 'error'");
}
@@ -41,42 +41,42 @@ LISP_FUNC_1(ucl_builtin_error, state, arg) {
return ucl_error_create(arg->error);
}
LISP_FUNC_1(ucl_builtin_symbol_p, state, arg) {
LISP_FUNC_1(ucl_builtin_symbol_p, scope, arg) {
return ucl_predicate(arg->type == UCL_TYPE_SYMBOL);
}
LISP_FUNC_1(ucl_builtin_string_p, state, arg) {
LISP_FUNC_1(ucl_builtin_string_p, scope, arg) {
return ucl_predicate(arg->type == UCL_TYPE_STRING);
}
LISP_FUNC_1(ucl_builtin_int_p, state, arg) {
LISP_FUNC_1(ucl_builtin_int_p, scope, arg) {
return ucl_predicate(arg->type == UCL_TYPE_INT);
}
LISP_FUNC_1(ucl_builtin_list_p, state, arg) {
LISP_FUNC_1(ucl_builtin_list_p, scope, arg) {
return ucl_predicate(arg->type == UCL_TYPE_CELL);
}
LISP_FUNC_1(ucl_builtin_error_p, state, arg) {
LISP_FUNC_1(ucl_builtin_error_p, scope, arg) {
return ucl_predicate(arg->type == UCL_TYPE_ERROR);
}
LISP_FUNC_1(ucl_builtin_car, state, arg) {
LISP_FUNC_1(ucl_builtin_car, scope, arg) {
return ucl_car(arg);
}
LISP_FUNC_1(ucl_builtin_cdr, state, arg) {
LISP_FUNC_1(ucl_builtin_cdr, scope, arg) {
return ucl_cdr(arg);
}
LISP_FUNC_2(ucl_builtin_nth, state, n, list) {
LISP_FUNC_2(ucl_builtin_nth, scope, n, list) {
UCL_COND_OR_RET_ERROR(n->type == UCL_TYPE_INT, "First argument to nth must be an integer");
UCL_COND_OR_RET_ERROR(list->type == UCL_TYPE_CELL, "Second argument to nth must be a list");
return ucl_list_nth(list, n->integer);
}
LISP_FUNC_2(ucl_builtin_add, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_add, scope, arg0, arg1) {
if (arg0->type != UCL_TYPE_INT) {
return ucl_error_create("Invalid type of argument 0 to 'add'");
}
@@ -88,7 +88,7 @@ LISP_FUNC_2(ucl_builtin_add, state, arg0, arg1) {
return ucl_int_create(arg0->integer + arg1->integer);
}
LISP_FUNC_2(ucl_builtin_sub, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_sub, scope, arg0, arg1) {
if (arg0->type != UCL_TYPE_INT) {
return ucl_error_create("Invalid type of argument 0 to 'sub'");
}
@@ -100,7 +100,7 @@ LISP_FUNC_2(ucl_builtin_sub, state, arg0, arg1) {
return ucl_int_create(arg0->integer - arg1->integer);
}
LISP_FUNC_2(ucl_builtin_mul, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_mul, scope, arg0, arg1) {
if (arg0->type != UCL_TYPE_INT) {
return ucl_error_create("Invalid type of argument 0 to 'mul'");
}
@@ -112,7 +112,7 @@ LISP_FUNC_2(ucl_builtin_mul, state, arg0, arg1) {
return ucl_int_create(arg0->integer * arg1->integer);
}
LISP_FUNC_2(ucl_builtin_div, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_div, scope, arg0, arg1) {
if (arg0->type != UCL_TYPE_INT) {
return ucl_error_create("Invalid type of argument 0 to 'div'");
}
@@ -125,7 +125,7 @@ LISP_FUNC_2(ucl_builtin_div, state, arg0, arg1) {
return ucl_int_create(arg0->integer / arg1->integer);
}
LISP_FUNC_2(ucl_builtin_mod, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_mod, scope, arg0, arg1) {
if (arg0->type != UCL_TYPE_INT) {
return ucl_error_create("Invalid type of argument 0 to 'mod'");
}
@@ -137,7 +137,7 @@ LISP_FUNC_2(ucl_builtin_mod, state, arg0, arg1) {
return ucl_int_create(arg0->integer % arg1->integer);
}
LISP_FUNC_2(ucl_builtin_concat, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_concat, scope, arg0, arg1) {
if (arg0->type != UCL_TYPE_STRING) {
return ucl_error_create("Invalid type of argument 0 to 'concat'");
}
@@ -157,25 +157,25 @@ LISP_FUNC_2(ucl_builtin_concat, state, arg0, arg1) {
return result;
}
LISP_FUNC_0(ucl_builtin_now_millis_mono, state) {
LISP_FUNC_0(ucl_builtin_now_millis_mono, scope) {
// TODO: Implement and move to a 'platform' file
return NULL;
}
LISP_FUNC_1(ucl_builtin_print, state, arg0) {
LISP_FUNC_1(ucl_builtin_print, scope, arg0) {
ucl_print_obj(arg0);
return ucl_nil_create();
}
LISP_FUNC_1(ucl_builtin_printl, state, arg0) {
LISP_FUNC_1(ucl_builtin_printl, scope, arg0) {
ucl_print_obj(arg0);
printf("\n");
return ucl_nil_create();
}
struct ucl_object *ucl_builtin_list(struct ucl_state *state, struct ucl_object *args) {
struct ucl_object *ucl_builtin_list(struct ucl_scope *scope, struct ucl_object *args) {
struct ucl_object *head = ucl_nil_create();
FOREACH_LIST(args, iter, item) {
ucl_list_append(head, item);
@@ -184,57 +184,57 @@ struct ucl_object *ucl_builtin_list(struct ucl_state *state, struct ucl_object *
return head;
}
LISP_FUNC_2(ucl_builtin_mapcar, state, fun, elems) {
LISP_FUNC_2(ucl_builtin_mapcar, scope, fun, elems) {
// TODO: Support arbitrary number of 'elems' lists
struct ucl_object *result = ucl_nil_create();
FOREACH_LIST(elems, iter, elem) {
struct ucl_object *form = ucl_tuple_create(fun, elem);
struct ucl_object *value = ucl_evaluate(state, form);
struct ucl_object *value = ucl_evaluate(scope, form);
UCL_RET_IF_ERROR(value);
ucl_list_append(result, value);
}
return result;
}
LISP_FUNC_2(ucl_builtin_equal, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_equal, scope, arg0, arg1) {
return ucl_equal(arg0, arg1);
}
LISP_FUNC_2(ucl_builtin_gt, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_gt, scope, arg0, arg1) {
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "First argument to > must be an integer");
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "Second argument to > must be an integer");
return ucl_predicate(arg0->integer > arg1->integer);
}
LISP_FUNC_2(ucl_builtin_ge, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_ge, scope, arg0, arg1) {
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "First argument to >= must be an integer");
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "Second argument to >= must be an integer");
return ucl_predicate(arg0->integer > arg1->integer);
}
LISP_FUNC_2(ucl_builtin_lt, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_lt, scope, arg0, arg1) {
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "First argument to < must be an integer");
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "Second argument to < must be an integer");
return ucl_predicate(arg0->integer < arg1->integer);
}
LISP_FUNC_2(ucl_builtin_le, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_le, scope, arg0, arg1) {
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "First argument to <= must be an integer");
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "Second argument to <= must be an integer");
return ucl_predicate(arg0->integer < arg1->integer);
}
LISP_FUNC_2(ucl_builtin_num_eq, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_num_eq, scope, arg0, arg1) {
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "First argument to = must be an integer");
UCL_COND_OR_RET_ERROR(arg0->type == UCL_TYPE_INT, "Second argument to = must be an integer");
return ucl_predicate(arg0->integer == arg1->integer);
}
LISP_FUNC_2(ucl_builtin_xor, state, arg0, arg1) {
LISP_FUNC_2(ucl_builtin_xor, scope, arg0, arg1) {
return ucl_predicate(ucl_truthy_bool(arg0) || ucl_truthy_bool(arg1));
}
LISP_FUNC_1(ucl_builtin_not, state, arg0) {
LISP_FUNC_1(ucl_builtin_not, scope, arg0) {
return ucl_predicate(!ucl_truthy_bool(arg0));
}