Support for printing Strings!!!
[IRC.git] / Robust / src / Runtime / runtime.c
1 #include "runtime.h"
2 #include "structdefs.h"
3 extern int classsize[];
4
5 int ___Object______hashcode____(struct ___Object___ * ___this___) {
6   return (int) ___this___;
7 }
8
9 void ___System______printInt____I(int x) {
10   printf("%d\n",x);
11 }
12
13 void ___System______printString____L___String___(struct ___String___ * s) {
14     struct ArrayObject * chararray=s->___string___;
15     int i;
16     for(i=0;i<chararray->___length___;i++) {
17         short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i];
18         putchar(s);
19     }
20 }
21
22
23 void * allocate_new(int type) {
24   void * v=calloc(1,classsize[type]);
25   *((int *)v)=type;
26   return v;
27 }
28
29 void * allocate_newarray(int type, int length) {
30   void * v=calloc(1,sizeof(struct ArrayObject)+length*classsize[type]);
31   *((int *)v)=type;
32   ((struct ArrayObject *)v)->___length___=length;
33   return v;
34 }
35
36 struct ___String___ * NewString(char *str,int length) {
37   struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length);
38   struct ___String___ * strobj=allocate_new(STRINGTYPE);
39   int i;
40   strobj->___string___=chararray;
41   for(i=0;i<length;i++) {
42     ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]=(short)str[i];  }
43   return strobj;
44 }