From: DeaDDooMER Date: Tue, 25 Jul 2017 18:18:15 +0000 (+0300) Subject: JVM: Добавлен вызов процедур X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=3b56d873cc052fcbe8914dba3b9ae9ea220a801e;p=dsw-obn.git JVM: Добавлен вызов процедур --- diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index 2a2abcd..9812f0a 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -229,7 +229,7 @@ oberon_generate_procedure_class(oberon_context_t * ctx, oberon_type_t * proc) fprintf(fp, " aload_0\n"); fprintf(fp, " invokespecial java/lang/Object/()V\n"); fprintf(fp, " return\n"); - fprintf(fp, ".end method\n"); + fprintf(fp, ".end method\n\n"); fprintf(fp, ".method public abstract invoke%s\n", signature); fprintf(fp, ".end method\n\n"); @@ -347,6 +347,9 @@ oberon_generator_init_var(oberon_context_t * ctx, oberon_object_t * var) switch(var -> class) { + case OBERON_CLASS_VAR_PARAM: + oberon_error(ctx, "generator: VAR-parameters not implemented"); + break; case OBERON_CLASS_PARAM: case OBERON_CLASS_FIELD: break; @@ -398,6 +401,9 @@ oberon_generator_init_module(oberon_context_t * ctx, oberon_module_t * mod) // GENERATOR // ======================================================================= +static void +push_expr(oberon_context_t * ctx, FILE * fp, oberon_expr_t * expr); + void oberon_generate_begin_module(oberon_context_t * ctx) { @@ -433,7 +439,28 @@ oberon_generate_begin_proc(oberon_context_t * ctx, oberon_object_t * proc) void oberon_generate_call_proc(oberon_context_t * ctx, oberon_expr_t * desig) { - printf("call proc\n"); + oberon_object_t * proc; + gen_module_t * m; + char * fullname; + char * signature; + + assert(desig -> is_item); + assert(desig -> item.mode == MODE_CALL); + + m = ctx -> mod -> gen_mod; + proc = desig -> item.var; + fullname = get_field_full_name(ctx, proc); + signature = get_procedure_signature(ctx, proc -> type); + + int num = desig -> item.num_args; + oberon_expr_t * arg = desig -> item.args; + for(int i = 0; i < num; i++) + { + push_expr(ctx, m -> fp, arg); + arg = arg -> next; + } + + fprintf(m -> fp, "invokestatic %s%s\n", fullname, signature); } void diff --git a/src/test.c b/src/test.c index 53be586..0c80e4b 100644 --- a/src/test.c +++ b/src/test.c @@ -11,12 +11,13 @@ static char source_test[] = " x : INTEGER;" " z : BOOLEAN;" "" - "PROCEDURE Tier(a, b :INTEGER);" + "PROCEDURE Tier(x : INTEGER);" "END Tier;" "" "BEGIN;" - " x := x + 1;" - " z := TRUE;" + " x := x + 1;" + " z := TRUE;" + " Tier(666);" "END Test." ;