problem with string.jack

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

problem with string.jack

bader
hi i have finished all the OS classes, they passed the tests. but when i try to put all of my classes to work together (take all of my vm's and try to test) the string test fails when trying to perform setInt(-num)
somehow it tries to divide by zero. i don't know where the problem could be since the all pass in separate.

a help would be appreciated,
bader
Reply | Threaded
Open this post in threaded view
|

Re: problem with string.jack

cadet1620
Administrator
bader wrote
hi i have finished all the OS classes, they passed the tests. but when i try to put all of my classes to work together (take all of my vm's and try to test) the string test fails when trying to perform setInt(-num)
somehow it tries to divide by zero. i don't know where the problem could be since the all pass in separate.
The first thing I would check is that there are no missing  init() calls in Sys.init(). For instance, your String.setInt() is using divide, so perhaps Math.init() didn't get called.

Also, you may have an initialization order problem in Sys.init()'s calls to the other init() functions. This usually causes crashes before Main.main() gets called in SysTest, but there may be something subtly wrong.

One way to approach debugging this is to copy your OS .vm files into the StringTest directory one at a time and see which one causes the error to appear.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: problem with string.jack

bader
well i call the init function of other classes exactly as the supplied vm, and in the same order, here is the result vm commands:
function Sys.init 0
call Memory.init 0
pop temp 0
call Math.init 0
pop temp 0
call Screen.init 0
pop temp 0
call Output.init 0
pop temp 0
call Keyboard.init 0
pop temp 0
call Main.main 0
pop temp 0
call Sys.halt 0
pop temp 0
push constant 0
return

-----------------------------------
Math.jack class causes the error to appear (its from the divide function)!
i believe that it tries to divide by zero, i assumed the validity of the input (did not handle errors) but when i compile with the supplied Math class it tells me ERR3 which is division by zero!

maybe my String goes through another class in its way to the math class, i will keep debuging.

thanks,
bader

Reply | Threaded
Open this post in threaded view
|

Re: problem with string.jack

bader
In reply to this post by cadet1620
i get 'That' segment must bee in heap or screen range Math.divide.106
Reply | Threaded
Open this post in threaded view
|

Re: problem with string.jack

cadet1620
Administrator
Details? Which of your OS .vm files are you loading besides String.vm?

Assuming it's just your String.vm and Math.vm, What happens if you delete your String.vm and run with the built-in version?

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: problem with string.jack

bader
i also tried to put all built in vm files (except for math), and still have the same problem.
"That segment must be in heap..."

note: in divide i use access to two global static arrays which are initialized in the Math.init.  
Reply | Threaded
Open this post in threaded view
|

Re: problem with string.jack

bader
thanks for the email reply, works fine now!