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

@@ -6,51 +6,51 @@
#include "internal.h"
#include "utility.h"
#include "testing_helpers.h"
#include "state.h"
#include "scope.h"
#include "builtins.h"
#include "special.h"
static struct ucl_object *input;
static struct ucl_object *response;
static struct ucl_state *state;
static struct ucl_scope *scope;
void setUp(void) {
input = NULL;
response = NULL;
state = ucl_state_create();
ucl_state_put(state, "let", ucl_special_create(ucl_special_let));
ucl_state_put(state, "defun", ucl_special_create(ucl_special_defun));
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
ucl_state_put(state, "error", ucl_builtin_create(ucl_builtin_error));
ucl_state_put(state, "list", ucl_builtin_create(ucl_builtin_list));
ucl_state_put(state, "setq", ucl_special_create(ucl_special_setq));
ucl_state_put(state, "car", ucl_builtin_create(ucl_builtin_car));
ucl_state_put(state, "cdr", ucl_builtin_create(ucl_builtin_cdr));
ucl_state_put(state, "nth", ucl_builtin_create(ucl_builtin_nth));
ucl_state_put(state, "mapcar", ucl_builtin_create(ucl_builtin_mapcar));
ucl_state_put(state, "lambda", ucl_special_create(ucl_special_lambda));
ucl_state_put(state, "quote", ucl_special_create(ucl_special_quote));
scope = ucl_scope_create();
ucl_scope_put(scope, "let", ucl_special_create(ucl_special_let));
ucl_scope_put(scope, "defun", ucl_special_create(ucl_special_defun));
ucl_scope_put(scope, "+", ucl_builtin_create(ucl_builtin_add));
ucl_scope_put(scope, "error", ucl_builtin_create(ucl_builtin_error));
ucl_scope_put(scope, "list", ucl_builtin_create(ucl_builtin_list));
ucl_scope_put(scope, "setq", ucl_special_create(ucl_special_setq));
ucl_scope_put(scope, "car", ucl_builtin_create(ucl_builtin_car));
ucl_scope_put(scope, "cdr", ucl_builtin_create(ucl_builtin_cdr));
ucl_scope_put(scope, "nth", ucl_builtin_create(ucl_builtin_nth));
ucl_scope_put(scope, "mapcar", ucl_builtin_create(ucl_builtin_mapcar));
ucl_scope_put(scope, "lambda", ucl_special_create(ucl_special_lambda));
ucl_scope_put(scope, "quote", ucl_special_create(ucl_special_quote));
}
void tearDown(void) {
// TODO: Implement GC so we can clean these both up
//ucl_object_delete(input);
input = NULL;
ucl_state_delete(state);
ucl_scope_delete(scope);
ucl_gc();
response = NULL;
state = NULL;
scope = NULL;
}
static struct ucl_object *eval (const char *code) {
struct ucl_object *sexp = ucl_parse(code);
return ucl_evaluate(state, ucl_car(sexp));
return ucl_evaluate(scope, ucl_car(sexp));
}
void test_simple_add(void) {
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
ucl_scope_put(scope, "+", ucl_builtin_create(ucl_builtin_add));
response = eval("(+ 2 3)");
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 5);
@@ -103,7 +103,7 @@ void test_eval_string(void) {
}
void test_eval_sym_defined(void) {
ucl_state_put(state, "foo", ucl_int_create(2));
ucl_scope_put(scope, "foo", ucl_int_create(2));
response = eval("foo");
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 2);

View File

@@ -162,7 +162,7 @@ static void test_tokenize_nil(void) {
TEST_ASSERT_NULL(token2->cell.cdr);
}
static void test_tokenize_statement(void) {
static void test_tokenize_scopement(void) {
response = ucl_tokenize("(foo)");
TEST_ASSERT_NOT_NULL(response);
@@ -344,7 +344,7 @@ int main(void) {
RUN_TEST(test_token_next_symbol_w_whitespace);
RUN_TEST(test_tokenize_empty_str);
RUN_TEST(test_tokenize_nil);
RUN_TEST(test_tokenize_statement);
RUN_TEST(test_tokenize_scopement);
RUN_TEST(test_parse_atom_symbol);
RUN_TEST(test_parse_atom_lparen);
RUN_TEST(test_parse_atom_rparen);

View File

@@ -4,38 +4,38 @@
#include "uclisp.h"
#include "internal.h"
#include "state.h"
#include "scope.h"
#include "utility.h"
#include "testing_helpers.h"
/* static struct ucl_parse_result *result; */
static struct ucl_state *state;
static struct ucl_scope *scope;
static struct ucl_object *response;
void setUp(void) {
state = ucl_state_create();
scope = ucl_scope_create();
}
void tearDown(void) {
ucl_state_delete(state);
state = NULL;
ucl_scope_delete(scope);
scope = NULL;
}
static void test_get_empty(void) {
response = ucl_state_get(state, "foo");
response = ucl_scope_get(scope, "foo");
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_put_get(void) {
ucl_state_put(state, "foo", ucl_t_create());
response = ucl_state_get(state, "foo");
ucl_scope_put(scope, "foo", ucl_t_create());
response = ucl_scope_get(scope, "foo");
TEST_ASSERT_T(response);
}
static void test_put2_get(void) {
ucl_state_put(state, "foo1", ucl_t_create());
ucl_state_put(state, "foo2", ucl_nil_create());
response = ucl_state_get(state, "foo1");
ucl_scope_put(scope, "foo1", ucl_t_create());
ucl_scope_put(scope, "foo2", ucl_nil_create());
response = ucl_scope_get(scope, "foo1");
TEST_ASSERT_T(response);
}
@@ -44,9 +44,9 @@ static void test_put_modify_get(void) {
ucl_string_create("bar"),
ucl_string_create("baz"));
ucl_state_put(state, "foo", obj);
ucl_scope_put(scope, "foo", obj);
ucl_list_append(obj, ucl_string_create("quux"));
response = ucl_state_get(state, "foo");
response = ucl_scope_get(scope, "foo");
TEST_ASSERT_OBJ_STRING(ucl_list_nth(response, 2));
TEST_ASSERT_EQUAL_STRING(ucl_list_nth(response, 2)->string, "quux");

View File

@@ -5,7 +5,7 @@
#include "uclisp.h"
#include "internal.h"
#include "utility.h"
#include "state.h"
#include "scope.h"
#include "testing_helpers.h"
static struct ucl_object *input;