diff options
author | pacien | 2018-06-05 22:41:15 +0200 |
---|---|---|
committer | pacien | 2018-06-05 22:41:15 +0200 |
commit | 0f4b1600983f8afda41a02fec07424338785d81d (patch) | |
tree | cd1a3b2f599f7242c9fe76f9d66ca95ba58e34c0 /src/generator.c | |
parent | 864653f00dff0a8a1f37d8e9a732c1da8309a930 (diff) | |
download | tpc-compiler-0f4b1600983f8afda41a02fec07424338785d81d.tar.gz |
Prevent assigning to const
Diffstat (limited to 'src/generator.c')
-rw-r--r-- | src/generator.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/generator.c b/src/generator.c index 3ecfe0d..f32f468 100644 --- a/src/generator.c +++ b/src/generator.c | |||
@@ -159,7 +159,12 @@ void gen_check(const char name[], Scope scope) { | |||
159 | } | 159 | } |
160 | 160 | ||
161 | // ----- READ AND PRINT FUNCTIONS ----- | 161 | // ----- READ AND PRINT FUNCTIONS ----- |
162 | void gen_reade(const char name[]) { | 162 | void gen_reade(const char name[], Scope scope) { |
163 | if (is_read_only(name, scope)) { | ||
164 | fprintf(stderr, "Symbol \"%s\" at line %d is read only.\n", name, scope); | ||
165 | exit(1); | ||
166 | } | ||
167 | |||
163 | if (loc_lookup(name) != INT) { | 168 | if (loc_lookup(name) != INT) { |
164 | fprintf(stderr, "Need to be a INT in the reade() function\n"); | 169 | fprintf(stderr, "Need to be a INT in the reade() function\n"); |
165 | return; | 170 | return; |
@@ -174,7 +179,12 @@ void gen_reade(const char name[]) { | |||
174 | fprintf(output, "mov rax,globals\nadd rax,%d\ncall reade\n", g_addr); | 179 | fprintf(output, "mov rax,globals\nadd rax,%d\ncall reade\n", g_addr); |
175 | } | 180 | } |
176 | 181 | ||
177 | void gen_readc(const char name[]) { | 182 | void gen_readc(const char name[], Scope scope) { |
183 | if (is_read_only(name, scope)) { | ||
184 | fprintf(stderr, "Symbol \"%s\" at line %d is read only.\n", name, scope); | ||
185 | exit(1); | ||
186 | } | ||
187 | |||
178 | if (loc_lookup(name) != CHAR) { | 188 | if (loc_lookup(name) != CHAR) { |
179 | fprintf(stderr, "Need to be a CHAR in the readc() function\n"); | 189 | fprintf(stderr, "Need to be a CHAR in the readc() function\n"); |
180 | return; | 190 | return; |
@@ -233,6 +243,12 @@ void gen_ifelse_end(int idx) { | |||
233 | int gen_assign(const char ident[], Scope scope) { | 243 | int gen_assign(const char ident[], Scope scope) { |
234 | int l_addr = loc_get_addr(ident); | 244 | int l_addr = loc_get_addr(ident); |
235 | int g_addr = glo_get_addr(ident); | 245 | int g_addr = glo_get_addr(ident); |
246 | |||
247 | if (is_read_only(ident, scope)) { | ||
248 | fprintf(stderr, "Symbol \"%s\" at line %d is read only.\n", ident, scope); | ||
249 | exit(1); | ||
250 | } | ||
251 | |||
236 | switch (scope) { | 252 | switch (scope) { |
237 | case GLOBAL: | 253 | case GLOBAL: |
238 | fprintf(output, "pop QWORD [globals + %d] ;%s\n", g_addr, | 254 | fprintf(output, "pop QWORD [globals + %d] ;%s\n", g_addr, |