push local 0 - out of segment space

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

push local 0 - out of segment space

n.kinash
Hi.
Jack-code:

class Main {
    function void main() {
        var int result;
        result = 1;
        return;
    }
}


VM-code:

function Main.main 0
push constant 1
pop local 0
push constant 0
return

Error occurred in VM emulator: Out of segment space in Main.main.2

Its work if i change number of arguments:

function Main.main 1
push constant 1
pop local 0
push constant 0
return

Why VMemulator allocate memory for local, only if function have arguments?
Reply | Threaded
Open this post in threaded view
|

Re: push local 0 - out of segment space

cadet1620
Administrator
n.kinash wrote
Hi.
Jack-code:

class Main {
    function void main() {
        var int result;
        result = 1;
        return;
    }
}


VM-code:

function Main.main 0
push constant 1
pop local 0
push constant 0
return

Error occurred in VM emulator: Out of segment space in Main.main.2

Its work if i change number of arguments:

function Main.main 1
push constant 1
pop local 0
push constant 0
return

Why VMemulator allocate memory for local, only if function have arguments?
The number on the function command is the number of local variables the function uses, not the number of arguments.

The VM Emulator, and the code your VM translator writes for the function command, uses this number to allocate the local segment on the stack.

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: push local 0 - out of segment space

n.kinash
Ohh...it slipped from my mind

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: push local 0 - out of segment space

ashleyjsands
I did the exact same thing. It wasn't very clear in the textbook. I had to go back to Chapter 8 to find what it said about the function vm command.