Index: src/hugs.c =================================================================== RCS file: /cvs/hugs98/src/hugs.c,v retrieving revision 1.140 diff -u -r1.140 hugs.c --- src/hugs.c 5 Sep 2005 00:16:07 -0000 1.140 +++ src/hugs.c 5 Sep 2005 13:15:26 -0000 @@ -925,6 +925,10 @@ * main read-eval-print loop, with error trapping: * ------------------------------------------------------------------------*/ +void invoke(); +static Void local prefix(); + + static Void local interpreter(argc,argv)/* main interpreter loop */ Int argc; String argv[]; { @@ -945,10 +949,63 @@ __try { #endif - for (;;) { - Command cmd; + +#ifdef HUGS_FOR_WINDOWS + prefix(); + MessagePump(); +#else + for ( ; ; ) + { + prefix(); + invoke(); + } +#endif + + breakOn(FALSE); + +#if defined(_MSC_VER) && !defined(_MANAGED) + } __except ( ((GetExceptionCode() == EXCEPTION_STACK_OVERFLOW) ? + EXCEPTION_EXECUTE_HANDLER : + EXCEPTION_CONTINUE_SEARCH) ) { + /* Closely based on sample code in Nov 1999 Dr GUI MSDN column */ + char* stackPtr; + static SYSTEM_INFO si; + static MEMORY_BASIC_INFORMATION mi; + static DWORD protect; + + /* get at the current stack pointer */ + _asm mov stackPtr, esp; + + /* query for page size + VM info for the allocation chunk we're currently in. */ + GetSystemInfo(&si); + VirtualQuery(stackPtr, &mi, sizeof(mi)); + + /* Abandon the C stack and, most importantly, re-insert + the page guard bit. Do this on the page above the + current one, not the one where the exception was raised. */ + stackPtr = (LPBYTE) (mi.BaseAddress) - si.dwPageSize; + if ( VirtualFree(mi.AllocationBase, + (LPBYTE)stackPtr - (LPBYTE) mi.AllocationBase, + MEM_DECOMMIT) && + VirtualProtect(stackPtr, si.dwPageSize, + PAGE_GUARD | PAGE_READWRITE, &protect) ) { + + /* careful not to do a garbage collection here (as it may have caused the overflow). */ + ERRTEXT "ERROR - C stack overflow" + /* EEND does a longjmp back to a sane state. */ + EEND; + } else { + fatal("C stack overflow; unable to recover."); + } + } +#endif +} + + +static Void local prefix() +{ everybody(RESET); /* reset to sensible initial state */ dropScriptsFrom(numLoadedScripts()-1); /* remove partially loaded scripts */ /* not counting prelude as a script*/ @@ -956,7 +1013,11 @@ #if HUGS_FOR_WINDOWS InAutoReloadFiles = FALSE; #endif +} +void invoke() /* main interpreter loop */ + { + Command cmd; cmd = readCommand(cmds, (Char)':', (Char)'!'); #if WANT_TIMER updateTimers(); @@ -1048,44 +1109,6 @@ Printf("Elapsed time (ms): %ld (user), %ld (system)\n", millisecs(userElapsed), millisecs(systElapsed)); #endif - } - breakOn(FALSE); -#if defined(_MSC_VER) && !defined(_MANAGED) - } __except ( ((GetExceptionCode() == EXCEPTION_STACK_OVERFLOW) ? - EXCEPTION_EXECUTE_HANDLER : - EXCEPTION_CONTINUE_SEARCH) ) { - /* Closely based on sample code in Nov 1999 Dr GUI MSDN column */ - char* stackPtr; - static SYSTEM_INFO si; - static MEMORY_BASIC_INFORMATION mi; - static DWORD protect; - - /* get at the current stack pointer */ - _asm mov stackPtr, esp; - - /* query for page size + VM info for the allocation chunk we're currently in. */ - GetSystemInfo(&si); - VirtualQuery(stackPtr, &mi, sizeof(mi)); - - /* Abandon the C stack and, most importantly, re-insert - the page guard bit. Do this on the page above the - current one, not the one where the exception was raised. */ - stackPtr = (LPBYTE) (mi.BaseAddress) - si.dwPageSize; - if ( VirtualFree(mi.AllocationBase, - (LPBYTE)stackPtr - (LPBYTE) mi.AllocationBase, - MEM_DECOMMIT) && - VirtualProtect(stackPtr, si.dwPageSize, - PAGE_GUARD | PAGE_READWRITE, &protect) ) { - - /* careful not to do a garbage collection here (as it may have caused the overflow). */ - ERRTEXT "ERROR - C stack overflow" - /* EEND does a longjmp back to a sane state. */ - EEND; - } else { - fatal("C stack overflow; unable to recover."); - } - } -#endif } /*-------------------------------------------------------------------------*/