summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 13d2ebd)
raw | patch | inline | side by side (parent: 13d2ebd)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 28 Jul 2017 18:22:25 +0000 (21:22 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 28 Jul 2017 18:22:25 +0000 (21:22 +0300) |
src/backends/jvm/generator-jvm.c | patch | blob | history | |
src/test.c | patch | blob | history |
index 9408eca32328248fd37b8454c30b99d663ad7ebd..cbc834e58d5cf919926aae41423023dc4e259013 100644 (file)
}
static void
-jvm_generate_new_static(gen_proc_t * p, oberon_type_t * type);
+jvm_generate_new(gen_proc_t * p, oberon_type_t * type, int num);
/*
* Функция jvm_generate_static_array_initialization генерирует код для
{
jvm_generate(p, 0, 1, "aload %i", reg_a);
jvm_generate(p, 0, 1, "iload %i", reg_i);
- jvm_generate_new_static(p, type -> base);
+ jvm_generate_new(p, type -> base, 0);
jvm_generate(p, 3, 0, "aastore");
}
else
}
static void
-jvm_generate_new_static(gen_proc_t * p, oberon_type_t * type)
+jvm_generate_new(gen_proc_t * p, oberon_type_t * type, int num)
{
int dim;
char * cname;
desc = jvm_get_descriptor(type);
while(base -> class == OBERON_TYPE_ARRAY)
{
+ if(num > 0)
+ {
+ assert(base -> size == 0);
+ num -= 1;
+ }
+ else
+ {
+ assert(base -> size > 0);
+ jvm_generate_push_int(p, base -> size);
+ }
dim += 1;
- jvm_generate_push_int(p, base -> size);
base = base -> base;
}
+
+ assert(num == 0);
jvm_generate(p, dim, 1, "multianewarray %s %i", desc, dim);
if(base -> class == OBERON_TYPE_RECORD)
|| field -> type -> class == OBERON_TYPE_ARRAY)
{
jvm_generate(p, 0, 1, "aload_0");
- jvm_generate_new_static(p, field -> type);
+ jvm_generate_new(p, field -> type, 0);
jvm_generate_store(p, field -> type, field -> gen_var);
}
field = field -> next;
if(x -> type -> class == OBERON_TYPE_ARRAY
|| x -> type -> class == OBERON_TYPE_RECORD)
{
- jvm_generate_new_static(p, x -> type);
+ jvm_generate_new(p, x -> type, 0);
jvm_generate_store(p, x -> type, x -> gen_var);
}
}
}
}
-static void
-jvm_generate_expr_new_static(gen_proc_t * p, oberon_type_t * type, int num, oberon_expr_t * arg)
-{
- assert(num == 0);
- jvm_generate_new_static(p, type);
-}
-
static void
jvm_generate_expr_new_pointer(gen_proc_t * p, oberon_type_t * type, int num, oberon_expr_t * arg)
{
assert(type -> class == OBERON_TYPE_POINTER);
- jvm_generate_expr_new_static(p, type -> base, num, arg);
+
+ for(int i = 0; i < num; i++)
+ {
+ push_expr(p, arg);
+ arg = arg -> next;
+ }
+
+ jvm_generate_new(p, type -> base, num);
}
static void
diff --git a/src/test.c b/src/test.c
index 92223cdc7b49b4643f79f9edad013f341b9db6a4..51a1250523aebc88646d6add7368a3c5fe5f8f48 100644 (file)
--- a/src/test.c
+++ b/src/test.c
static char source_test[] =
"(* Main module *)"
"MODULE Test;"
+ "TYPE"
+ " Rec = POINTER TO RecDesc;"
+ " RecDesc = RECORD x : INTEGER; END;"
"VAR"
" g : ARRAY 4 OF INTEGER;"
" r : RECORD x : INTEGER; END;"
+ " a : POINTER TO ARRAY OF ARRAY OF RecDesc;"
"BEGIN"
+ " NEW(a, 10, 10);"
+ " a[9, 9].x := 666;"
" g[3] := 4;"
" r.x := 4546;"
"END Test."