- First, at this point, the idea is that the actual code generated for a method's
body would look like:
methLabel LINK A6,#-sizeOfLocalsAndTemps
MOVE A5,objPtrSaveDisp(A6)
...
code for the statements in the body
...
UNLK A6
RTD #-numberOfParams
Note: The correct value for "sizeOfLocalsAndTemps" won't be known until after
the code for the body is generated. You can use a symbolic label in the LINK
instruction and then generate an assembler EQU directive after the RTD.
- Second, while processing of each class, you should generate a method jump
table of the form:
jmpTabLabel DC superClassTableLabel
JMP method 1
JMP method 2
....
Note: We haven't actually talked about the initial DC yet, but I will shortly.
- Next, during semantic processing, you will restructure the tree so that
any invocation of the form:
methname( ... )
in which "methname" refers to a method from a surrounding class
will be rewritten as a tree for an invocation of the form
expr.methname( ... )
where the tree for "expr" is basically a chain of ref-var nodes designed to
generate code that will take the correct number of steps up the chain of static
links to get to the object with which "methname" is associated.
- Next (to last), when you encounter an invocation of the form:
methname( param1, param2, ... )
you will generate code for the form:
SUB #1,A7 // space to save A5?
code for param1
MOVE p1-op,-(A7)
code for param2
MOVE p2-op,-A7)
...
MOVE (A5),Ai // get addr of method tab
JSR 1+methNum*2(Ai)
ADD #1,A7 // pop space for saved A5
or
MOVE (SP)+,some-temp // access return value
- Finally, when you encounter an invocation of the form:
expr.methname( param1, param2, ... )
you will generate code for the form:
SUB #1,A7 // space to save A5?
code for param1
MOVE p1-op,-(A7)
code for param2
MOVE p2-op,-A7)
...
code for expr
MOVE expr-op,A5
MOVE (A5),Ai // get addr of method tab
JSR 1+methNum*2(Ai)
MOVE objPtrSaveDisp(A6),A5 // restore A5
ADD #1,A7 // pop space for saved A5
or
MOVE (SP)+,some-temp // access return value