diff options
Diffstat (limited to 'src/generator.c')
-rw-r--r-- | src/generator.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/generator.c b/src/generator.c index dc85517..1965ab9 100644 --- a/src/generator.c +++ b/src/generator.c | |||
@@ -102,7 +102,7 @@ void gen_const(const char name[], int value, Scope scope) { | |||
102 | 102 | ||
103 | case GLOBAL: | 103 | case GLOBAL: |
104 | glo_addConst(name); | 104 | glo_addConst(name); |
105 | fprintf(output, "%s: db QWORD %d\n", name, value); | 105 | fprintf(output, "%s dq %d\n", name, value); |
106 | return; | 106 | return; |
107 | } | 107 | } |
108 | } | 108 | } |
@@ -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, lineno); | ||
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, lineno); | ||
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, lineno); | ||
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, |