| 1 | /* do not edit automatically generated by mc from M2RTS. */ |
| 2 | /* M2RTS.mod Implements the run time system facilities of Modula-2. |
| 3 | |
| 4 | Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 5 | Contributed by Gaius Mulley <[email protected]>. |
| 6 | |
| 7 | This file is part of GNU Modula-2. |
| 8 | |
| 9 | GNU Modula-2 is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 3, or (at your option) |
| 12 | any later version. |
| 13 | |
| 14 | GNU Modula-2 is distributed in the hope that it will be useful, but |
| 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | General Public License for more details. |
| 18 | |
| 19 | Under Section 7 of GPL version 3, you are granted additional |
| 20 | permissions described in the GCC Runtime Library Exception, version |
| 21 | 3.1, as published by the Free Software Foundation. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License and |
| 24 | a copy of the GCC Runtime Library Exception along with this program; |
| 25 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 26 | <http://www.gnu.org/licenses/>. */ |
| 27 | |
| 28 | #include <stdbool.h> |
| 29 | # if !defined (PROC_D) |
| 30 | # define PROC_D |
| 31 | typedef void (*PROC_t) (void); |
| 32 | typedef struct { PROC_t proc; } PROC; |
| 33 | # endif |
| 34 | |
| 35 | # if !defined (TRUE) |
| 36 | # define TRUE (1==1) |
| 37 | # endif |
| 38 | |
| 39 | # if !defined (FALSE) |
| 40 | # define FALSE (1==0) |
| 41 | # endif |
| 42 | |
| 43 | #include <string.h> |
| 44 | #include <limits.h> |
| 45 | #include <stdlib.h> |
| 46 | #include <unistd.h> |
| 47 | #define _M2RTS_C |
| 48 | |
| 49 | #include "GM2RTS.h" |
| 50 | # include "Glibc.h" |
| 51 | # include "GNumberIO.h" |
| 52 | # include "GStrLib.h" |
| 53 | # include "GSYSTEM.h" |
| 54 | # include "GASCII.h" |
| 55 | # include "GStorage.h" |
| 56 | # include "GRTExceptions.h" |
| 57 | # include "GM2EXCEPTION.h" |
| 58 | # include "GM2Dependent.h" |
| 59 | |
| 60 | typedef struct M2RTS_ArgCVEnvP_p M2RTS_ArgCVEnvP; |
| 61 | |
| 62 | # define stderrFd 2 |
| 63 | typedef char *M2RTS_PtrToChar; |
| 64 | |
| 65 | static int ExitValue; |
| 66 | static bool isHalting; |
| 67 | static bool CallExit; |
| 68 | static bool Initialized; |
| 69 | |
| 70 | /* |
| 71 | ConstructModules - resolve dependencies and then call each |
| 72 | module constructor in turn. |
| 73 | */ |
| 74 | |
| 75 | extern "C" void M2RTS_ConstructModules (void * applicationmodule, void * libname, void * overrideliborder, int argc, void * argv, void * envp); |
| 76 | |
| 77 | /* |
| 78 | DeconstructModules - resolve dependencies and then call each |
| 79 | module constructor in turn. |
| 80 | */ |
| 81 | |
| 82 | extern "C" void M2RTS_DeconstructModules (void * applicationmodule, void * libname, int argc, void * argv, void * envp); |
| 83 | |
| 84 | /* |
| 85 | RegisterModule - adds module name to the list of outstanding |
| 86 | modules which need to have their dependencies |
| 87 | explored to determine initialization order. |
| 88 | */ |
| 89 | |
| 90 | extern "C" void M2RTS_RegisterModule (void * name, void * libname, M2RTS_ArgCVEnvP init, M2RTS_ArgCVEnvP fini, PROC dependencies); |
| 91 | |
| 92 | /* |
| 93 | RequestDependant - used to specify that modulename is dependant upon |
| 94 | module dependantmodule. |
| 95 | */ |
| 96 | |
| 97 | extern "C" void M2RTS_RequestDependant (void * modulename, void * libname, void * dependantmodule, void * dependantlibname); |
| 98 | |
| 99 | /* |
| 100 | InstallTerminationProcedure - installs a procedure, p, which will |
| 101 | be called when the procedure |
| 102 | ExecuteTerminationProcedures |
| 103 | is invoked. It returns TRUE if the |
| 104 | procedure is installed. |
| 105 | */ |
| 106 | |
| 107 | extern "C" bool M2RTS_InstallTerminationProcedure (PROC p); |
| 108 | |
| 109 | /* |
| 110 | ExecuteInitialProcedures - executes the initial procedures installed by |
| 111 | InstallInitialProcedure. |
| 112 | */ |
| 113 | |
| 114 | extern "C" void M2RTS_ExecuteInitialProcedures (void); |
| 115 | |
| 116 | /* |
| 117 | InstallInitialProcedure - installs a procedure to be executed just |
| 118 | before the BEGIN code section of the |
| 119 | main program module. |
| 120 | */ |
| 121 | |
| 122 | extern "C" bool M2RTS_InstallInitialProcedure (PROC p); |
| 123 | |
| 124 | /* |
| 125 | ExecuteTerminationProcedures - calls each installed termination procedure |
| 126 | in reverse order. |
| 127 | */ |
| 128 | |
| 129 | extern "C" void M2RTS_ExecuteTerminationProcedures (void); |
| 130 | |
| 131 | /* |
| 132 | Terminate - provides compatibility for pim. It calls exit with |
| 133 | the exitcode provided in a prior call to ExitOnHalt |
| 134 | (or zero if ExitOnHalt was never called). It does |
| 135 | not call ExecuteTerminationProcedures. |
| 136 | */ |
| 137 | |
| 138 | extern "C" void M2RTS_Terminate (void); |
| 139 | |
| 140 | /* |
| 141 | HALT - terminate the current program. The procedure |
| 142 | ExecuteTerminationProcedures |
| 143 | is called before the program is stopped. The parameter |
| 144 | exitcode is optional. If the parameter is not supplied |
| 145 | HALT will call libc 'abort', otherwise it will exit with |
| 146 | the code supplied. Supplying a parameter to HALT has the |
| 147 | same effect as calling ExitOnHalt with the same code and |
| 148 | then calling HALT with no parameter. |
| 149 | */ |
| 150 | |
| 151 | extern "C" void M2RTS_HALT (int exitcode); |
| 152 | |
| 153 | /* |
| 154 | Halt - provides a more user friendly version of HALT, which takes |
| 155 | four parameters to aid debugging. It writes an error message |
| 156 | to stderr and calls exit (1). |
| 157 | */ |
| 158 | |
| 159 | extern "C" void M2RTS_Halt (const char *description_, unsigned int _description_high, const char *filename_, unsigned int _filename_high, const char *function_, unsigned int _function_high, unsigned int line); |
| 160 | |
| 161 | /* |
| 162 | HaltC - provides a more user friendly version of HALT, which takes |
| 163 | four parameters to aid debugging. It writes an error message |
| 164 | to stderr and calls exit (1). |
| 165 | */ |
| 166 | |
| 167 | extern "C" void M2RTS_HaltC (void * description, void * filename, void * function, unsigned int line); |
| 168 | |
| 169 | /* |
| 170 | ExitOnHalt - if HALT is executed then call exit with the exit code, e. |
| 171 | */ |
| 172 | |
| 173 | extern "C" void M2RTS_ExitOnHalt (int e); |
| 174 | |
| 175 | /* |
| 176 | ErrorMessage - emits an error message to stderr and then calls exit (1). |
| 177 | */ |
| 178 | |
| 179 | extern "C" void M2RTS_ErrorMessage (const char *message_, unsigned int _message_high, const char *filename_, unsigned int _filename_high, unsigned int line, const char *function_, unsigned int _function_high); |
| 180 | |
| 181 | /* |
| 182 | Length - returns the length of a string, a. This is called whenever |
| 183 | the user calls LENGTH and the parameter cannot be calculated |
| 184 | at compile time. |
| 185 | */ |
| 186 | |
| 187 | extern "C" unsigned int M2RTS_Length (const char *a_, unsigned int _a_high); |
| 188 | extern "C" void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 189 | extern "C" void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 190 | extern "C" void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 191 | extern "C" void M2RTS_DecException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 192 | extern "C" void M2RTS_InclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 193 | extern "C" void M2RTS_ExclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 194 | extern "C" void M2RTS_ShiftException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 195 | extern "C" void M2RTS_RotateException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 196 | extern "C" void M2RTS_StaticArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 197 | extern "C" void M2RTS_DynamicArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 198 | extern "C" void M2RTS_ForLoopBeginException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 199 | extern "C" void M2RTS_ForLoopToException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 200 | extern "C" void M2RTS_ForLoopEndException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 201 | extern "C" void M2RTS_PointerNilException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 202 | extern "C" void M2RTS_NoReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 203 | extern "C" void M2RTS_CaseException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 204 | extern "C" void M2RTS_WholeNonPosDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 205 | extern "C" void M2RTS_WholeNonPosModException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 206 | extern "C" void M2RTS_WholeZeroDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 207 | extern "C" void M2RTS_WholeZeroRemException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 208 | extern "C" void M2RTS_WholeValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 209 | extern "C" void M2RTS_RealValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 210 | extern "C" void M2RTS_ParameterException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 211 | extern "C" void M2RTS_NoException (void * filename, unsigned int line, unsigned int column, void * scope, void * message); |
| 212 | |
| 213 | /* |
| 214 | ErrorString - writes a string to stderr. |
| 215 | */ |
| 216 | |
| 217 | static void ErrorString (const char *a_, unsigned int _a_high); |
| 218 | |
| 219 | /* |
| 220 | ErrorStringC - writes a string to stderr. |
| 221 | */ |
| 222 | |
| 223 | static void ErrorStringC (void * str); |
| 224 | |
| 225 | /* |
| 226 | ErrorMessageC - emits an error message to stderr and then calls exit (1). |
| 227 | */ |
| 228 | |
| 229 | static void ErrorMessageC (void * message, void * filename, unsigned int line, void * function); |
| 230 | |
| 231 | /* |
| 232 | Init - initialize the initial, terminate procedure lists and booleans. |
| 233 | */ |
| 234 | |
| 235 | static void Init (void); |
| 236 | |
| 237 | /* |
| 238 | CheckInitialized - checks to see if this module has been initialized |
| 239 | and if it has not it calls Init. We need this |
| 240 | approach as this module is called by module ctors |
| 241 | before we reach main. |
| 242 | */ |
| 243 | |
| 244 | static void CheckInitialized (void); |
| 245 | |
| 246 | |
| 247 | /* |
| 248 | ErrorString - writes a string to stderr. |
| 249 | */ |
| 250 | |
| 251 | static void ErrorString (const char *a_, unsigned int _a_high) |
| 252 | { |
| 253 | int n; |
| 254 | char a[_a_high+1]; |
| 255 | |
| 256 | /* make a local copy of each unbounded array. */ |
| 257 | memcpy (a, a_, _a_high+1); |
| 258 | |
| 259 | n = static_cast<int> (libc_write (stderrFd, const_cast<void*> (static_cast<const void*>(a)), static_cast<size_t> (StrLib_StrLen ((const char *) a, _a_high)))); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | /* |
| 264 | ErrorStringC - writes a string to stderr. |
| 265 | */ |
| 266 | |
| 267 | static void ErrorStringC (void * str) |
| 268 | { |
| 269 | int len; |
| 270 | |
| 271 | len = static_cast<int> (libc_write (stderrFd, str, libc_strlen (str))); |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | ErrorMessageC - emits an error message to stderr and then calls exit (1). |
| 277 | */ |
| 278 | |
| 279 | static void ErrorMessageC (void * message, void * filename, unsigned int line, void * function) |
| 280 | { |
| 281 | typedef struct ErrorMessageC__T1_a ErrorMessageC__T1; |
| 282 | |
| 283 | struct ErrorMessageC__T1_a { char array[10+1]; }; |
| 284 | ErrorMessageC__T1 buffer; |
| 285 | |
| 286 | ErrorStringC (filename); |
| 287 | ErrorString ((const char *) ":", 1); |
| 288 | NumberIO_CardToStr (line, 0, (char *) &buffer.array[0], 10); |
| 289 | ErrorString ((const char *) &buffer.array[0], 10); |
| 290 | ErrorString ((const char *) ":", 1); |
| 291 | if ((libc_strlen (function)) > 0) |
| 292 | { |
| 293 | ErrorString ((const char *) "in ", 3); |
| 294 | ErrorStringC (function); |
| 295 | ErrorString ((const char *) " has caused ", 12); |
| 296 | } |
| 297 | ErrorStringC (message); |
| 298 | buffer.array[0] = ASCII_nl; |
| 299 | buffer.array[1] = ASCII_nul; |
| 300 | ErrorString ((const char *) &buffer.array[0], 10); |
| 301 | libc_exit (1); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | /* |
| 306 | Init - initialize the initial, terminate procedure lists and booleans. |
| 307 | */ |
| 308 | |
| 309 | static void Init (void) |
| 310 | { |
| 311 | ExitValue = 0; |
| 312 | isHalting = false; |
| 313 | CallExit = false; /* default by calling abort */ |
| 314 | } |
| 315 | |
| 316 | |
| 317 | /* |
| 318 | CheckInitialized - checks to see if this module has been initialized |
| 319 | and if it has not it calls Init. We need this |
| 320 | approach as this module is called by module ctors |
| 321 | before we reach main. |
| 322 | */ |
| 323 | |
| 324 | static void CheckInitialized (void) |
| 325 | { |
| 326 | if (! Initialized) |
| 327 | { |
| 328 | Initialized = true; |
| 329 | Init (); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /* |
| 335 | ConstructModules - resolve dependencies and then call each |
| 336 | module constructor in turn. |
| 337 | */ |
| 338 | |
| 339 | extern "C" void M2RTS_ConstructModules (void * applicationmodule, void * libname, void * overrideliborder, int argc, void * argv, void * envp) |
| 340 | { |
| 341 | M2Dependent_ConstructModules (applicationmodule, libname, overrideliborder, argc, argv, envp); |
| 342 | } |
| 343 | |
| 344 | |
| 345 | /* |
| 346 | DeconstructModules - resolve dependencies and then call each |
| 347 | module constructor in turn. |
| 348 | */ |
| 349 | |
| 350 | extern "C" void M2RTS_DeconstructModules (void * applicationmodule, void * libname, int argc, void * argv, void * envp) |
| 351 | { |
| 352 | M2Dependent_DeconstructModules (applicationmodule, libname, argc, argv, envp); |
| 353 | } |
| 354 | |
| 355 | |
| 356 | /* |
| 357 | RegisterModule - adds module name to the list of outstanding |
| 358 | modules which need to have their dependencies |
| 359 | explored to determine initialization order. |
| 360 | */ |
| 361 | |
| 362 | extern "C" void M2RTS_RegisterModule (void * name, void * libname, M2RTS_ArgCVEnvP init, M2RTS_ArgCVEnvP fini, PROC dependencies) |
| 363 | { |
| 364 | M2Dependent_RegisterModule (name, libname, (M2Dependent_ArgCVEnvP) {(M2Dependent_ArgCVEnvP_t) init.proc}, (M2Dependent_ArgCVEnvP) {(M2Dependent_ArgCVEnvP_t) fini.proc}, dependencies); |
| 365 | } |
| 366 | |
| 367 | |
| 368 | /* |
| 369 | RequestDependant - used to specify that modulename is dependant upon |
| 370 | module dependantmodule. |
| 371 | */ |
| 372 | |
| 373 | extern "C" void M2RTS_RequestDependant (void * modulename, void * libname, void * dependantmodule, void * dependantlibname) |
| 374 | { |
| 375 | M2Dependent_RequestDependant (modulename, libname, dependantmodule, dependantlibname); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | /* |
| 380 | InstallTerminationProcedure - installs a procedure, p, which will |
| 381 | be called when the procedure |
| 382 | ExecuteTerminationProcedures |
| 383 | is invoked. It returns TRUE if the |
| 384 | procedure is installed. |
| 385 | */ |
| 386 | |
| 387 | extern "C" bool M2RTS_InstallTerminationProcedure (PROC p) |
| 388 | { |
| 389 | return M2Dependent_InstallTerminationProcedure (p); |
| 390 | /* static analysis guarentees a RETURN statement will be used before here. */ |
| 391 | __builtin_unreachable (); |
| 392 | } |
| 393 | |
| 394 | |
| 395 | /* |
| 396 | ExecuteInitialProcedures - executes the initial procedures installed by |
| 397 | InstallInitialProcedure. |
| 398 | */ |
| 399 | |
| 400 | extern "C" void M2RTS_ExecuteInitialProcedures (void) |
| 401 | { |
| 402 | M2Dependent_ExecuteInitialProcedures (); |
| 403 | } |
| 404 | |
| 405 | |
| 406 | /* |
| 407 | InstallInitialProcedure - installs a procedure to be executed just |
| 408 | before the BEGIN code section of the |
| 409 | main program module. |
| 410 | */ |
| 411 | |
| 412 | extern "C" bool M2RTS_InstallInitialProcedure (PROC p) |
| 413 | { |
| 414 | return M2Dependent_InstallInitialProcedure (p); |
| 415 | /* static analysis guarentees a RETURN statement will be used before here. */ |
| 416 | __builtin_unreachable (); |
| 417 | } |
| 418 | |
| 419 | |
| 420 | /* |
| 421 | ExecuteTerminationProcedures - calls each installed termination procedure |
| 422 | in reverse order. |
| 423 | */ |
| 424 | |
| 425 | extern "C" void M2RTS_ExecuteTerminationProcedures (void) |
| 426 | { |
| 427 | M2Dependent_ExecuteTerminationProcedures (); |
| 428 | } |
| 429 | |
| 430 | |
| 431 | /* |
| 432 | Terminate - provides compatibility for pim. It calls exit with |
| 433 | the exitcode provided in a prior call to ExitOnHalt |
| 434 | (or zero if ExitOnHalt was never called). It does |
| 435 | not call ExecuteTerminationProcedures. |
| 436 | */ |
| 437 | |
| 438 | extern "C" void M2RTS_Terminate (void) |
| 439 | { |
| 440 | libc_exit (ExitValue); |
| 441 | } |
| 442 | |
| 443 | |
| 444 | /* |
| 445 | HALT - terminate the current program. The procedure |
| 446 | ExecuteTerminationProcedures |
| 447 | is called before the program is stopped. The parameter |
| 448 | exitcode is optional. If the parameter is not supplied |
| 449 | HALT will call libc 'abort', otherwise it will exit with |
| 450 | the code supplied. Supplying a parameter to HALT has the |
| 451 | same effect as calling ExitOnHalt with the same code and |
| 452 | then calling HALT with no parameter. |
| 453 | */ |
| 454 | |
| 455 | extern "C" void M2RTS_HALT (int exitcode) |
| 456 | { |
| 457 | if (exitcode != -1) |
| 458 | { |
| 459 | CallExit = true; |
| 460 | ExitValue = exitcode; |
| 461 | } |
| 462 | if (isHalting) |
| 463 | { |
| 464 | /* double HALT found */ |
| 465 | libc_exit (-1); |
| 466 | } |
| 467 | else |
| 468 | { |
| 469 | isHalting = true; |
| 470 | M2RTS_ExecuteTerminationProcedures (); |
| 471 | } |
| 472 | if (CallExit) |
| 473 | { |
| 474 | libc_exit (ExitValue); |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | libc_abort (); |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | |
| 483 | /* |
| 484 | Halt - provides a more user friendly version of HALT, which takes |
| 485 | four parameters to aid debugging. It writes an error message |
| 486 | to stderr and calls exit (1). |
| 487 | */ |
| 488 | |
| 489 | extern "C" void M2RTS_Halt (const char *description_, unsigned int _description_high, const char *filename_, unsigned int _filename_high, const char *function_, unsigned int _function_high, unsigned int line) |
| 490 | { |
| 491 | char description[_description_high+1]; |
| 492 | char filename[_filename_high+1]; |
| 493 | char function[_function_high+1]; |
| 494 | |
| 495 | /* make a local copy of each unbounded array. */ |
| 496 | memcpy (description, description_, _description_high+1); |
| 497 | memcpy (filename, filename_, _filename_high+1); |
| 498 | memcpy (function, function_, _function_high+1); |
| 499 | |
| 500 | M2RTS_ErrorMessage ((const char *) description, _description_high, (const char *) filename, _filename_high, line, (const char *) function, _function_high); |
| 501 | libc_exit (1); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | /* |
| 506 | HaltC - provides a more user friendly version of HALT, which takes |
| 507 | four parameters to aid debugging. It writes an error message |
| 508 | to stderr and calls exit (1). |
| 509 | */ |
| 510 | |
| 511 | extern "C" void M2RTS_HaltC (void * description, void * filename, void * function, unsigned int line) |
| 512 | { |
| 513 | ErrorMessageC (description, filename, line, function); |
| 514 | libc_exit (1); |
| 515 | } |
| 516 | |
| 517 | |
| 518 | /* |
| 519 | ExitOnHalt - if HALT is executed then call exit with the exit code, e. |
| 520 | */ |
| 521 | |
| 522 | extern "C" void M2RTS_ExitOnHalt (int e) |
| 523 | { |
| 524 | ExitValue = e; |
| 525 | CallExit = true; |
| 526 | } |
| 527 | |
| 528 | |
| 529 | /* |
| 530 | ErrorMessage - emits an error message to stderr and then calls exit (1). |
| 531 | */ |
| 532 | |
| 533 | extern "C" void M2RTS_ErrorMessage (const char *message_, unsigned int _message_high, const char *filename_, unsigned int _filename_high, unsigned int line, const char *function_, unsigned int _function_high) |
| 534 | { |
| 535 | typedef struct ErrorMessage__T2_a ErrorMessage__T2; |
| 536 | |
| 537 | struct ErrorMessage__T2_a { char array[10+1]; }; |
| 538 | ErrorMessage__T2 buffer; |
| 539 | char message[_message_high+1]; |
| 540 | char filename[_filename_high+1]; |
| 541 | char function[_function_high+1]; |
| 542 | |
| 543 | /* make a local copy of each unbounded array. */ |
| 544 | memcpy (message, message_, _message_high+1); |
| 545 | memcpy (filename, filename_, _filename_high+1); |
| 546 | memcpy (function, function_, _function_high+1); |
| 547 | |
| 548 | ErrorString ((const char *) filename, _filename_high); |
| 549 | ErrorString ((const char *) ":", 1); |
| 550 | NumberIO_CardToStr (line, 0, (char *) &buffer.array[0], 10); |
| 551 | ErrorString ((const char *) &buffer.array[0], 10); |
| 552 | ErrorString ((const char *) ":", 1); |
| 553 | if (! (StrLib_StrEqual ((const char *) function, _function_high, (const char *) "", 0))) |
| 554 | { |
| 555 | ErrorString ((const char *) "in ", 3); |
| 556 | ErrorString ((const char *) function, _function_high); |
| 557 | ErrorString ((const char *) " has caused ", 12); |
| 558 | } |
| 559 | ErrorString ((const char *) message, _message_high); |
| 560 | buffer.array[0] = ASCII_nl; |
| 561 | buffer.array[1] = ASCII_nul; |
| 562 | ErrorString ((const char *) &buffer.array[0], 10); |
| 563 | libc_exit (1); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | /* |
| 568 | Length - returns the length of a string, a. This is called whenever |
| 569 | the user calls LENGTH and the parameter cannot be calculated |
| 570 | at compile time. |
| 571 | */ |
| 572 | |
| 573 | extern "C" unsigned int M2RTS_Length (const char *a_, unsigned int _a_high) |
| 574 | { |
| 575 | unsigned int l; |
| 576 | unsigned int h; |
| 577 | char a[_a_high+1]; |
| 578 | |
| 579 | /* make a local copy of each unbounded array. */ |
| 580 | memcpy (a, a_, _a_high+1); |
| 581 | |
| 582 | l = 0; |
| 583 | h = _a_high; |
| 584 | while ((l <= h) && (a[l] != ASCII_nul)) |
| 585 | { |
| 586 | l += 1; |
| 587 | } |
| 588 | return l; |
| 589 | /* static analysis guarentees a RETURN statement will be used before here. */ |
| 590 | __builtin_unreachable (); |
| 591 | } |
| 592 | |
| 593 | extern "C" void M2RTS_AssignmentException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 594 | { |
| 595 | /* |
| 596 | The following are the runtime exception handler routines. |
| 597 | */ |
| 598 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 599 | } |
| 600 | |
| 601 | extern "C" void M2RTS_ReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 602 | { |
| 603 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 604 | } |
| 605 | |
| 606 | extern "C" void M2RTS_IncException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 607 | { |
| 608 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 609 | } |
| 610 | |
| 611 | extern "C" void M2RTS_DecException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 612 | { |
| 613 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 614 | } |
| 615 | |
| 616 | extern "C" void M2RTS_InclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 617 | { |
| 618 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 619 | } |
| 620 | |
| 621 | extern "C" void M2RTS_ExclException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 622 | { |
| 623 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 624 | } |
| 625 | |
| 626 | extern "C" void M2RTS_ShiftException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 627 | { |
| 628 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 629 | } |
| 630 | |
| 631 | extern "C" void M2RTS_RotateException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 632 | { |
| 633 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 634 | } |
| 635 | |
| 636 | extern "C" void M2RTS_StaticArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 637 | { |
| 638 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException)), filename, line, column, scope, message); |
| 639 | } |
| 640 | |
| 641 | extern "C" void M2RTS_DynamicArraySubscriptException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 642 | { |
| 643 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_indexException)), filename, line, column, scope, message); |
| 644 | } |
| 645 | |
| 646 | extern "C" void M2RTS_ForLoopBeginException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 647 | { |
| 648 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 649 | } |
| 650 | |
| 651 | extern "C" void M2RTS_ForLoopToException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 652 | { |
| 653 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 654 | } |
| 655 | |
| 656 | extern "C" void M2RTS_ForLoopEndException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 657 | { |
| 658 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 659 | } |
| 660 | |
| 661 | extern "C" void M2RTS_PointerNilException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 662 | { |
| 663 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_invalidLocation)), filename, line, column, scope, message); |
| 664 | } |
| 665 | |
| 666 | extern "C" void M2RTS_NoReturnException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 667 | { |
| 668 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_functionException)), filename, line, column, scope, message); |
| 669 | } |
| 670 | |
| 671 | extern "C" void M2RTS_CaseException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 672 | { |
| 673 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_caseSelectException)), filename, line, column, scope, message); |
| 674 | } |
| 675 | |
| 676 | extern "C" void M2RTS_WholeNonPosDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 677 | { |
| 678 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message); |
| 679 | } |
| 680 | |
| 681 | extern "C" void M2RTS_WholeNonPosModException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 682 | { |
| 683 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message); |
| 684 | } |
| 685 | |
| 686 | extern "C" void M2RTS_WholeZeroDivException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 687 | { |
| 688 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message); |
| 689 | } |
| 690 | |
| 691 | extern "C" void M2RTS_WholeZeroRemException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 692 | { |
| 693 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeDivException)), filename, line, column, scope, message); |
| 694 | } |
| 695 | |
| 696 | extern "C" void M2RTS_WholeValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 697 | { |
| 698 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_wholeValueException)), filename, line, column, scope, message); |
| 699 | } |
| 700 | |
| 701 | extern "C" void M2RTS_RealValueException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 702 | { |
| 703 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_realValueException)), filename, line, column, scope, message); |
| 704 | } |
| 705 | |
| 706 | extern "C" void M2RTS_ParameterException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 707 | { |
| 708 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_rangeException)), filename, line, column, scope, message); |
| 709 | } |
| 710 | |
| 711 | extern "C" void M2RTS_NoException (void * filename, unsigned int line, unsigned int column, void * scope, void * message) |
| 712 | { |
| 713 | RTExceptions_Raise ( ((unsigned int) (M2EXCEPTION_exException)), filename, line, column, scope, message); |
| 714 | } |
| 715 | |
| 716 | extern "C" void _M2_M2RTS_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 717 | { |
| 718 | CheckInitialized (); |
| 719 | } |
| 720 | |
| 721 | extern "C" void _M2_M2RTS_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 722 | { |
| 723 | } |