1 hour ago, desertfish said:
It no longer uses the software-eval-stack for that.
Hi! Is this "software-eval-stack" you mention a software-based stack used for mathematical computations based on a RPN-type stack? E.g. 2+3 becomes 2, PUSH, 3, PUSH, +? This is what I am using for my BASIC compiler. If so, it does do a lot of function calling and can be greatly optimized if one bypasses the stack entirely but involves major compiler modifications as you mentioned. This is a sample code from my compiler using macros that greatly improves readability:
Quote
10 REM ASSIGNMENT
20 AX = 3 : REM NEED TO OPTIMIZE
30 V = ABS(AX + 2)
35 Q = 1 + 2 * 6 / 3
40 PRINT "THE END"
50 END
start
line
10
comment REM ASSIGNMENT
line
20
assignment
AX
3
comment REM NEED TO OPTIMIZE
line
30
assignment
V
abs
add_exp
AX
+
2
line
35
assignment
Q
add_exp
1
+
mul_exp
mul_exp
2
*
6
/
3
line
40
print "THE END"
line
50
end
Tree('start', [Tree('line', [Token('INT', '10'), Tree('comment', [Token('COMMENT', 'REM ASSIGNMENT')])]), Tree('line', [Token('INT', '20'), Tree('assignment', [Token('VAR_ID', 'AX'), Token('INT', '3')]), Tree('comment', [Token('COMMENT', 'REM NEED TO OPTIMIZE')])]), Tree('line', [Token('INT', '30'), Tree('assignment', [Token('VAR_ID', 'V'), Tree('abs', [Tree('add_exp', [Token('VAR_ID', 'AX'), Token('ADD_OP', '+'), Token('INT', '2')])])])]), Tree('line', [Token('INT', '35'), Tree('assignment', [Token('VAR_ID', 'Q'), Tree('add_exp', [Token('INT', '1'), Token('ADD_OP', '+'), Tree('mul_exp', [Tree('mul_exp', [Token('INT', '2'), Token('MUL_OP', '*'), Token('INT', '6')]), Token('MUL_OP', '/'), Token('INT', '3')])])])]), Tree('line', [Token('INT', '40'), Tree('print', [Token('STRING', '"THE END"')])]), Tree('line', [Token('INT', '50'), Tree('end', [])])])
.include "macros.inc"
.include "header.inc"
.code
L10: ; REM ASSIGNMENT
L20: PushInt 3
PullVar AX
; REM NEED TO OPTIMIZE
L30: PushVar AX
PushInt 2
jsr ADD
jsr ABS
PullVar V
L35: PushInt 1
PushInt 2
PushInt 6
jsr UMUL
PushInt 3
jsr UDIV
jsr ADD
PullVar Q
L40: LoadAddress S0 ; to r0
jsr PrString
L50: rts
S0: .asciiz "the end"
AX: .res 2
V: .res 2
Q: .res 2
.include "io.asm"
.include "math.asm"
As you can see, line 20 does a PUSH and a PULL to/from stack for a simple AX=3. It could have simply copied over the INT 3 directly into VAR AX. I'm planning in writing a post-compiler optimizer much later. Note that I couldn't use VAR A since A is a reserved keyword in ca65!