From ee7fd939ac99201466900fb3983aa90b980da5c3 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Wed, 2 Aug 2017 12:32:41 +0300 Subject: [PATCH] =?utf8?q?JVM:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=83=D0=BA=D0=B0=D0=B7=D0=B0=D1=82?= =?utf8?q?=D0=B5=D0=BB=D0=B8=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D1=86?= =?utf8?q?=D0=B5=D0=B4=D1=83=D1=80=D1=8B:=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?utf8?q?=D0=B5=20=D0=BD=D0=B5=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5?= =?utf8?q?=D1=82=D1=81=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?utf8?q?=D0=BA=D0=B0=20=D1=81=D0=BE=20=D1=81=D1=82=D0=BE=D1=80=D0=BE?= =?utf8?q?=D0=BD=D1=8B=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20=D0=B4?= =?utf8?q?=D0=BB=D1=8F=20=D0=B8=D1=85=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?utf8?q?=D1=8B,=20=D0=B0=20=D1=82=D0=B0=D0=BA=20=D0=B6=D0=B5=20=D0=B8?= =?utf8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BD?= =?utf8?q?=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BB=D0=B0?= =?utf8?q?=D1=81=D1=81=D0=BE=D0=B2=20=D0=B2=D0=BE=20=D0=B8=D0=B7=D0=B1?= =?utf8?q?=D0=B5=D0=B6=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=84?= =?utf8?q?=D0=BB=D0=B8=D0=BA=D1=82=D0=BE=D0=B2=20=D1=81=20jvm.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- JTest.java | 8 -------- src/backends/jvm/generator-jvm-basic.c | 27 ++++++++++++++++++++++++-- src/backends/jvm/generator-jvm.c | 15 +++++++------- src/test.c | 6 ++++-- 4 files changed, 37 insertions(+), 19 deletions(-) delete mode 100644 JTest.java diff --git a/JTest.java b/JTest.java deleted file mode 100644 index 0e621c8..0000000 --- a/JTest.java +++ /dev/null @@ -1,8 +0,0 @@ -class JTest -{ - public static JTest pointer; - - { - pointer = this; - } -} diff --git a/src/backends/jvm/generator-jvm-basic.c b/src/backends/jvm/generator-jvm-basic.c index aad9747..24c28b0 100644 --- a/src/backends/jvm/generator-jvm-basic.c +++ b/src/backends/jvm/generator-jvm-basic.c @@ -133,6 +133,29 @@ jvm_get_descriptor(oberon_type_t * type) return NULL; } +char * +jvm_get_descriptor_safe(oberon_type_t * type) +{ + switch(type -> class) + { + case OBERON_TYPE_POINTER: + return new_string("PTR%s", jvm_get_descriptor_safe(type -> base)); + break; + case OBERON_TYPE_PROCEDURE: + case OBERON_TYPE_RECORD: + return jvm_get_class_full_name(type); + break; + case OBERON_TYPE_ARRAY: + return new_string("A%sX", jvm_get_descriptor_safe(type -> base)); + break; + default: + return jvm_get_descriptor(type); + break; + } + + return NULL; +} + char jvm_get_prefix(oberon_type_t * type) { @@ -283,14 +306,14 @@ jvm_get_class_full_name(oberon_type_t * type) name = new_string("SYSTEM$PROCEDURE"); char * desc; - desc = jvm_get_descriptor(type -> base); + desc = jvm_get_descriptor_safe(type -> base); name = new_string("%s$%s", name, desc); int num = type -> num_decl; oberon_object_t * arg = type -> decl; for(int i = 0; i < num; i++) { - desc = jvm_get_descriptor(arg -> type); + desc = jvm_get_descriptor_safe(arg -> type); name = new_string("%s%s", name, desc); arg = arg -> next; } diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index e4c70b1..d609ed8 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -761,7 +761,14 @@ oberon_generate_procedure_pointer_class(oberon_object_t * proc) fprintf(fp, ".method ()V\n"); fprintf(fp, " aload_0\n"); fprintf(fp, " invokespecial %s/()V\n", abscname); - fprintf(fp, " aload_0\n"); + fprintf(fp, " return\n"); + fprintf(fp, ".end method\n\n"); + + fprintf(fp, ".method static ()V\n"); + fprintf(fp, " .limit stack 2\n"); + fprintf(fp, " new %s\n", cname); + fprintf(fp, " dup\n"); + fprintf(fp, " invokespecial %s/()V\n", cname); fprintf(fp, " putstatic %s/pointer %s\n", cname, absdesc); fprintf(fp, " return\n"); fprintf(fp, ".end method\n\n"); @@ -1076,12 +1083,6 @@ oberon_generate_begin_module(oberon_context_t * ctx) jvm_generate_store(p, x -> type, x -> gen_var); } } - else if(x -> class == OBERON_CLASS_PROC) - { - char * cname = jvm_get_field_full_name_safe(x); - jvm_generate(p, 0, 1, "new %s", cname); - jvm_generate(p, 1, 0, "invokespecial %s/()V", cname); - } x = x -> next; } diff --git a/src/test.c b/src/test.c index 03ac7fc..d2950b9 100644 --- a/src/test.c +++ b/src/test.c @@ -22,12 +22,14 @@ static char source_test[] = "" "TYPE" " Ident = ARRAY 20 OF CHAR;" + " PrintString = PROCEDURE (str : ARRAY OF CHAR);" "" "VAR" " hello : Ident;" - " cc : CHAR;" + " print : PrintString;" "" "BEGIN" + " print := Out.String;" " hello[0] := h;" " hello[1] := e;" " hello[2] := l;" @@ -42,7 +44,7 @@ static char source_test[] = " hello[11] := bang;" " hello[12] := null;" " Out.Open;" - " Out.String(hello);" + " print(hello);" " Out.Ln;" "END Test." ; -- 2.29.2