From 6a3dfd4bef9a28863a7645070f0067f4a09d143a Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Tue, 22 Aug 2017 13:23:14 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B0=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8?= =?utf8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB?= =?utf8?q?=D1=8C=D0=BD=D1=8B=D1=85=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87?= =?utf8?q?=D0=B5=D1=81=D0=BA=D0=B8=D1=85=20=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?utf8?q?=D1=82=D1=83=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Test.obn | 14 +++++----- obn-run-tests.sh | 1 + src/backends/jvm/generator-jvm.c | 45 ++++++++++++++++++-------------- tests/Test22.obn | 30 +++++++++++++++++++++ 4 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 tests/Test22.obn diff --git a/Test.obn b/Test.obn index 8889d77..e4eeec3 100644 --- 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. diff --git a/obn-run-tests.sh b/obn-run-tests.sh index 7cfbb49..b9116ff 100755 --- a/obn-run-tests.sh +++ b/obn-run-tests.sh @@ -91,3 +91,4 @@ makefail Test18C maketest Test19 maketest Test20 maketest Test21 +maketest Test22 diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index cb8eeef..bf3b07b 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -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 index 0000000..da07140 --- /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. + +Проверка аллокации локальных статических структур и копирования параметров. -- 2.29.2