summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 55d9ee9)
raw | patch | inline | side by side (parent: 55d9ee9)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 7 Aug 2017 13:58:04 +0000 (16:58 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Mon, 7 Aug 2017 13:58:04 +0000 (16:58 +0300) |
index ed4a19ad1f3cd5ccae3c0e9645ded564faf9c355..fa34f1dfd8190149b12569aca64b7bc29b767d64 100644 (file)
void
jvm_generate_ldst_prepare(gen_proc_t * p, gen_var_t * v)
{
- char * full_name = v -> full_name;
- char * desc = v -> type -> desc;
-
+ char * desc;
+ char * full_name;
switch(v -> storage)
{
case JVM_STORAGE_REGISTER:
break;
case JVM_STORAGE_STATIC:
+ full_name = v -> full_name;
+ desc = v -> type -> desc;
jvm_generate(p, 0, 1, "getstatic %s [%s", full_name, desc);
jvm_generate(p, 0, 1, "iconst_0");
break;
case JVM_STORAGE_FIELD:
+ full_name = v -> full_name;
+ desc = v -> type -> desc;
jvm_generate(p, 1, 1, "getfield %s [%s", full_name, desc);
jvm_generate(p, 0, 1, "iconst_0");
break;
jvm_generate_and_init_local_var(gen_proc_t * p, gen_var_t * v, gen_type_t * t)
{
v -> storage = JVM_STORAGE_REGISTER;
- v -> reg = jvm_alloc_register_untyped(p -> rf, t -> wide);
+ v -> reg = jvm_alloc_register_untyped(p -> rf, t -> wide);
v -> type = t;
}
void
-jvm_generate_and_init_named_local_var(gen_proc_t * p, gen_var_t * v, char * name, gen_type_t * t)
+jvm_init_named_local_var(gen_proc_t * p, gen_var_t * v, gen_type_t * t)
{
- jvm_generate_and_init_local_var(p, v, t);
- jvm_generate(p, 0, 0, ".var %i is %s %s from start to end", v -> reg, name, t -> desc);
+ v -> storage = JVM_STORAGE_REGISTER;
+ v -> reg = jvm_alloc_register_untyped(p -> rf, t -> wide);
+ v -> type = t;
+}
+
+void
+jvm_init_param(gen_proc_t * p, gen_var_t * v, gen_type_t * t)
+{
+ v -> storage = JVM_STORAGE_LOCAL;
+ v -> reg = jvm_alloc_register_untyped(p -> rf, t -> wide);
+ v -> type = t;
}
void
-jvm_generate_and_init_var_param(gen_proc_t * p, gen_var_t * v, char * name, gen_type_t * t)
+jvm_init_var_param(gen_proc_t * p, gen_var_t * v, gen_type_t * t)
{
v -> storage = JVM_STORAGE_VARPTR;
- v -> reg = jvm_alloc_register_untyped(p -> rf, true);
+ v -> reg = jvm_alloc_register_untyped(p -> rf, true);
v -> type = t;
- jvm_generate(p, 0, 0, ".var %i is %s [%s from start to end", v -> reg, name, t -> desc);
- jvm_generate(p, 0, 0, ".var %i is __%s_offset I from start to end", v -> reg + 1, name);
}
void
}
void
-jvm_generate_param_initialization(gen_proc_t * p, gen_var_t * v)
+jvm_generate_named_local_var_initialization(gen_proc_t * p, gen_var_t * v, char * name)
{
- assert(v -> storage == JVM_STORAGE_REGISTER);
+ jvm_generate(p, 0, 0, ".var %i is %s %s from start to end", v -> reg, name, v -> type -> desc);
+}
+void
+jvm_generate_param_initialization(gen_proc_t * p, gen_var_t * v, char * name)
+{
int old_reg = v -> reg;
bool wide = v -> type -> wide;
int cell_size = v -> type -> cell_size;
char prefix = v -> type -> prefix;
char * desc = v -> type -> desc;
- v -> storage = JVM_STORAGE_LOCAL;
+ jvm_generate(p, 0, 0, ".var %i is %s %s from start to end", old_reg, name, desc);
v -> reg = jvm_alloc_register_untyped(p -> rf, wide);
jvm_generate(p, 0, 1, "iconst_1");
jvm_generate(p, 0, cell_size, "%cload %i", prefix, old_reg);
jvm_generate(p, 1 + 1 + cell_size, 0, "%castore", prefix);
}
+
+void
+jvm_generate_var_param_initialization(gen_proc_t * p, gen_var_t * v, char * name)
+{
+ jvm_generate(p, 0, 0, ".var %i is %s [%s from start to end", v -> reg, name, v -> type -> desc);
+ jvm_generate(p, 0, 0, ".var %i is __%s_offset I from start to end", v -> reg + 1, name);
+}
index 01bfefcde6548b20f8aa0f108b4fdc3038dcb7ea..90f5d653ccada22664742c12a98621f271cc9c7d 100644 (file)
void
jvm_generate_store(gen_proc_t * p, gen_var_t * dst);
+
+
void
jvm_generate_and_init_global_var(struct gen_class * class, gen_var_t * v, char * name, gen_type_t * t);
@@ -16,14 +18,28 @@ jvm_generate_and_init_field(struct gen_class * class, gen_var_t * v, char * name
void
jvm_generate_and_init_local_var(gen_proc_t * p, gen_var_t * v, gen_type_t * t);
+
+
void
-jvm_generate_and_init_named_local_var(gen_proc_t * p, gen_var_t * v, char * name, gen_type_t * t);
+jvm_init_named_local_var(gen_proc_t * p, gen_var_t * v, gen_type_t * t);
void
-jvm_generate_and_init_var_param(gen_proc_t * p, gen_var_t * v, char * name, gen_type_t * t);
+jvm_init_param(gen_proc_t * p, gen_var_t * v, gen_type_t * t);
+
+void
+jvm_init_var_param(gen_proc_t * p, gen_var_t * v, gen_type_t * t);
+
+
void
jvm_generate_variable_initialization(gen_proc_t * p, gen_var_t * v);
void
-jvm_generate_param_initialization(gen_proc_t * p, gen_var_t * v);
+jvm_generate_named_local_var_initialization(gen_proc_t * p, gen_var_t * v, char * name);
+
+void
+jvm_generate_param_initialization(gen_proc_t * p, gen_var_t * v, char * name);
+
+void
+jvm_generate_var_param_initialization(gen_proc_t * p, gen_var_t * v, char * name);
+
index 277940ce17b58fb18f46ee630aa162c2a250c62a..1757cb6221fe49317bb5336c9ff136ed7572ffde 100644 (file)
return '!';
}
+char *
+jvm_get_name(oberon_object_t * x)
+{
+ switch(x -> class)
+ {
+ case OBERON_CLASS_VAR:
+ case OBERON_CLASS_VAR_PARAM:
+ case OBERON_CLASS_PARAM:
+ case OBERON_CLASS_FIELD:
+ return new_string(x -> name);
+ case OBERON_CLASS_PROC:
+ if(x -> parent)
+ {
+ return new_string("%s$%s", jvm_get_name(x -> parent), x -> name);
+ }
+ else
+ {
+ return new_string(x -> name);
+ }
+ default:
+ gen_error("jvm_get_name: wat");
+ }
+
+ return NULL;
+}
+
char *
jvm_get_field_full_name(oberon_object_t * x)
{
+ char * parent;
switch(x -> class)
{
case OBERON_CLASS_VAR:
+ return new_string("%s/%s", x -> module -> name, jvm_get_name(x));
case OBERON_CLASS_PROC:
- return new_string("%s/%s", x -> module -> name, x -> name);
- case OBERON_CLASS_FIELD:;
- char * rec_name = jvm_get_class_full_name(x -> parent_type);
- return new_string("%s/%s", rec_name, x -> name);
+ return new_string("%s/%s", x -> module -> name, jvm_get_name(x));
+ case OBERON_CLASS_FIELD:
+ parent = jvm_get_class_full_name(x -> parent_type);
+ return new_string("%s/%s", parent, jvm_get_name(x));
case OBERON_CLASS_MODULE:
return new_string(x -> module -> name);
default:
index 121c89b7817147679feb41faa7330c970c3c16ba..8d2b29c930c8687da3ceda4ca261388ab4c5cb8f 100644 (file)
char
jvm_get_postfix(oberon_type_t * type);
+char *
+jvm_get_name(oberon_object_t * x);
+
char *
jvm_get_field_full_name(oberon_object_t * x);
index da8b06b29f5142a7ea9b25cdd2e6c8ed18a00bb8..559325964d72498d3bfd7cfee1f1faf9e7e02012 100644 (file)
oberon_object_t * param = proc -> type -> decl;
for(int i = 0; i < num; i++)
{
- gen_var_t * v = oberon_generator_new_var();
gen_type_t * t = param -> type -> gen_type;
- use_size += t -> cell_size;
if(param -> class == OBERON_CLASS_VAR_PARAM)
{
- jvm_generate_and_init_var_param(p, v, param -> name, t);
- jvm_generate_ldst_prepare(p, v);
+ int reg = jvm_alloc_register_untyped(p -> rf, true);
+ jvm_generate(p, 0, 1, "aload %i", reg);
+ jvm_generate(p, 0, 1, "iload %i", reg + 1);
}
else
{
- jvm_generate_and_init_named_local_var(p, v, param -> name, t);
- jvm_generate_load(p, v);
+ int reg = jvm_alloc_register_untyped(p -> rf, t -> wide);
+ jvm_generate(p, 0, t -> cell_size, "%cload %i", t -> prefix, reg);
}
+ use_size += t -> cell_size;
param = param -> next;
}
gen_var_t * copy_src = oberon_generator_new_var();
char * signature = new_string("(%s%s)V", rec -> gen_type -> desc, rec -> gen_type -> desc);
jvm_generate_function_header(p, "public static", "$COPY$", signature);
- jvm_generate_and_init_named_local_var(p, copy_dst, "dst", rec -> gen_type);
- jvm_generate_and_init_named_local_var(p, copy_src, "src", rec -> gen_type);
+ jvm_init_param(p, copy_dst, rec -> gen_type);
+ jvm_init_param(p, copy_src, rec -> gen_type);
+ jvm_generate_param_initialization(p, copy_dst, "dst");
+ jvm_generate_param_initialization(p, copy_src, "src");
num = rec -> num_decl;
field = rec -> decl;
for(int i = 0; i < num; i++)
struct gen_class * class;
class = m -> class;
+ gen_proc_t * p;
switch(var -> class)
{
case OBERON_CLASS_VAR_PARAM:
+ p = var -> parent -> gen_proc;
+ jvm_init_var_param(p, v, var -> type -> gen_type);
+ break;
case OBERON_CLASS_PARAM:
- /* Заполняется при генерации функции */
- /* смотри jvm_init_local_object() */
+ p = var -> parent -> gen_proc;
+ jvm_init_param(p, v, var -> type -> gen_type);
break;
case OBERON_CLASS_FIELD:
/* Заполняются при инициализации структуры */
/* смотри oberon_generator_init_record() */
break;
case OBERON_CLASS_VAR:
- /* Локальные заполняются при генерации функции */
- /* смотри jvm_init_local_object() */
- if(var -> local == false)
+ if(var -> local)
+ {
+ p = var -> parent -> gen_proc;
+ jvm_init_named_local_var(p, v, var -> type -> gen_type);
+ }
+ else
{
jvm_generate_and_init_global_var(class, v, var -> name, var -> type -> gen_type);
}
{
struct gen_class * class = proc -> module -> gen_mod -> class;
proc -> gen_proc = jvm_create_proc(class);
-
- if(proc -> local)
- {
- gen_error("generator: local procedures not implemented");
- }
- else
- {
- oberon_generate_procedure_pointer_class(proc);
- }
}
void
@@ -802,10 +802,11 @@ jvm_generate_record_duplicate_and_replace(gen_proc_t * p, gen_var_t * v, oberon_
}
static void
-jvm_init_local_object(gen_proc_t * p, oberon_object_t * x)
+jvm_generate_local_initialization(gen_proc_t * p, oberon_object_t * x)
{
gen_var_t * v;
struct gen_class * class;
+ char * name;
v = x -> gen_var;
class = p -> class;
assert(class -> p);
assert(x -> local);
+ name = jvm_get_name(x);
switch(x -> class)
{
case OBERON_CLASS_VAR_PARAM:
- jvm_generate_and_init_var_param(p, v, x -> name, x -> type -> gen_type);
+ jvm_generate_var_param_initialization(p, v, name);
break;
- case OBERON_CLASS_VAR:
case OBERON_CLASS_PARAM:
- jvm_generate_and_init_named_local_var(p, v, x -> name, x -> type -> gen_type);
- break;
- default:
- gen_error("jvm_init_local_object: wat");
- break;
- }
-}
-
-static void
-jvm_generate_local_initialization(gen_proc_t * p, oberon_object_t * x)
-{
- gen_var_t * v;
- struct gen_class * class;
-
- v = x -> gen_var;
- class = p -> class;
-
- // Убеждаемся что сейчас находимся в функции
- assert(class -> p);
- assert(x -> local);
-
- switch(x -> class)
- {
- case OBERON_CLASS_VAR_PARAM:
+ jvm_generate_param_initialization(p, v, name);
break;
case OBERON_CLASS_VAR:
- jvm_generate_variable_initialization(p, v);
+ jvm_generate_named_local_var_initialization(p, v, name);
break;
- case OBERON_CLASS_PARAM:
- jvm_generate_param_initialization(p, v);
+ case OBERON_CLASS_PROC:
break;
default:
gen_error("jvm_generate_local_initialization: wat");
break;
}
+
+ if(x -> class == OBERON_CLASS_PARAM || x -> class == OBERON_CLASS_VAR_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
oberon_generate_begin_proc(oberon_context_t * ctx, oberon_object_t * proc)
{
gen_proc_t * p;
+ char * name;
char * signature;
p = proc -> gen_proc;
- signature = jvm_get_procedure_signature(proc -> type);
- jvm_generate_function_header(p, "public static", proc -> name, signature);
-
- /* Выделение регистров под параметры и переменные */
- oberon_object_t * var = proc -> scope -> list -> next;
- while(var)
+ if(proc -> local == false)
{
- jvm_init_local_object(p, var);
- var = var -> next;
+ oberon_generate_procedure_pointer_class(proc);
}
+ signature = jvm_get_procedure_signature(proc -> type);
+ name = jvm_get_name(proc);
+ jvm_generate_function_header(p, "public static", name, signature);
+
/* Инициализация */
- var = proc -> scope -> list -> next;
+ oberon_object_t * var = proc -> scope -> list -> next;
while(var)
{
jvm_generate_local_initialization(p, var);
var = var -> next;
}
-
- /* Копирование статических/открытых массивов и записей */
- var = proc -> type -> decl;
- while(var)
- {
- if(var -> class == OBERON_CLASS_PARAM || var -> class == OBERON_CLASS_VAR_PARAM)
- {
- if(var -> type -> class == OBERON_TYPE_ARRAY)
- {
- jvm_generate_array_duplicate_and_replace(p, var -> gen_var, var -> type);
- }
- else if(var -> type -> class == OBERON_TYPE_RECORD)
- {
- jvm_generate_record_duplicate_and_replace(p, var -> gen_var, var -> type);
- }
- }
- var = var -> next;
- }
}
void
diff --git a/src/oberon.c b/src/oberon.c
index 58eb67c3eb72562294074f972fde2e15f68b5fec..66a3c7025056b195a204386c126024933c4ebca3 100644 (file)
--- a/src/oberon.c
+++ b/src/oberon.c
signature = oberon_new_type_ptr(OBERON_TYPE_VOID);
oberon_opt_formal_pars(ctx, &signature);
- oberon_initialize_decl(ctx);
+ //oberon_initialize_decl(ctx);
oberon_generator_init_type(ctx, signature);
oberon_close_scope(ctx -> decl);
oberon_object_t * proc;
proc = oberon_find_object(ctx -> decl, name, 0);
- if(proc != NULL)
+ if(proc == NULL)
+ {
+ proc = oberon_define_object(ctx -> decl, name, OBERON_CLASS_PROC, export, read_only, false);
+ proc -> type = signature;
+ proc -> scope = proc_scope;
+ oberon_generator_init_proc(ctx, proc);
+ }
+ else
{
if(proc -> class != OBERON_CLASS_PROC)
{
oberon_compare_signatures(ctx, proc -> type, signature);
}
- else
+
+ proc_scope -> parent = proc;
+ oberon_object_t * param = proc_scope -> list -> next;
+ while(param)
{
- proc = oberon_define_object(ctx -> decl, name, OBERON_CLASS_PROC, export, read_only, false);
- proc -> type = signature;
- proc -> scope = proc_scope;
- oberon_generator_init_proc(ctx, proc);
+ param -> parent = proc;
+ param = param -> next;
}
- proc -> scope -> parent = proc;
-
if(forward == 0)
{
proc -> linked = 1;
diff --git a/src/test.c b/src/test.c
index cd28a2109e803224afb6a10ca56baaf18184be64..595df77a7af072cf374214cd89c64b44c853fcaf 100644 (file)
--- a/src/test.c
+++ b/src/test.c
" r : R;"
""
"PROCEDURE X(VAR x : INTEGER);"
+ " PROCEDURE Y;"
+ " BEGIN"
+ " Out.String('YYYyYYYyYY'); Out.Ln;"
+ " END Y;"
"BEGIN"
+ " Y;"
" x := x * 666;"
"END X;"
""