sys.halt

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

sys.halt

ngogo
(A) In the book it is suggested to implement sys.halt by entering an infinite loop.
The VM emulator though never halts upon entering an infinite loop, I need to press the stop button to make the program stop. This doesn't seem like what we want with a halting function.
(B) Is the correct way of ending sys.init - a sys.halt, so upon returning from the main function the program halts?
Reply | Threaded
Open this post in threaded view
|

Re: sys.halt

cadet1620
Administrator
Sys.halt() is just an infinite loop. There is no "halt" CPU instruction so there is no "halt" VM command. You can look at the VM code for Sys.halt() in the supplied Sys.vm and determine what it does.

Yes, when Main.main() returns to Sys.init(), you should enter an infinite loop or call Sys.halt(). (I think calling Sys.halt() is conceptually cleaner, but an optimizing compiler would be able to compile while(true) to a single jump instruction.)

--Mark