check in changes
[IRC.git] / Robust / src / Runtime / runtime.c
1 #include "runtime.h"
2 #include "structdefs.h"
3 #include <string.h>
4
5 extern int classsize[];
6 #ifdef BOEHM_GC
7 #include "gc.h"
8 #define FREEMALLOC(x) GC_malloc(x)
9 #else
10 #define FREEMALLOC(x) calloc(1,x)
11 #endif
12
13 #ifdef TASK
14 int main(int argc, char **argv) {
15   int i;
16   /* Allocate startup object */
17   struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE);
18   /* Set flag */
19   flagor(startupobject,1);
20
21   /* Build array of strings */
22   struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc); 
23   startupobject->___parameters___=stringarray;
24
25   for(i=0;i<argc;i++) {
26     int length=strlen(argv[i]);
27     struct ___String___ *newstring=NewString(argv[i],length);
28     ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i]=newstring;
29   }
30   processtasks();
31 }
32
33 void flagor(void * ptr, int ormask) {
34   ((int *)ptr)[1]|=ormask;
35 }
36
37 void flagand(void * ptr, int andmask) {
38   ((int *)ptr)[1]&=andmask;
39 }
40
41 void processtasks();
42 #endif
43
44 int ___Object______hashcode____(struct ___Object___ * ___this___) {
45   return (int) ___this___;
46 }
47
48 void ___System______printString____L___String___(struct ___String___ * s) {
49     struct ArrayObject * chararray=s->___string___;
50     int i;
51     for(i=0;i<chararray->___length___;i++) {
52         short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i];
53         putchar(s);
54     }
55 }
56
57 void * allocate_new(int type) {
58   void * v=FREEMALLOC(classsize[type]);
59   *((int *)v)=type;
60   return v;
61 }
62
63 struct ArrayObject * allocate_newarray(int type, int length) {
64   struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
65   v->type=type;
66   v->___length___=length;
67   return v;
68 }
69
70 struct ___String___ * NewString(char *str,int length) {
71   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
72   struct ___String___ * strobj=allocate_new(STRINGTYPE);
73   int i;
74   strobj->___string___=chararray;
75   for(i=0;i<length;i++) {
76     ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i];  }
77   return strobj;
78 }
79
80 void failedboundschk() {
81   printf("Array out of bounds\n");
82   exit(-1);
83 }
84
85 void failednullptr() {
86   printf("Dereferenced a null pointer\n");
87   exit(-1);
88 }