提交 67b5f248 authored 作者: Thomas Mueller's avatar Thomas Mueller

A Java parser / Java to C converter.

上级 3f377668
......@@ -1280,6 +1280,9 @@ public class JavaParser {
if (m.block != null) {
out.print(m.block.toString());
}
if (m.isConstructor) {
out.println(indent("return this;"));
}
out.println("}");
out.println();
}
......
......@@ -13,7 +13,7 @@ public class TestApp {
/* c:
int main(char** args) {
int main(int argc, char** argv) {
org_h2_java_TestApp_main(null);
}
......@@ -25,8 +25,8 @@ int main(char** args) {
* @param args the command line arguments
*/
public static void main(String... args) {
// c:printf("Hello\n");
System.out.println("Hello World");
System.out.println("Hello!");
}
/**
......
package org.h2.java.io;
import org.h2.java.lang.System;
/**
* A print stream.
*/
......@@ -13,8 +11,8 @@ public class PrintStream {
* @param s the string
*/
public void println(String s) {
System.arraycopy(null, 0, null, 0, 1);
// c: printf("%s\n");
// c: int x = LENGTH(s->chars);
// c: printf("%.*S\n", x, s->chars);
}
}
......@@ -5,11 +5,12 @@ package org.h2.java.lang;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#define jvoid void
#define jboolean int8_t
#define jbyte int8_t
#define jchar int16_t
#define jchar wchar_t
#define jint int32_t
#define jlong int64_t
#define jfloat float
......@@ -18,7 +19,7 @@ package org.h2.java.lang;
#define false 0
#define null 0
#define LENGTH(a) (*(((jint*)(a))-1))
#define LENGTH(a) (*(((jint*)(a))-2))
#define NEW_ARRAY(size, length) new_array(0, size, length)
#define NEW_OBJ_ARRAY(length) new_array(1, sizeof(void*), length)
#define NEW_OBJ(typeId, typeName) new_object(typeId, sizeof(struct typeName))
......@@ -42,7 +43,7 @@ public class String {
void* new_array(jint object, jint size, jint length) {
int count = sizeof(jint) * 2 + size * length;
int* m = (jint*) calloc(1, count);
*m = object << 31 + length;
*m = (object << 31) + length;
*(m+1) = 1;
return m + 2;
}
......@@ -67,11 +68,12 @@ void* set_object(void** target, void* o) {
if (o != 0) {
(*(m - 2))++;
}
return m;
}
void* string(char* s) {
int len = strlen(s);
jchar* chars = NEW_ARRAY(sizeof(char), 1 * LENGTH(chars));
jchar* chars = NEW_ARRAY(sizeof(jchar), len);
for (int i = 0; i < len; i++) {
chars[i] = s[i];
}
......@@ -85,7 +87,7 @@ void* string(char* s) {
public String(char[] chars) {
this.chars = new char[chars.length];
System.arraycopy(chars, 0, this.chars, 0, chars.length);
System.arraycopyChars(chars, 0, this.chars, 0, chars.length);
}
public int hashCode() {
......
......@@ -23,6 +23,22 @@ public class System {
* @param length the number of element to copy
*/
public static void arraycopy(java.lang.Object src, int srcPos, java.lang.Object dest, int destPos, int length) {
// c: memmove(src + srcPos, dest + destPos, length);
// TODO
// c: memmove(dest + destPos, src + srcPos, length);
}
/**
* Copy data from the source to the target.
* Source and target may overlap.
*
* @param src the source array
* @param srcPos the first element in the source array
* @param dest the destination
* @param destPos the first element in the destination
* @param length the number of element to copy
*/
public static void arraycopyChars(char[] src, int srcPos, char[] dest, int destPos, int length) {
// c: memmove(((jchar*)dest) + destPos, ((jchar*)src) + srcPos, sizeof(jchar) * length);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论