Re: Rationale behind constructor call chain... ( and comparison with
C++)
Tor Iver Wilhelmsen wrote:
Thomas Hawtin <usenet@tackline.plus.com> writes:
You could target the 6502 with a Java bytecode compiler, but that
has no invokevirtual instruction.
Really? All VMs I've seen for that small processors run interpreted,
not byte-compiled.
http://www.mts.net/~kbagnall/commodore/java.html
YA RLY
There are a number of reasons why you'd want to interpret on a small
platform. Probably the most important is that it requires much less
effort to write an interpreter over a compiler. It has nothing to do
with whether there is a one-to-one correspondence between JVM and
machine instructions.
I've seen a suspicious lack of details about what happens with JavaCard
implementations, although it does seem set up for cross compilation.
So, invokevirtual in 6502 (assuming we're not using "sideways" memory or
anything like that)
; zero page location
obj = 0 ; object to call
tmpA = 2 ; a temporary
; invokevirtual
; JSR to push return code onto stack first
; There is no JSR indirect
; (at least not in classic NMOS Mostek 6502).
JSR invokeCode
...
..invokeCode
; Called with return address on stack.
; We push method address onto stack (so two addresses)
; and RTS to jump to it.
; load vtbl/class from obj
LDY #0
LDA (obj), Y
STA tmpA+0
INY
LDA (obj), Y
STA tmpA+1
; tmpA now points to obj.vtbl
; push method address onto stack
; I think this is the right way around...
; Not sure if vtbl requires a fixed offset from actual address.
; An alternative method is to store and JMP indirect
LDY #methodOffset+1
LDA (tmpA), Y
PHA
DEY
LDA (tmpA), Y
PHA
; not return - jump to method
RTS
6502 was a 1980s thing for me, so I'm a bit rusty.
Actually checking my instructions (I used X for indirect postindexing,
at first), I see using RTS for an indirect jump is a standard idiom.
http://www.atarimax.com/jindroush.atari.org/aopc.html#RTS
Tom Hawtin