Possible bug in VMEmulator when assigning static variables in Sys.init()

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

Possible bug in VMEmulator when assigning static variables in Sys.init()

dc136
I came across a possible VMEmulator bug while working on Project 12.

In debugging my OS modules, I found that assigning a value in Sys.init() to the one static variable I wanted to use in class Sys would cause the VMEmulator to set RAM[16] to the value assigned to this static variable, when previously, RAM[16] had been used for a static variable assigned in Math.init(). As far as I can tell, the spec for class Sys does not prohibit a static variable in class Sys.
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in VMEmulator when assigning static variables in Sys.init()

WBahn
Administrator
What's the bug?

The mapping from static variables to memory locations is done by the assembler and is based on the order in which they are first encountered by the assembler. If you add a new variable, all of the other variables will get mapped to different locations.

So what?

All that matters is that a given variable uses a consistent memory location within THAT program.
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in VMEmulator when assigning static variables in Sys.init()

dc136
I understand what the assembler is supposed to do. I am not seeing the correct behavior in VMEmulator when running my own OS modules if a static variable in Sys is created/assigned.

I can put up some test code later tonight, but here's a high level description of the behavior I was seeing:

class Sys {
    static String bar;

    function void Sys.init() {
        do Math.init() // Math.init() creates and assigns a static variable Math.foo. 
                       // VMEmulator does "push static 0" and stores it in RAM[16]
        do Output.init() // More static variables assigned, stored in RAM[17] and beyond
        
        ...
        
        let bar = "ERR" // VMEmulator takes the "push static 0" at the last step of this assignment,
                            // and stores the pointer to Sys.bar in RAM[16], overwriting Math.foo
      
        return;
    }

}

The assembler, which VMEmulator is handling internally, should not be assigning static 0 in Math to the same RAM address as static 0 in Sys.
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in VMEmulator when assigning static variables in Sys.init()

purple_pixie
Hah, I don't know how I didn't see this when I was writing up and posting the same issue.

I encountered the exact same problem (Math's statics being clobbered by Sys's) and also narrowed it down to .init() specifically.

Interestingly you can avoid this bug if you stick the assignment operation in a separate function and call that function within .init(), leading me to think the real issue is that the VMEmulator doesn't "know" that Sys.init() belongs to the class Sys, it just kind of 'exists' (possibly because of the way it is called on startup rather than being called properly)