Improve indirect function call code generation

This commit is contained in:
David Schmenk 2014-05-21 09:43:54 -07:00
parent 9fe7d4d29d
commit 5dd829161b
3 changed files with 22 additions and 21 deletions

View File

@ -50,7 +50,7 @@ TESTLIB: testlib.pla $(PLVM) $(PLASM)
test: test.pla TESTLIB $(PLVM) $(PLASM) test: test.pla TESTLIB $(PLVM) $(PLASM)
./$(PLASM) -AM < test.pla > test.a ./$(PLASM) -AM < test.pla > test.a
acme --setpc 4096 -o TEST.REL test.a acme --setpc 4096 -o TEST.REL test.a
./$(PLVM) TEST.REL MAIN ./$(PLVM) TEST.REL
debug: test.pla TESTLIB $(PLVM) $(PLASM) debug: test.pla TESTLIB $(PLVM) $(PLASM)
./$(PLASM) -AM < test.pla > test.a ./$(PLASM) -AM < test.pla > test.a

View File

@ -428,19 +428,7 @@ int parse_value(int rvalue)
/* /*
* Function call * Function call
*/ */
if (!emit_value) if (emit_value && !(type & (FUNC_TYPE | CONST_TYPE)))
{
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 (scan_lookahead() != CLOSE_PAREN_TOKEN) if (scan_lookahead() != CLOSE_PAREN_TOKEN)
emit_push(); emit_push();
@ -461,6 +449,19 @@ int parse_value(int rvalue)
emit_call(value, type); emit_call(value, type);
else else
{ {
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) if (cparams)
emit_pull(); emit_pull();
emit_ical(); emit_ical();

View File

@ -27,17 +27,17 @@ def ascii
next next
end end
def nums def nums(range)
word i word i
for i = -10 to 10 for i = -10 to range
puti(i) puti(i)
putnl putnl
next next
end end
export def main export def main(range)
cls cls
nums nums(range)
viewport(12, 12, 16, 8) viewport(12, 12, 16, 8)
ascii ascii
viewport(0, 0, 40, 24) viewport(0, 0, 40, 24)
@ -48,7 +48,7 @@ end
export def indirect export def indirect
word mainptr word mainptr
mainptr = @main mainptr = @main
*mainptr() return mainptr(10)
end end
indirect indirect