diff options
Diffstat (limited to 'src/symbol_table.c')
-rw-r--r-- | src/symbol_table.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/symbol_table.c b/src/symbol_table.c index 483de4c..08124ac 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c | |||
@@ -66,7 +66,7 @@ int fun_lookup(const char name[], int nb_param) { | |||
66 | return -1; | 66 | return -1; |
67 | } | 67 | } |
68 | 68 | ||
69 | void glo_addVar(const char name[], int type) { | 69 | static void glo_add(const char name[], int type, bool read_only) { |
70 | int count; | 70 | int count; |
71 | for (count = 0; count < glo_symbol_table.size; count++) { | 71 | for (count = 0; count < glo_symbol_table.size; count++) { |
72 | if (!strcmp(glo_symbol_table.entries[count].name, name)) { | 72 | if (!strcmp(glo_symbol_table.entries[count].name, name)) { |
@@ -82,8 +82,16 @@ void glo_addVar(const char name[], int type) { | |||
82 | } | 82 | } |
83 | strcpy(glo_symbol_table.entries[glo_symbol_table.size - 1].name, name); | 83 | strcpy(glo_symbol_table.entries[glo_symbol_table.size - 1].name, name); |
84 | glo_symbol_table.entries[glo_symbol_table.size - 1].type = type; | 84 | glo_symbol_table.entries[glo_symbol_table.size - 1].type = type; |
85 | glo_symbol_table.entries[glo_symbol_table.size - 1].addr = | 85 | glo_symbol_table.entries[glo_symbol_table.size - 1].addr = (glo_symbol_table.size - 1) * 8; |
86 | (glo_symbol_table.size - 1) * 8; | 86 | glo_symbol_table.entries[glo_symbol_table.size - 1].read_only = read_only; |
87 | } | ||
88 | |||
89 | void glo_addVar(const char name[], int type) { | ||
90 | glo_add(name, type, false); | ||
91 | } | ||
92 | |||
93 | void glo_addConst(const char name[]) { | ||
94 | glo_add(name, INT, true); | ||
87 | } | 95 | } |
88 | 96 | ||
89 | // Verifies that the variable exists and returns the type | 97 | // Verifies that the variable exists and returns the type |
@@ -125,7 +133,7 @@ void glo_display_table() { | |||
125 | fprintf(output, "\n"); | 133 | fprintf(output, "\n"); |
126 | } | 134 | } |
127 | 135 | ||
128 | void loc_addVar(const char name[], int type) { | 136 | static void loc_add(const char name[], int type, bool read_only) { |
129 | int count; | 137 | int count; |
130 | for (count = 0; count < loc_symbol_table.size; count++) { | 138 | for (count = 0; count < loc_symbol_table.size; count++) { |
131 | if (!strcmp(loc_symbol_table.entries[count].name, name)) { | 139 | if (!strcmp(loc_symbol_table.entries[count].name, name)) { |
@@ -141,8 +149,16 @@ void loc_addVar(const char name[], int type) { | |||
141 | } | 149 | } |
142 | strcpy(loc_symbol_table.entries[loc_symbol_table.size - 1].name, name); | 150 | strcpy(loc_symbol_table.entries[loc_symbol_table.size - 1].name, name); |
143 | loc_symbol_table.entries[loc_symbol_table.size - 1].type = type; | 151 | loc_symbol_table.entries[loc_symbol_table.size - 1].type = type; |
144 | loc_symbol_table.entries[loc_symbol_table.size - 1].addr = | 152 | loc_symbol_table.entries[loc_symbol_table.size - 1].addr = (loc_symbol_table.size - 1) * 8 + 8; |
145 | (loc_symbol_table.size - 1) * 8 + 8; | 153 | loc_symbol_table.entries[loc_symbol_table.size - 1].read_only = read_only; |
154 | } | ||
155 | |||
156 | void loc_addVar(const char name[], int type) { | ||
157 | loc_add(name, type, false); | ||
158 | } | ||
159 | |||
160 | void loc_addConst(const char name[]) { | ||
161 | loc_add(name, INT, true); | ||
146 | } | 162 | } |
147 | 163 | ||
148 | int loc_lookup(const char name[]) { | 164 | int loc_lookup(const char name[]) { |