DEADSOFTWARE

JVM: исправлены указатели на процедуры: больше не требуется поддержка со стороны...
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 2 Aug 2017 09:32:41 +0000 (12:32 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Wed, 2 Aug 2017 09:32:41 +0000 (12:32 +0300)
JTest.java [deleted file]
src/backends/jvm/generator-jvm-basic.c
src/backends/jvm/generator-jvm.c
src/test.c

diff --git a/JTest.java b/JTest.java
deleted file mode 100644 (file)
index 0e621c8..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-class JTest
-{
-       public static JTest pointer;
-
-       {
-               pointer = this;
-       }
-}
index aad9747f25cbf4d091e86db1f0ea9a3d098753dc..24c28b057429313018bf1529c64154c1e2a27825 100644 (file)
@@ -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;
                        }
index e4c70b1c23d312e580c24f1a2d2348963548ecc1..d609ed8de96c216a30ac4ec9bceda90ec230583e 100644 (file)
@@ -761,7 +761,14 @@ oberon_generate_procedure_pointer_class(oberon_object_t * proc)
        fprintf(fp, ".method <init>()V\n");
        fprintf(fp, "  aload_0\n");
        fprintf(fp, "  invokespecial %s/<init>()V\n", abscname);
-       fprintf(fp, "  aload_0\n");
+       fprintf(fp, "  return\n");
+       fprintf(fp, ".end method\n\n");
+
+       fprintf(fp, ".method static <clinit>()V\n");
+       fprintf(fp, "  .limit stack 2\n");
+       fprintf(fp, "  new %s\n", cname);
+       fprintf(fp, "  dup\n");
+       fprintf(fp, "  invokespecial %s/<init>()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/<init>()V", cname);
-               }
 
                x = x -> next;
        }
index 03ac7fc3ab12979d8fcaadac8c5ccd244769f4bc..d2950b968189c70a5f4b743c5131cd9682498959 100644 (file)
@@ -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."
 ;