objectformat: one word after mtable in object layout
[mate.git] / ffi / native.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 static char ascii(char s) {
6         if(s < 0x20) return '.';
7         if(s > 0x7E) return '.';
8         return s;
9 }
10
11 void hexdump(void *d, int len) {
12         unsigned char *data;
13         int i, off;
14         data = (unsigned char*)d;
15         for (off=0; off<len; off += 16) {
16                 printf("%08x  ",off);
17                 for(i=0; i<16; i++)
18                         if((i+off)>=len) printf("   ");
19                         else printf("%02x ",data[off+i]);
20
21                 printf(" ");
22                 for(i=0; i<16; i++)
23                         if((i+off)>=len) printf(" ");
24                         else printf("%c",ascii(data[off+i]));
25                 printf("\n");
26         }
27 }
28
29 void tests_Native1__printSomething____V(void)
30 {
31         printf("printSomething: woot \\o/\n");
32 }
33
34 void tests_Native1__printSomething___I_V(int a)
35 {
36         printf("printSomething: 0x%08x\n", a);
37 }
38
39 void tests_Instance5__printX___I_V(int a)
40 {
41         printf("printX: 0x%08x\n", a);
42 }
43
44 void java_io_PrintStream__printf___I_V(int a)
45 {
46         printf("printstream: 0x%08x\n", a);
47 }
48
49 struct integer {
50         unsigned int method_table_ptr;
51         unsigned int gc_data;
52         int value;
53 };
54
55 struct string {
56         unsigned int method_table_ptr;
57         unsigned int gc_data;
58         struct chararray *value;
59 };
60
61 struct chararray {
62         unsigned int length;
63         char str;
64 };
65
66 void jmate_io_PrintStream__printf_0___Ljava_lang_String__V
67         (struct string *fmt)
68 {
69         printf("%s", &fmt->value->str);
70 }
71
72 void jmate_io_PrintStream__printf_1___Ljava_lang_String_Ljava_lang_Object__V
73         (struct integer *a1, struct string *fmt)
74 {
75 #if 0
76         printf("fmt:        0x%08x\n", (unsigned int) fmt);
77         printf("fmt->value: 0x%08x\n", (unsigned int) fmt->value);
78         printf("fmt->val.len: 0x%08x\n", (unsigned int) (*fmt->value).length);
79         printf("first: %d\n", fmt->value->length);
80         printf("*fmt: %s\n", &fmt->value->str);
81 #endif
82         printf(&fmt->value->str, a1->value);
83 }
84
85 void jmate_io_PrintStream__printf_2___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object__V
86         (struct integer *a2, struct integer *a1, struct string *fmt)
87 {
88         printf(&fmt->value->str, a1->value, a2->value);
89 }
90
91 void
92 jmate_io_PrintStream__printf_3___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object__V
93         (struct integer *a3, struct integer *a2, struct integer *a1, struct string *fmt)
94 {
95         printf(&fmt->value->str, a1->value, a2->value, a3->value);
96 }
97
98 void jmate_io_PrintStream__printf_4___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object__V
99         (struct integer *a4, struct integer *a3, struct integer *a2, struct integer *a1, struct string *fmt)
100 {
101         printf(&fmt->value->str, a1->value, a2->value, a3->value, a4->value);
102 }
103
104 void jmate_io_PrintStream__printf_5___Ljava_lang_String_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object__V
105         (struct integer *a5, struct integer *a4, struct integer *a3, struct integer *a2, struct integer *a1, struct string *fmt)
106 {
107         printf(&fmt->value->str, a1->value, a2->value, a3->value, a4->value, a5->value);
108 }
109
110 void gnu_classpath_VMSystemProperties__preInit___Ljava_util_Properties__V() {
111         return;
112 }
113
114 void java_lang_VMSystem__arraycopy___Ljava_lang_Object_ILjava_lang_Object_II_V(
115                 int len, int dest_start, struct chararray *dest,
116                 int src_start, struct chararray *src)
117 #if 0
118                 /* original */
119                 struct chararray *src, int src_start,
120                 struct chararray *dest, int dest_start, int len)
121 #endif
122 {
123         memcpy(&dest->str, &src->str + src_start, len);
124         dest->length = len;
125 #if 0
126         hexdump(src, len + 4);
127         hexdump(dest, len + 4);
128 #endif
129 }