From 5dd829161ba2b13254474e5b2fd9b90e0d647830 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Wed, 21 May 2014 09:43:54 -0700 Subject: [PATCH] Improve indirect function call code generation --- PLASMA/src/makefile | 2 +- PLASMA/src/parse.c | 31 ++++++++++++++++--------------- PLASMA/src/test.pla | 10 +++++----- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/PLASMA/src/makefile b/PLASMA/src/makefile index ac9e6648..0bf35cc5 100755 --- a/PLASMA/src/makefile +++ b/PLASMA/src/makefile @@ -50,7 +50,7 @@ TESTLIB: testlib.pla $(PLVM) $(PLASM) test: test.pla TESTLIB $(PLVM) $(PLASM) ./$(PLASM) -AM < test.pla > test.a acme --setpc 4096 -o TEST.REL test.a - ./$(PLVM) TEST.REL MAIN + ./$(PLVM) TEST.REL debug: test.pla TESTLIB $(PLVM) $(PLASM) ./$(PLASM) -AM < test.pla > test.a diff --git a/PLASMA/src/parse.c b/PLASMA/src/parse.c index fe00594b..34e3a34a 100755 --- a/PLASMA/src/parse.c +++ b/PLASMA/src/parse.c @@ -428,19 +428,7 @@ int parse_value(int rvalue) /* * Function call */ - if (!emit_value) - { - if (type & VAR_TYPE) - { - if (type & LOCAL_TYPE) - emit_llw(value); - else - emit_law(value, type); - } - else if (type & PTR_TYPE) - emit_lw(); - } - if (!(type & (FUNC_TYPE | CONST_TYPE))) + if (emit_value && !(type & (FUNC_TYPE | CONST_TYPE))) { if (scan_lookahead() != CLOSE_PAREN_TOKEN) emit_push(); @@ -461,8 +449,21 @@ int parse_value(int rvalue) emit_call(value, type); else { - if (cparams) - emit_pull(); + if (!emit_value) + { + if (type & VAR_TYPE) + { + if (type & LOCAL_TYPE) + emit_llw(value); + else + emit_law(value, type); + } + else if (type & PTR_TYPE) + emit_lw(); + } + else + if (cparams) + emit_pull(); emit_ical(); } emit_value = 1; diff --git a/PLASMA/src/test.pla b/PLASMA/src/test.pla index 1fa2a394..c8baedc2 100755 --- a/PLASMA/src/test.pla +++ b/PLASMA/src/test.pla @@ -27,17 +27,17 @@ def ascii next end -def nums +def nums(range) word i - for i = -10 to 10 + for i = -10 to range puti(i) putnl next end -export def main +export def main(range) cls - nums + nums(range) viewport(12, 12, 16, 8) ascii viewport(0, 0, 40, 24) @@ -48,7 +48,7 @@ end export def indirect word mainptr mainptr = @main - *mainptr() + return mainptr(10) end indirect