summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2384633)
raw | patch | inline | side by side (parent: 2384633)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 26 Jul 2017 19:57:29 +0000 (22:57 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 26 Jul 2017 19:57:29 +0000 (22:57 +0300) |
src/backends/jvm/generator-jvm.c | patch | blob | history | |
src/test.c | patch | blob | history |
index b0c54ff1d967aab8a5126d43f1313a344be408f4..eb0f3dc16b014bc803edf7307ce29049917efb51 100644 (file)
}
}
+static void
+jvm_generate_logical_or(oberon_context_t * ctx, FILE * fp, oberon_expr_t * p, oberon_expr_t * q)
+{
+ int label_calc_q = jvm_new_label_id(ctx);
+ int label_done = jvm_new_label_id(ctx);
+ char * label_name_calc_q = jvm_get_label_name(label_calc_q);
+ char * label_name_done = jvm_get_label_name(label_done);
+
+ /* p OR q -- если p, то TRUE, иначе q */
+
+ push_expr(ctx, fp, p);
+ fprintf(fp, "ifne %s\n", label_name_calc_q);
+ fprintf(fp, "iconst_1\n");
+ fprintf(fp, "goto %s\n", label_name_done);
+ jvm_generate_label(fp, label_calc_q);
+ push_expr(ctx, fp, q);
+ jvm_generate_label(fp, label_done);
+}
+
+static void
+jvm_generate_logical_and(oberon_context_t * ctx, FILE * fp, oberon_expr_t * p, oberon_expr_t * q)
+{
+ int label_false = jvm_new_label_id(ctx);
+ int label_done = jvm_new_label_id(ctx);
+ char * label_name_false = jvm_get_label_name(label_false);
+ char * label_name_done = jvm_get_label_name(label_done);
+
+ /* p AND q -- если p, то q, иначе FALSE */
+
+ push_expr(ctx, fp, p);
+ fprintf(fp, "ifne %s\n", label_name_false);
+ push_expr(ctx, fp, q);
+ fprintf(fp, "goto %s\n", label_name_done);
+ jvm_generate_label(fp, label_false);
+ fprintf(fp, "iconst_0\n");
+ jvm_generate_label(fp, label_done);
+}
+
static void
push_operator(oberon_context_t * ctx, FILE * fp, oberon_oper_t * oper)
{
jvm_generate_operator(ctx, fp, prefix, op);
break;
+ case OP_LOGIC_OR:
+ jvm_generate_logical_or(ctx, fp, oper -> left, oper -> right);
+ break;
+ case OP_LOGIC_AND:
+ jvm_generate_logical_and(ctx, fp, oper -> left, oper -> right);
+ break;
default:
oberon_error(ctx, "push_oper: unk op %i", op);
break;
diff --git a/src/test.c b/src/test.c
index 96e160a7087354a4e07b77900298aacdf9e235ba..6543c472967939fdd097218aacb349d860ed90ba 100644 (file)
--- a/src/test.c
+++ b/src/test.c
"BEGIN;"
" x := ABS(-666);"
" x := Tier(x);"
- " b := ~TRUE;"
+ " b := TRUE OR FALSE;"
"END Test."
;