DEADSOFTWARE

Исправлена инициализация локальных статических структур
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 22 Aug 2017 10:23:14 +0000 (13:23 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 22 Aug 2017 10:23:14 +0000 (13:23 +0300)
Test.obn
obn-run-tests.sh
src/backends/jvm/generator-jvm.c
tests/Test22.obn [new file with mode: 0644]

index 8889d77c0c50802f40f632397a621a5dba4eaeea..e4eeec3fd93e1dc48ac82f3e67accc672fd2131c 100644 (file)
--- a/Test.obn
+++ b/Test.obn
@@ -1,17 +1,15 @@
 MODULE Test;
 
 TYPE
-  PRec = POINTER TO Rec;
-  Rec = RECORD END;
+  Rider = RECORD i : INTEGER END;
 
-VAR
-  d : PRec;
-
-PROCEDURE X (z : INTEGER; a : SET; b : ARRAY OF CHAR) : PRec;
+PROCEDURE X;
+  VAR
+    r : Rider;
 BEGIN
-  RETURN NIL;
+  r.i := 666;
 END X;
 
 BEGIN
-  d := X(1, {}, "xyz");
+  X;
 END Test.
index 7cfbb4954b5d1bc145a137171bdfebf0c44a7e7d..b9116ff673c445e6081b5c256fa7e928bdae4a3f 100755 (executable)
@@ -91,3 +91,4 @@ makefail Test18C
 maketest Test19
 maketest Test20
 maketest Test21
+maketest Test22
index cb8eeef564ba2925b7eb5701002253f79cdd47d4..bf3b07b52aee0c728cf194e2fbb521b635500557 100644 (file)
@@ -732,6 +732,18 @@ oberon_generator_fini_module(oberon_module_t * mod)
 static void
 push_expr(gen_proc_t * p, oberon_expr_t * expr);
 
+static void
+oberon_generate_static_initialization(gen_proc_t * p, oberon_object_t * x)
+{
+       if(x -> type -> class == OBERON_TYPE_ARRAY
+               || x -> type -> class == OBERON_TYPE_RECORD)
+       {
+               jvm_generate_ldst_prepare(p, x -> gen_var);
+               jvm_generate_new(p, x -> type, 0);
+               jvm_generate_store(p, x -> gen_var);
+       }
+}
+
 void
 oberon_generate_begin_module(oberon_context_t * ctx)
 {
@@ -767,13 +779,7 @@ oberon_generate_begin_module(oberon_context_t * ctx)
                else if(x -> class == OBERON_CLASS_VAR)
                {
                        jvm_generate_var_initialization(p, x -> gen_var);
-                       if(x -> type -> class == OBERON_TYPE_ARRAY
-                               || x -> type -> class == OBERON_TYPE_RECORD)
-                       {
-                               jvm_generate_ldst_prepare(p, x -> gen_var);
-                               jvm_generate_new(p, x -> type, 0);
-                               jvm_generate_store(p, x -> gen_var);
-                       }
+                       oberon_generate_static_initialization(p, x);
                }
 
                x = x -> next;
@@ -898,9 +904,22 @@ jvm_generate_local_initialization(gen_proc_t * p, oberon_object_t * x)
        switch(x -> class)
        {
                case OBERON_CLASS_VAR_PARAM:
+                       jvm_generate_var_initialization(p, v);
+                       break;
                case OBERON_CLASS_PARAM:
+                       jvm_generate_var_initialization(p, v);
+                       if(x -> type -> class == OBERON_TYPE_ARRAY)
+                       {
+                               jvm_generate_array_duplicate_and_replace(p, v, x -> type);
+                       }
+                       else if(x -> type -> class == OBERON_TYPE_RECORD)
+                       {                               
+                               jvm_generate_record_duplicate_and_replace(p, v, x -> type);
+                       }
+                       break;
                case OBERON_CLASS_VAR:
                        jvm_generate_var_initialization(p, v);
+                       oberon_generate_static_initialization(p, x);
                        break;
                case OBERON_CLASS_CONST:
                case OBERON_CLASS_TYPE:
@@ -910,18 +929,6 @@ jvm_generate_local_initialization(gen_proc_t * p, oberon_object_t * x)
                        gen_error("jvm_generate_local_initialization: wat class %i", x -> class);
                        break;
        }
-
-       if(x -> class == OBERON_CLASS_PARAM)
-       {
-               if(x -> type -> class == OBERON_TYPE_ARRAY)
-               {
-                       jvm_generate_array_duplicate_and_replace(p, v, x -> type);
-               }
-               else if(x -> type -> class == OBERON_TYPE_RECORD)
-               {                               
-                       jvm_generate_record_duplicate_and_replace(p, v, x -> type);
-               }
-       }
 }
 
 void
diff --git a/tests/Test22.obn b/tests/Test22.obn
new file mode 100644 (file)
index 0000000..da07140
--- /dev/null
@@ -0,0 +1,30 @@
+MODULE Test22;
+
+TYPE
+  Rider = RECORD i : INTEGER END;
+  Array = ARRAY 10 OF Rider;
+
+VAR
+  Ride : Rider;
+  Arr  : Array;
+
+PROCEDURE X(R : Rider; A : Array);
+  VAR
+    r : Rider;
+    a : Array;
+BEGIN
+  r.i := 666;
+  a[2].i := 666;
+  R.i := 789;
+  A[7].i := 987;
+END X;
+
+BEGIN
+  Ride.i := 123;
+  Arr[7].i := 321;
+  X(Ride, Arr);
+  ASSERT(Ride.i = 123);
+  ASSERT(Arr[7].i = 321);
+END Test22.
+
+Проверка аллокации локальных статических структур и копирования параметров.