Order of .vm files?

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

Order of .vm files?

atom
For test purposes I've been taking the VM files, and appending all of the text to a single file that gets translated to VM. I'm having problems currently with the last test, the StaticsTest, and sometimes the order in which I appended the files had something to do with it.

To differentiate the static variables of the different function I'm keeping an inner record in a Java Stack, doing pushes and pops as I call and return from the functions and doing a peek() to get the string of the current function so any static symbol's name will contain the name of the current function. However, I'm getting lost somewhere.

The sourcecode of my implementation is available upon request. Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Order of .vm files?

ybakos
Hmmm, something doesn't sound right.

Static variables are scoped to each class. For example, a Foo class may have a static variable called bar. This should be known, symbolically, as Foo.bar.

In your description, you seem to be creating some kind of semantic relationship between function names and static variables, which does not sound right to me.

In other words, I see two "gotchas" that are causing your problem. First, by taking all .jack files, combining them into one "text file" for parsing, you're losing the ability to use the filename to allude to the scope of any static variable. Second, if you haven't recognized that static in Jack means "scoped to the class," then you're probably not creating the right symbol name for that static var in your symbol table.

Reply | Threaded
Open this post in threaded view
|

Re: Order of .vm files?

atom
Thanks for the quick reply. So it is recommended that I parse the VM to ASM separately and then combine them in one single ASM file?

Also, I followed the idea of the "semantic relation" because I found that during calls my static variables were overwritten. I guess I should try another thing then.