aboutsummaryrefslogtreecommitdiff
path: root/src/generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/generator.c')
-rw-r--r--src/generator.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/generator.c b/src/generator.c
index 44fdeab..b75f7a8 100644
--- a/src/generator.c
+++ b/src/generator.c
@@ -265,7 +265,7 @@ void gen_ifelse_end(int idx) {
265 265
266// ----- OPERATORS ----- 266// ----- OPERATORS -----
267 267
268int gen_assign(const char ident[], Scope scope) { 268static int gen_assign_simple(const char ident[], Scope scope) {
269 int l_addr = loc_get_addr(ident); 269 int l_addr = loc_get_addr(ident);
270 int g_addr = glo_get_addr(ident); 270 int g_addr = glo_get_addr(ident);
271 271
@@ -291,7 +291,7 @@ int gen_assign(const char ident[], Scope scope) {
291 } 291 }
292} 292}
293 293
294int gen_assign_tab(const char ident[], Scope scope) { 294static int gen_assign_tab(const char ident[], Scope scope) {
295 int l_addr = loc_get_addr(ident); 295 int l_addr = loc_get_addr(ident);
296 int g_addr = glo_get_addr(ident); 296 int g_addr = glo_get_addr(ident);
297 297
@@ -317,6 +317,13 @@ int gen_assign_tab(const char ident[], Scope scope) {
317 } 317 }
318} 318}
319 319
320int gen_assign(const char ident[], Scope scope) {
321 switch (loc_lookup(ident)) {
322 case TAB: return gen_assign_tab(ident, scope);
323 default: return gen_assign_simple(ident, scope);
324 }
325}
326
320void gen_or(int left, int right, int idx) { 327void gen_or(int left, int right, int idx) {
321 check_expected_types(left, INT,TAB); 328 check_expected_types(left, INT,TAB);
322 check_expected_types(right, INT,TAB); 329 check_expected_types(right, INT,TAB);
@@ -447,7 +454,7 @@ int gen_negate_expr(int type) {
447 return type; 454 return type;
448} 455}
449 456
450int gen_value(const char ident[], Scope scope) { 457static int gen_value_simple(const char ident[], Scope scope) {
451 int l_addr = loc_get_addr(ident); 458 int l_addr = loc_get_addr(ident);
452 459
453 switch (scope) { 460 switch (scope) {
@@ -470,7 +477,8 @@ int gen_value(const char ident[], Scope scope) {
470 exit(1); 477 exit(1);
471 } 478 }
472} 479}
473int gen_value_tab(const char ident[], Scope scope) { 480
481static int gen_value_tab(const char ident[], Scope scope) {
474 int l_addr = loc_get_addr(ident); 482 int l_addr = loc_get_addr(ident);
475 int g_addr = glo_get_addr(ident); 483 int g_addr = glo_get_addr(ident);
476 switch (scope) { 484 switch (scope) {
@@ -489,6 +497,14 @@ int gen_value_tab(const char ident[], Scope scope) {
489 exit(1); 497 exit(1);
490 } 498 }
491} 499}
500
501int gen_value(const char ident[], Scope scope) {
502 switch (loc_lookup(ident)) {
503 case TAB: return gen_value_tab(ident, scope);
504 default: return gen_value_simple(ident, scope);
505 }
506}
507
492int gen_num(int value, Scope scope) { 508int gen_num(int value, Scope scope) {
493 fprintf(output, "push %d\n", value); 509 fprintf(output, "push %d\n", value);
494 return INT; 510 return INT;