summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 51a1ab2)
raw | patch | inline | side by side (parent: 51a1ab2)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 3 Aug 2017 10:18:53 +0000 (13:18 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 3 Aug 2017 10:18:53 +0000 (13:18 +0300) |
jvm_test.sh | patch | blob | history | |
src/backends/jvm/generator-jvm.c | patch | blob | history | |
src/oberon.c | patch | blob | history | |
src/test.c | patch | blob | history |
diff --git a/jvm_test.sh b/jvm_test.sh
index 6519656ef1f13317b42551fb8e3b63bf9a35f1cc..0ec37e70c47df3ee58ea7b335045217189b1f12c 100755 (executable)
--- a/jvm_test.sh
+++ b/jvm_test.sh
javac -d classes rtl/*.java
# -a -- for asm as comments
-jad -o -b -noinner classes/*
+#jad -o -b -noinner classes/*
proguard -injars classes \
-libraryjars /usr/lib/jvm/java-8-openjdk/jre/lib/rt.jar \
index b17711bd5627d68a54b5dd06c4a475023a1a204a..0295e47c145d4081113e9271d78c12af4da5e2a8 100644 (file)
jvm_generate(p, cell_size, cell_size, "invokestatic java/lang/Math/abs(%c)%c", t, t);
}
-static void
-jvm_generate_compare_op(gen_proc_t * p, oberon_type_t * t, char prefix, int op)
+static char *
+jvm_get_compare_postfix(int op)
{
- int label_true = jvm_new_label_id(p);
- int label_done = jvm_new_label_id(p);
- char * label_name_true = jvm_get_label_name(label_true);
- char * label_name_done = jvm_get_label_name(label_done);
- int cell_size = 2 * jvm_cell_size_for_postfix(prefix);
-
- assert(prefix == 'i' || prefix == 'a');
-
- const char * cmpop = "";
+ char * cmpop = "";
switch(op)
{
case OP_EQ:
@@ -1557,10 +1549,44 @@ jvm_generate_compare_op(gen_proc_t * p, oberon_type_t * t, char prefix, int op)
gen_error("jvm_generate_compare_op: wat");
break;
}
+ return cmpop;
+}
+
+static void
+jvm_generate_compare_op(gen_proc_t * p, oberon_type_t * t, int op)
+{
+ char prefix = jvm_get_prefix(t);
+ int label_true = jvm_new_label_id(p);
+ int label_done = jvm_new_label_id(p);
+ int cell_size = jvm_cell_size_for_type(t);
+ char * cmpop = jvm_get_compare_postfix(op);
+
+ if(prefix == 'l')
+ {
+ jvm_generate(p, 2 * cell_size, 1, "lcmp");
+ jvm_generate(p, 1, 1, "if%s L%i", cmpop, label_true);
+ }
+ else if(prefix == 'f' || prefix == 'd')
+ {
+ char fop;
+ if(op == OP_EQ || op == OP_NEQ || op == OP_GRT || op == OP_GEQ)
+ {
+ fop = 'l';
+ }
+ else
+ {
+ fop = 'g';
+ }
+ jvm_generate(p, 2 * cell_size, 1, "%ccmp%c", prefix, fop);
+ jvm_generate(p, 1, 1, "if%s L%i", cmpop, label_true);
+ }
+ else
+ {
+ jvm_generate(p, 2 * cell_size, 0, "if_%ccmp%s L%i", prefix, cmpop, label_true);
+ }
- jvm_generate(p, cell_size, 0, "if_%ccmp%s %s", prefix, cmpop, label_name_true);
jvm_generate(p, 0, 1, "iconst_0");
- jvm_generate(p, 0, 0, "goto %s", label_name_done);
+ jvm_generate(p, 0, 0, "goto L%i", label_done);
jvm_generate_label(p, label_true);
jvm_generate(p, 0, 1, "iconst_1");
jvm_generate_label(p, label_done);
case OP_LEQ:
case OP_GRT:
case OP_GEQ:
- jvm_generate_compare_op(p, t, prefix, op);
+ jvm_generate_compare_op(p, t, op);
break;
default:
gen_error("jvm_generate_operator: unk op %i", op);
diff --git a/src/oberon.c b/src/oberon.c
index 5816c2b3fb0a96f2076f0e6ff82fbeb2b87058d2..f2c901433aeb49363ef01007ed8336a1e5db1919 100644 (file)
--- a/src/oberon.c
+++ b/src/oberon.c
oberon_statement_seq(ctx);
oberon_generate_goto(ctx, end);
+ oberon_generate_label(ctx, els);
if(ctx -> token == ELSE)
{
- oberon_generate_label(ctx, els);
oberon_assert_token(ctx, ELSE);
oberon_statement_seq(ctx);
}
diff --git a/src/test.c b/src/test.c
index a144f3616074e1f8891dbc30af0007420bad0ef9..d2501611eee396c8c7f2e4036d115937e967eec3 100644 (file)
--- a/src/test.c
+++ b/src/test.c
#include "../include/oberon.h"
+/*
static char source_test[] =
"(* Main module *)"
"MODULE Test;"
"IMPORT Out;"
""
"TYPE"
- " R = INTEGER;"
+ " R = LONGINT;"
""
"PROCEDURE Factorial(n : R) : R;"
"BEGIN"
" Out.Int(Factorial(12), 0); Out.Ln;"
" Out.Int(Factorial(13), 0); Out.Ln;"
" Out.Int(Factorial(14), 0); Out.Ln;"
+ " Out.Int(Factorial(15), 0); Out.Ln;"
+ " Out.Int(Factorial(16), 0); Out.Ln;"
+ " Out.Int(Factorial(17), 0); Out.Ln;"
+ " Out.Int(Factorial(18), 0); Out.Ln;"
+ " Out.Int(Factorial(19), 0); Out.Ln;"
+ " Out.Int(Factorial(20), 0); Out.Ln;"
+ "END Test."
+;
+*/
+
+static char source_test[] =
+ "(* Main module *)"
+ "MODULE Test;"
+ "IMPORT Out;"
+ ""
+ "TYPE"
+ " R = LONGREAL;"
+ ""
+ "PROCEDURE Factorial(n : R) : R;"
+ "BEGIN"
+ " IF n <= 1 THEN"
+ " RETURN 1;"
+ " ELSE"
+ " RETURN n * Factorial(n - 1);"
+ " END;"
+ " RETURN 0; (* Детектор ретурнов - дерьмо *)"
+ "END Factorial;"
+ ""
+ "BEGIN"
+ " Out.Open();"
+ " Out.LongReal(Factorial(0), 0); Out.Ln;"
+ " Out.LongReal(Factorial(1), 0); Out.Ln;"
+ " Out.LongReal(Factorial(2), 0); Out.Ln;"
+ " Out.LongReal(Factorial(3), 0); Out.Ln;"
+ " Out.LongReal(Factorial(4), 0); Out.Ln;"
+ " Out.LongReal(Factorial(5), 0); Out.Ln;"
+ " Out.LongReal(Factorial(6), 0); Out.Ln;"
+ " Out.LongReal(Factorial(7), 0); Out.Ln;"
+ " Out.LongReal(Factorial(8), 0); Out.Ln;"
+ " Out.LongReal(Factorial(9), 0); Out.Ln;"
+ " Out.LongReal(Factorial(10), 0); Out.Ln;"
+ " Out.LongReal(Factorial(11), 0); Out.Ln;"
+ " Out.LongReal(Factorial(12), 0); Out.Ln;"
+ " Out.LongReal(Factorial(13), 0); Out.Ln;"
+ " Out.LongReal(Factorial(14), 0); Out.Ln;"
+ " Out.LongReal(Factorial(15), 0); Out.Ln;"
+ " Out.LongReal(Factorial(16), 0); Out.Ln;"
+ " Out.LongReal(Factorial(17), 0); Out.Ln;"
+ " Out.LongReal(Factorial(18), 0); Out.Ln;"
+ " Out.LongReal(Factorial(19), 0); Out.Ln;"
+ " Out.LongReal(Factorial(20), 0); Out.Ln;"
+ " Out.LongReal(Factorial(170), 0); Out.Ln;"
"END Test."
;