Search code examples
smalltalkgnu-smalltalk

Is it possible to manually exit out of Smalltalk vm with return code?


Basically, is there some kind of analogue of exit(-1) function in GNU Smalltalk 3.2.5? Or is there a way to configure it so that if it encounters an error during execution it'd return non-zero exit code? I want to be able to detect if gst executed the st code file successfully or if an error (syntax or runtime/exception) occurred.


Solution

  • Yes, it is possible using ObjectMemory quit: 0 or ObjectMemory quit: 1 etc. The source code for ObjectMemory quit:

    ObjectMemory class >> quit: exitStatus [
        "Quit the Smalltalk environment, passing the exitStatus integer
         to the OS. Files are closed and other similar cleanups occur."
    
        <category: 'builtins'>
        <primitive: VMpr_ObjectMemory_quit>
        SystemExceptions.WrongClass signalOn: exitStatus mustBe: SmallInteger
        ]
    

    Searching for 'quit' in the source code will provide examples of it in action.