From: DeaDDooMER Date: Wed, 2 Aug 2017 09:32:41 +0000 (+0300) Subject: JVM: исправлены указатели на процедуры: больше не требуется поддержка со стороны... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=ee7fd939ac99201466900fb3983aa90b980da5c3;p=dsw-obn.git JVM: исправлены указатели на процедуры: больше не требуется поддержка со стороны модуля для их работы, а так же исправлены названия классов во избежание конфликтов с jvm. --- 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." ;