-
Notifications
You must be signed in to change notification settings - Fork 1
/
FACT_var.c
81 lines (70 loc) · 2.18 KB
/
FACT_var.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* This file is part of FACT.
*
* FACT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FACT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FACT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FACT.h"
#include "FACT_types.h"
#include "FACT_hash.h"
#include "FACT_vm.h"
#include "FACT_error.h"
#include <string.h>
/* Lexically global - not thread global. */
FACT_t *FACT_get_global (FACT_scope_t env, char *name)
{
FACT_t *r;
size_t h;
for (h = FACT_get_hash (name, strlen (name));
env != NULL && env->lock_stat == UNLOCKED;
env = env->up) {
if ((r = FACT_find_in_table (env->vars, name, h)) != NULL)
return r;
}
/* As a last ditch effort, try the global variables table. */
return FACT_find_in_table (&Furlow_globals, name, h);
}
void FACT_get_var (char *name) /* Search all relevent scopes for a variable and push it to the stack. */
{
FACT_t new;
FACT_t *res;
size_t h;
/* Get the variable. If it doesn't exist, throw an error. */
res = FACT_get_global (CURR_THIS, name);
if (res == NULL)
FACT_throw_error (CURR_THIS, "undefined variable: %s", name);
#if 0
h = FACT_get_hash (name, strlen (name));
if ((res = FACT_find_in_table (CURR_THIS->vars, name, h)) == NULL)
if ((res = FACT_find_in_table (&Furlow_globals, name, h)) == NULL) {
/* Add an unset variable. */
new.type = UNSET_TYPE;
new.ap = name;
new.home = CURR_THIS->vars;
res = &new;
}
#endif
/* Push the variable to the var stack. */
push_v (*res);
}
bool FACT_is_circular (FACT_scope_t env)
{
bool r;
if (env == NULL)
return false;
if (*env->marked)
return true;
*env->marked = true;
r = FACT_is_circular (env->up);
*env->marked = false;
return r;
}