summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 35e75d2)
raw | patch | inline | side by side (parent: 35e75d2)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 22 Aug 2017 10:23:14 +0000 (13:23 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 22 Aug 2017 10:23:14 +0000 (13:23 +0300) |
Test.obn | patch | blob | history | |
obn-run-tests.sh | patch | blob | history | |
src/backends/jvm/generator-jvm.c | patch | blob | history | |
tests/Test22.obn | [new file with mode: 0644] | patch | blob |
diff --git a/Test.obn b/Test.obn
index 8889d77c0c50802f40f632397a621a5dba4eaeea..e4eeec3fd93e1dc48ac82f3e67accc672fd2131c 100644 (file)
--- a/Test.obn
+++ b/Test.obn
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.
diff --git a/obn-run-tests.sh b/obn-run-tests.sh
index 7cfbb4954b5d1bc145a137171bdfebf0c44a7e7d..b9116ff673c445e6081b5c256fa7e928bdae4a3f 100755 (executable)
--- a/obn-run-tests.sh
+++ b/obn-run-tests.sh
maketest Test19
maketest Test20
maketest Test21
+maketest Test22
index cb8eeef564ba2925b7eb5701002253f79cdd47d4..bf3b07b52aee0c728cf194e2fbb521b635500557 100644 (file)
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)
{
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;
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:
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
--- /dev/null
+++ b/tests/Test22.obn
@@ -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.
+
+Проверка аллокации локальных статических структур и копирования параметров.