How Does the VMEmulator Call Methods from Class Files

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How Does the VMEmulator Call Methods from Class Files

gnb03
Hi,

When we run 'Main'(for any of the programs from Chapter 11) in the VMEmulator, how does the VMEmulator 'see' the VM commands of the called methods belonging to other files?

Example(from Square - Main):
function Main.main 1
call SquareGame.new 0 
pop local 0
push local 0
call SquareGame.run 1
pop temp 0
push local 0
call SquareGame.dispose 1
pop temp 0
push constant 0
return

--> How does the VMEmulator know what to do when it see's 'Call SquareGame.new 0', 'call SquareGame.run 1', or 'call SquareGame.dispose 1'?

Is there an explanation for this in somewhere in the lectures or textbook that I missed? If not, could someone give me a brief explanation of this or point me towards a good explanation of this that already exists out there on the Internet?

Thanks,

Jason

Reply | Threaded
Open this post in threaded view
|

Re: How Does the VMEmulator Call Methods from Class Files

ivant
Are you asking about how the VMEmulator works internally? If so, it works by loading all the .vm files from a given folder (it will load any missing OS files from its installation folder). It then knows all the declared classes, functions, methods, etc. and starts executing from Main.main.

I don't think there is any documentation about it, but the VMEmulator along with most* of the other tools are open source and are available from the site. But note, that the code is a quite messy and at least I find it quite hard to refactor and improve. And I've tried several times during the last few years.

----
* All except the assembler and Jack compiler for obvious reasons.
Reply | Threaded
Open this post in threaded view
|

Re: How Does the VMEmulator Call Methods from Class Files

gnb03
Hi Ivant,

Yes, that answers my question. I was wondering if there was a simple explanation of how the VMEmulator worked.

I currently don't have the time and energy to look through the VMEmulator source code, so I'll remain content with my understanding of the VM Emulator as a black box.

Best,

Jason