checked in changes
[IRC.git] / Robust / src / Runtime / runtime.c
1 #include "runtime.h"
2 #include "structdefs.h"
3 extern int classsize[];
4 #ifdef BOEHM_GC
5 #include "gc.h"
6 #define FREEMALLOC(x) GC_malloc(x)
7 #else
8 #define FREEMALLOC(x) calloc(1,x)
9 #endif
10
11 int ___Object______hashcode____(struct ___Object___ * ___this___) {
12   return (int) ___this___;
13 }
14
15 /*void ___System______printInt____I(int x) {
16   printf("%d",x);
17   }*/
18
19 void ___System______printString____L___String___(struct ___String___ * s) {
20     struct ArrayObject * chararray=s->___string___;
21     int i;
22     for(i=0;i<chararray->___length___;i++) {
23         short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i];
24         putchar(s);
25     }
26 }
27
28
29 void * allocate_new(int type) {
30   void * v=FREEMALLOC(classsize[type]);
31   *((int *)v)=type;
32   return v;
33 }
34
35 void * allocate_newarray(int type, int length) {
36   void * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]);
37   *((int *)v)=type;
38   ((struct ArrayObject *)v)->___length___=length;
39   return v;
40 }
41
42 struct ___String___ * NewString(char *str,int length) {
43   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
44   struct ___String___ * strobj=allocate_new(STRINGTYPE);
45   int i;
46   strobj->___string___=chararray;
47   for(i=0;i<length;i++) {
48     ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i];  }
49   return strobj;
50 }
51
52 void failedboundschk() {
53   printf("Array out of bounds\n");
54   exit(-1);
55 }
56
57 void failednullptr() {
58   printf("Dereferenced a null pointer\n");
59   exit(-1);
60 }