Simplify runtime error reporting and move to platform common source.

This commit is contained in:
David Brown 2016-11-12 10:20:50 +00:00
parent ed7043324d
commit 716240bdd6
205 changed files with 986 additions and 1063 deletions

View file

@ -1,4 +1,4 @@
/* voc 1.95 [2016/11/11]. Bootstrapping compiler for address size 8, alignment 8. xtspaSfF */
/* voc 1.95 [2016/11/12]. Bootstrapping compiler for address size 8, alignment 8. xtspaSfF */
#define SHORTINT INT8
#define INTEGER INT16
@ -49,22 +49,19 @@ export ADDRESS *Platform_FileIdentity__typ;
export BOOLEAN Platform_Absent (INT16 e);
export INT16 Platform_ArgPos (CHAR *s, LONGINT s__len);
export void Platform_AssertFail (INT32 code);
export INT16 Platform_Chdir (CHAR *n, LONGINT n__len);
export INT16 Platform_Close (INT32 h);
export BOOLEAN Platform_ConnectionFailed (INT16 e);
export void Platform_Delay (INT32 ms);
export BOOLEAN Platform_DifferentFilesystems (INT16 e);
static void Platform_DisplayHaltCode (INT32 code);
static void Platform_EnableVT100 (void);
export INT16 Platform_Error (void);
export void Platform_Exit (INT16 code);
export void Platform_Exit (INT32 code);
export void Platform_GetArg (INT16 n, CHAR *val, LONGINT val__len);
export void Platform_GetClock (INT32 *t, INT32 *d);
export void Platform_GetEnv (CHAR *var, LONGINT var__len, CHAR *val, LONGINT val__len);
export void Platform_GetIntArg (INT16 n, INT32 *val);
export void Platform_GetTimeOfDay (INT32 *sec, INT32 *usec);
export void Platform_Halt (INT32 code);
export INT16 Platform_Identify (INT32 h, Platform_FileIdentity *identity, ADDRESS *identity__typ);
export INT16 Platform_IdentifyByName (CHAR *n, LONGINT n__len, Platform_FileIdentity *identity, ADDRESS *identity__typ);
export BOOLEAN Platform_Inaccessible (INT16 e);
@ -84,7 +81,6 @@ export BOOLEAN Platform_SameFile (Platform_FileIdentity i1, Platform_FileIdentit
export BOOLEAN Platform_SameFileTime (Platform_FileIdentity i1, Platform_FileIdentity i2);
export INT16 Platform_Seek (INT32 h, INT32 o, INT16 r);
export void Platform_SetBadInstructionHandler (Platform_SignalHandler handler);
export void Platform_SetHalt (Platform_HaltProcedure p);
export void Platform_SetMTime (Platform_FileIdentity *target, ADDRESS *target__typ, Platform_FileIdentity source);
export INT16 Platform_Size (INT32 h, INT32 *l);
export INT16 Platform_Sync (INT32 h);
@ -97,10 +93,6 @@ export INT16 Platform_Truncate (INT32 h, INT32 limit);
export INT16 Platform_Unlink (CHAR *n, LONGINT n__len);
export INT16 Platform_Write (INT32 h, INT32 p, INT32 l);
static void Platform_YMDHMStoClock (INT16 ye, INT16 mo, INT16 da, INT16 ho, INT16 mi, INT16 se, INT32 *t, INT32 *d);
static void Platform_errch (CHAR c);
static void Platform_errint (INT32 l);
static void Platform_errln (void);
static void Platform_errposint (INT32 l);
export BOOLEAN Platform_getEnv (CHAR *var, LONGINT var__len, CHAR *val, LONGINT val__len);
#include "WindowsWrapper.h"
@ -137,8 +129,6 @@ extern void Heap_InitHeap();
#define Platform_createProcess(str, str__len) (INTEGER)CreateProcess(0, (char*)str, 0,0,0,0,0,0,&si,&pi)
#define Platform_deleteFile(n, n__len) (INTEGER)DeleteFile((char*)n)
#define Platform_err() (INTEGER)GetLastError()
#define Platform_errc(c) WriteFile((HANDLE)Platform_StdOut, &c, 1, 0,0)
#define Platform_errstring(s, s__len) WriteFile((HANDLE)Platform_StdOut, s, s__len-1, 0,0)
#define Platform_exit(code) ExitProcess((UINT)code)
#define Platform_fileTimeToSysTime() SYSTEMTIME st; FileTimeToSystemTime(&ft, &st)
#define Platform_flushFileBuffers(h) (INTEGER)FlushFileBuffers((HANDLE)h)
@ -619,128 +609,11 @@ INT16 Platform_Rename (CHAR *o, LONGINT o__len, CHAR *n, LONGINT n__len)
__RETCHK;
}
void Platform_Exit (INT16 code)
void Platform_Exit (INT32 code)
{
Platform_exit(code);
}
static void Platform_errch (CHAR c)
{
Platform_errc(c);
}
static void Platform_errln (void)
{
Platform_errch(0x0d);
Platform_errch(0x0a);
}
static void Platform_errposint (INT32 l)
{
if (l > 10) {
Platform_errposint(__DIV(l, 10));
}
Platform_errch((CHAR)(48 + (int)__MOD(l, 10)));
}
static void Platform_errint (INT32 l)
{
if (l < 0) {
Platform_errch('-');
l = -l;
}
Platform_errposint(l);
}
static void Platform_DisplayHaltCode (INT32 code)
{
switch (code) {
case -1:
Platform_errstring((CHAR*)"Assertion failure.", 19);
break;
case -2:
Platform_errstring((CHAR*)"Index out of range.", 20);
break;
case -3:
Platform_errstring((CHAR*)"Reached end of function without reaching RETURN.", 49);
break;
case -4:
Platform_errstring((CHAR*)"CASE statement: no matching label and no ELSE.", 47);
break;
case -5:
Platform_errstring((CHAR*)"Type guard failed.", 19);
break;
case -6:
Platform_errstring((CHAR*)"Type equality failed.", 22);
break;
case -7:
Platform_errstring((CHAR*)"WITH statement type guard failed.", 34);
break;
case -8:
Platform_errstring((CHAR*)"SHORT: Value too large for shorter type.", 41);
break;
case -9:
Platform_errstring((CHAR*)"Heap interrupted while locked, but lockdepth = 0 at unlock.", 60);
break;
case -10:
Platform_errstring((CHAR*)"NIL access.", 12);
break;
case -11:
Platform_errstring((CHAR*)"Alignment error.", 17);
break;
case -12:
Platform_errstring((CHAR*)"Divide by zero.", 16);
break;
case -13:
Platform_errstring((CHAR*)"Arithmetic overflow/underflow.", 31);
break;
case -14:
Platform_errstring((CHAR*)"Invalid function argument.", 27);
break;
case -15:
Platform_errstring((CHAR*)"Internal error, e.g. Type descriptor size mismatch.", 52);
break;
case -20:
Platform_errstring((CHAR*)"Too many, or negative number of, elements in dynamic array.", 60);
break;
default:
break;
}
}
void Platform_Halt (INT32 code)
{
Platform_HaltCode = code;
if (Platform_HaltHandler != NIL) {
(*Platform_HaltHandler)(code);
}
Platform_errstring((CHAR*)"Terminated by Halt(", 20);
Platform_errint(code);
Platform_errstring((CHAR*)"). ", 4);
if (code < 0) {
Platform_DisplayHaltCode(code);
}
Platform_errln();
Platform_exit(__VAL(INT16, code));
}
void Platform_AssertFail (INT32 code)
{
Platform_errstring((CHAR*)"Assertion failure.", 19);
if (code != 0) {
Platform_errstring((CHAR*)" ASSERT code ", 14);
Platform_errint(code);
Platform_errstring((CHAR*)".", 2);
}
Platform_errln();
Platform_exit(__VAL(INT16, code));
}
void Platform_SetHalt (Platform_HaltProcedure p)
{
Platform_HaltHandler = p;
}
static void Platform_EnableVT100 (void)
{
INT32 mode;