aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/generator.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/generator.c b/src/generator.c
index 60a2b89..c6140f1 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -397,21 +397,22 @@ int gen_negate_expr(int type) {
397 397
398int gen_value(const char ident[], Scope scope) { 398int gen_value(const char ident[], Scope scope) {
399 int l_addr = loc_get_addr(ident); 399 int l_addr = loc_get_addr(ident);
400 int g_addr = glo_get_addr(ident); 400
401 switch (scope) { 401 switch (scope) {
402 case GLOBAL:
403 fprintf(output, "push QWORD [globals + %d] ;%s\n", g_addr,
404 ident);
405 return glo_lookup(ident);
406 case LOCAL: 402 case LOCAL:
407 if (l_addr != -1) { 403 if (l_addr != -1) {
408 fprintf(output, "push QWORD [rbp - %d] ;%s\n", l_addr, 404 fprintf(output, "push QWORD [rbp - %d] ;%s\n", l_addr, ident);
409 ident);
410 return loc_lookup(ident); 405 return loc_lookup(ident);
411 } else {
412 fprintf(output, "push QWORD [globals + %d] ;%s\n", g_addr, ident);
413 return glo_lookup(ident);
414 } 406 }
407
408 case GLOBAL:
409 if (is_read_only(ident, scope))
410 fprintf(output, "push QWORD %s\n", ident);
411 else
412 fprintf(output, "push QWORD [globals + %d] ;%s\n", glo_get_addr(ident), ident);
413
414 return glo_lookup(ident);
415
415 default: 416 default:
416 exit(1); 417 exit(1);
417 } 418 }