示例#1
0
文件: env.c 项目: 946336/calc_var
void Env_free_r(Env *e)
{
    if (e == NULL || *e == NULL) return;
    Env_free_r(&(*e)->rest);
    Env_free(e);
    *e = NULL;
}
示例#2
0
文件: test_env.c 项目: cjlarose/clike
char * all_tests() {
    mu_suite_start();
    mu_run_test(test_init);
    mu_run_test(test_global);
    mu_run_test(test_local);

    Env_free(global);
    return NULL;
}
示例#3
0
文件: test_env.c 项目: cjlarose/clike
char * test_local() {
    Env * local_scope = Env_new(global);
    Symbol * local_sym1, * local_sym2;
    local_sym1 = (Symbol *) malloc(sizeof(Symbol));
    local_sym2 = (Symbol *) malloc(sizeof(Symbol));
    local_sym1->type = 3;
    local_sym2->type = 4;

    Env_put(local_scope, strdup("baz"), local_sym1); // new id name
    Env_put(local_scope, strdup("foo"), local_sym2); // already in global

    mu_assert(Env_get(local_scope, "baz")->type == 3, "Wrong type");
    mu_assert(Env_get(local_scope, "foo")->type == 4, "Wrong type");
    
    // test inheritance
    mu_assert(Env_get(local_scope, "bar") != NULL, "Cannot find global symbol");
    mu_assert(Env_get(local_scope, "bar")->type == 2, "Wrong type");

    Env_free(local_scope);
    return NULL;
}