(*
Halt - provides a more user friendly version of HALT, which takes
- four parameters to aid debugging.
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
*)
-PROCEDURE Halt (file: ARRAY OF CHAR; line: CARDINAL;
+PROCEDURE Halt (filename: ARRAY OF CHAR; line: CARDINAL;
function: ARRAY OF CHAR; description: ARRAY OF CHAR) ;
+(*
+ HaltC - provides a more user friendly version of HALT, which takes
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
+*)
+
+PROCEDURE HaltC (filename: ADDRESS; line: CARDINAL;
+ function, description: ADDRESS) ;
+
+
(*
ExitOnHalt - if HALT is executed then call exit with the exit code, e.
*)
*)
PROCEDURE ErrorMessage (message: ARRAY OF CHAR;
- file: ARRAY OF CHAR;
+ filename: ARRAY OF CHAR;
line: CARDINAL;
function: ARRAY OF CHAR) ;
IMPLEMENTATION MODULE M2RTS ;
-FROM libc IMPORT abort, exit, write, getenv, printf ;
+FROM libc IMPORT abort, exit, write, getenv, printf, strlen ;
(* FROM Builtins IMPORT strncmp, strcmp ; not available during bootstrap. *)
FROM NumberIO IMPORT CardToStr ;
FROM StrLib IMPORT StrCopy, StrLen, StrEqual ;
IMPORT M2EXCEPTION ;
IMPORT M2Dependent ;
+CONST
+ stderrFd = 2 ;
+
TYPE
PtrToChar = POINTER TO CHAR ;
VAR
n: INTEGER ;
BEGIN
- n := write (2, ADR (a), StrLen (a))
+ n := write (stderrFd, ADR (a), StrLen (a))
END ErrorString ;
+(*
+ ErrorStringC - writes a string to stderr.
+*)
+
+PROCEDURE ErrorStringC (str: ADDRESS) ;
+VAR
+ len: INTEGER ;
+BEGIN
+ len := write (stderrFd, str, strlen (str))
+END ErrorStringC ;
+
+
(*
ErrorMessage - emits an error message to stderr and then calls exit (1).
*)
PROCEDURE ErrorMessage (message: ARRAY OF CHAR;
- file: ARRAY OF CHAR;
+ filename: ARRAY OF CHAR;
line: CARDINAL;
function: ARRAY OF CHAR) <* noreturn *> ;
VAR
- LineNo: ARRAY [0..10] OF CHAR ;
+ buffer: ARRAY [0..10] OF CHAR ;
BEGIN
- ErrorString (file) ; ErrorString(':') ;
- CardToStr (line, 0, LineNo) ;
- ErrorString (LineNo) ; ErrorString(':') ;
+ ErrorString (filename) ; ErrorString(':') ;
+ CardToStr (line, 0, buffer) ;
+ ErrorString (buffer) ; ErrorString(':') ;
IF NOT StrEqual (function, '')
THEN
ErrorString ('in ') ;
ErrorString (' has caused ') ;
END ;
ErrorString (message) ;
- LineNo[0] := nl ; LineNo[1] := nul ;
- ErrorString (LineNo) ;
+ buffer[0] := nl ; buffer[1] := nul ;
+ ErrorString (buffer) ;
exit (1)
END ErrorMessage ;
+(*
+ ErrorMessageC - emits an error message to stderr and then calls exit (1).
+*)
+
+PROCEDURE ErrorMessageC (message, filename: ADDRESS;
+ line: CARDINAL;
+ function: ADDRESS) <* noreturn *> ;
+VAR
+ buffer: ARRAY [0..10] OF CHAR ;
+BEGIN
+ ErrorStringC (filename) ; ErrorString (':') ;
+ CardToStr (line, 0, buffer) ;
+ ErrorString (buffer) ; ErrorString(':') ;
+ IF strlen (function) > 0
+ THEN
+ ErrorString ('in ') ;
+ ErrorStringC (function) ;
+ ErrorString (' has caused ') ;
+ END ;
+ ErrorStringC (message) ;
+ buffer[0] := nl ; buffer[1] := nul ;
+ ErrorString (buffer) ;
+ exit (1)
+END ErrorMessageC ;
+
+
+(*
+ HaltC - provides a more user friendly version of HALT, which takes
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
+*)
+
+PROCEDURE HaltC (filename: ADDRESS; line: CARDINAL;
+ function, description: ADDRESS) ;
+BEGIN
+ ErrorMessageC (description, filename, line, function)
+END HaltC ;
+
+
(*
Halt - provides a more user friendly version of HALT, which takes
- four parameters to aid debugging.
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
*)
-PROCEDURE Halt (file: ARRAY OF CHAR; line: CARDINAL;
+PROCEDURE Halt (filename: ARRAY OF CHAR; line: CARDINAL;
function: ARRAY OF CHAR; description: ARRAY OF CHAR) ;
BEGIN
- ErrorMessage (description, file, line, function) ;
- HALT
+ ErrorMessage (description, filename, line, function)
END Halt ;
(*
Halt - provides a more user friendly version of HALT, which takes
- four parameters to aid debugging.
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
*)
-PROCEDURE Halt (file: ARRAY OF CHAR; line: CARDINAL;
+PROCEDURE Halt (filename: ARRAY OF CHAR; line: CARDINAL;
function: ARRAY OF CHAR; description: ARRAY OF CHAR)
- <* noreturn *> ;
+ <* noreturn *> ;
+
+
+(*
+ HaltC - provides a more user friendly version of HALT, which takes
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
+*)
+
+PROCEDURE HaltC (filename: ADDRESS; line: CARDINAL;
+ function, description: ADDRESS) ;
(*
*)
PROCEDURE ErrorMessage (message: ARRAY OF CHAR;
- file: ARRAY OF CHAR;
+ filename: ARRAY OF CHAR;
line: CARDINAL;
function: ARRAY OF CHAR) <* noreturn *> ;
IMPLEMENTATION MODULE M2RTS ;
-FROM libc IMPORT abort, exit, write, getenv, printf ;
+FROM libc IMPORT abort, exit, write, getenv, printf, strlen ;
(* FROM Builtins IMPORT strncmp, strcmp ; not available during bootstrap. *)
FROM NumberIO IMPORT CardToStr ;
FROM StrLib IMPORT StrCopy, StrLen, StrEqual ;
IMPORT M2EXCEPTION ;
IMPORT M2Dependent ;
+CONST
+ stderrFd = 2 ;
+
TYPE
PtrToChar = POINTER TO CHAR ;
VAR
n: INTEGER ;
BEGIN
- n := write (2, ADR (a), StrLen (a))
+ n := write (stderrFd, ADR (a), StrLen (a))
END ErrorString ;
+(*
+ ErrorStringC - writes a string to stderr.
+*)
+
+PROCEDURE ErrorStringC (str: ADDRESS) ;
+VAR
+ len: INTEGER ;
+BEGIN
+ len := write (stderrFd, str, strlen (str))
+END ErrorStringC ;
+
+
(*
ErrorMessage - emits an error message to stderr and then calls exit (1).
*)
PROCEDURE ErrorMessage (message: ARRAY OF CHAR;
- file: ARRAY OF CHAR;
+ filename: ARRAY OF CHAR;
line: CARDINAL;
function: ARRAY OF CHAR) <* noreturn *> ;
VAR
- LineNo: ARRAY [0..10] OF CHAR ;
+ buffer: ARRAY [0..10] OF CHAR ;
BEGIN
- ErrorString (file) ; ErrorString(':') ;
- CardToStr (line, 0, LineNo) ;
- ErrorString (LineNo) ; ErrorString(':') ;
+ ErrorString (filename) ; ErrorString(':') ;
+ CardToStr (line, 0, buffer) ;
+ ErrorString (buffer) ; ErrorString(':') ;
IF NOT StrEqual (function, '')
THEN
ErrorString ('in ') ;
ErrorString (' has caused ') ;
END ;
ErrorString (message) ;
- LineNo[0] := nl ; LineNo[1] := nul ;
- ErrorString (LineNo) ;
+ buffer[0] := nl ; buffer[1] := nul ;
+ ErrorString (buffer) ;
exit (1)
END ErrorMessage ;
+(*
+ ErrorMessageC - emits an error message to stderr and then calls exit (1).
+*)
+
+PROCEDURE ErrorMessageC (message, filename: ADDRESS;
+ line: CARDINAL;
+ function: ADDRESS) <* noreturn *> ;
+VAR
+ buffer: ARRAY [0..10] OF CHAR ;
+BEGIN
+ ErrorStringC (filename) ; ErrorString (':') ;
+ CardToStr (line, 0, buffer) ;
+ ErrorString (buffer) ; ErrorString(':') ;
+ IF strlen (function) > 0
+ THEN
+ ErrorString ('in ') ;
+ ErrorStringC (function) ;
+ ErrorString (' has caused ') ;
+ END ;
+ ErrorStringC (message) ;
+ buffer[0] := nl ; buffer[1] := nul ;
+ ErrorString (buffer) ;
+ exit (1)
+END ErrorMessageC ;
+
+
+(*
+ HaltC - provides a more user friendly version of HALT, which takes
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
+*)
+
+PROCEDURE HaltC (filename: ADDRESS; line: CARDINAL;
+ function, description: ADDRESS) ;
+BEGIN
+ ErrorMessageC (description, filename, line, function)
+END HaltC ;
+
+
(*
Halt - provides a more user friendly version of HALT, which takes
- four parameters to aid debugging.
+ four parameters to aid debugging. It writes an error message
+ to stderr and calls exit (1).
*)
-PROCEDURE Halt (file: ARRAY OF CHAR; line: CARDINAL;
+PROCEDURE Halt (filename: ARRAY OF CHAR; line: CARDINAL;
function: ARRAY OF CHAR; description: ARRAY OF CHAR) ;
BEGIN
- ErrorMessage (description, file, line, function) ;
- HALT
+ ErrorMessage (description, filename, line, function)
END Halt ;
{
}
+
static void
initSem (threadSem *sem, int value)
{
= (threadSem *)malloc (sizeof (threadSem));
nSemaphores += 1;
if (nSemaphores == SEM_POOL)
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__,
- "too many semaphores created");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
+ "too many semaphores created");
#else
threadSem *sem
= (threadSem *)malloc (sizeof (threadSem));
for (tid = 0; tid < nThreads; tid++)
if (pthread_self () == threadArray[tid].p)
return tid;
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__,
- "failed to find currentThread");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
+ "failed to find currentThread");
}
extern "C" int
static void
never (void)
{
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__,
- "the main thread should never call here");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
+ "the main thread should never call here");
}
static void *
#if 0
M2RTS_CoroutineException ( __FILE__, __LINE__, __COLUMN__, __FUNCTION__, "coroutine finishing");
#endif
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__, "execThread should never finish");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
+ "execThread should never finish");
return NULL;
}
#if defined(POOL)
nThreads += 1;
if (nThreads == THREAD_POOL)
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__, "too many threads created");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
+ "too many threads created");
return nThreads - 1;
#else
if (nThreads == 0)
/* set thread creation attributes. */
result = pthread_attr_init (&attr);
if (result != 0)
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__,
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
"failed to create thread attribute");
if (stackSize > 0)
{
result = pthread_attr_setstacksize (&attr, stackSize);
if (result != 0)
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__,
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
"failed to set stack size attribute");
}
result = pthread_create (&threadArray[tid].p, &attr, execThread,
(void *)&threadArray[tid]);
if (result != 0)
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__, "thread_create failed");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__, "thread_create failed");
tprintf (" created thread [%d] function = 0x%p 0x%p\n", tid, proc,
(void *)&threadArray[tid]);
return tid;
int tid = currentThread ();
if (!initialized)
- M2RTS_Halt (
+ M2RTS_HaltC (
__FILE__, __LINE__, __FUNCTION__,
"cannot transfer to a process before the process has been created");
if (tid == p2)
{
/* error. */
- M2RTS_Halt (__FILE__, __LINE__, __FUNCTION__,
- "attempting to transfer to ourself");
+ M2RTS_HaltC (__FILE__, __LINE__, __FUNCTION__,
+ "attempting to transfer to ourself");
}
else
{
extern "C" void M2RTS_Terminate (void);
extern "C" void M2RTS_DeconstructModules (void);
-extern "C" void M2RTS_Halt (const char *, int, const char *, const char *) __attribute__ ((noreturn));
+extern "C" void M2RTS_HaltC (const char *filename, int line,
+ const char *functionname, const char *desc)
+ __attribute__ ((noreturn));