1 /* Implement runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
36 /* type definitions */
37 typedef void (*init_ptr) ();
38 typedef void (*rts_init_ptr) (int *argc, char *argv []);
40 typedef struct INIT_LIST
43 struct INIT_LIST *forward;
46 InitList *_ch_init_list = 0;
48 /* force linker to get correct RTS functions */
49 extern rts_init_ptr __RTS_INIT__;
50 extern init_ptr __RTS_MAIN_LOOP__;
51 extern init_ptr __RTS_FETCH_NUMBERS__;
52 extern init_ptr __RTS_FETCH_NAMES__;
53 static init_ptr *rts_dummies[4] =
57 &__RTS_FETCH_NUMBERS__,
61 /* chill argc and argv */
63 TVaryingCharType **chill_argv = NULL;
65 /* the program name for debugging purpose */
68 extern void *__xmalloc_ ();
71 * function __xrealloc_
74 * ptr pointer to reallocate
75 * size new number of bytes
81 * This is the general reallocation routine for libchill
86 __xrealloc_ (ptr, size)
90 void *tmp = realloc (ptr, size);
94 fprintf (stderr, "ChillLib: Out of heap space.\n");
102 setup_argc_argv (argc, argv)
108 chill_argv = __xmalloc_ ((argc + 1) * sizeof (TVaryingCharType *));
109 for (i = 0; i < argc; i++)
111 chill_argv[i] = __xmalloc_ (sizeof (TVaryingCharType) + strlen (argv[i]) + 1);
112 chill_argv[i]->len = strlen (argv[i]);
113 strcpy (chill_argv[i]->body, argv[i]);
115 chill_argv[chill_argc = argc] = NULL;
117 if ((progname = strrchr (argv[0], '/')) == 0)
122 } /* setup_argc_argv */
124 extern void __setexceptionStack ();
126 /*--------- main entry for each CHILL - program ----------*/
132 /* call look up for tasking */
133 (*__RTS_INIT__) (&argc, argv);
135 /* setup argc and argv */
136 setup_argc_argv (argc, argv);
138 /* clear exception stack */
139 __setexceptionStack (0);
141 /* now call code at module level */
142 while (_ch_init_list)
144 if (_ch_init_list->code)
145 (*(_ch_init_list->code)) ();
146 _ch_init_list = _ch_init_list->forward;
149 /* if we have rts linked, something will be done, else just return */
150 (*__RTS_MAIN_LOOP__) ();