X-Git-Url: https://deadsoftware.ru/gitweb?p=dsw-obn.git;a=blobdiff_plain;f=src%2Fbackends%2Fjvm%2Fgenerator-jvm.c;h=c2fd9abd4662bef894b32ae159650e7cdcb4baa2;hp=bb1123147706034e75ce660c255861fbc7a20f9f;hb=95acec6c3ae8d3c324c84b001a680aa49320790b;hpb=f4aa48e4c1e3b81ccbe3da5c33fdaba3a46081dd diff --git a/src/backends/jvm/generator-jvm.c b/src/backends/jvm/generator-jvm.c index bb11231..c2fd9ab 100644 --- a/src/backends/jvm/generator-jvm.c +++ b/src/backends/jvm/generator-jvm.c @@ -1141,8 +1141,11 @@ jvm_generate_cast_type(gen_proc_t * p, oberon_type_t * from, oberon_type_t * to) { if(to -> class == OBERON_TYPE_RECORD || to -> class == OBERON_TYPE_POINTER) { - char * full_name = jvm_get_class_full_name(to); - jvm_generate(p, 1, 1, "checkcast %s", full_name); + if(to -> class == OBERON_TYPE_POINTER && to -> base -> class == OBERON_TYPE_RECORD) + { + char * full_name = jvm_get_class_full_name(to); + jvm_generate(p, 1, 1, "checkcast %s", full_name); + } } else { @@ -1301,6 +1304,19 @@ jvm_generate_compare_op(gen_proc_t * p, oberon_type_t * t, int op) jvm_generate(p, 2 * cell_size, 1, "%ccmp%c", prefix, fop); jvm_generate(p, 1, 1, "if%s L%i", cmpop, label_true); } + else if(prefix == 'a') + { + if(t -> class == OBERON_TYPE_STRING + || (t -> class == OBERON_TYPE_POINTER && t -> base -> class == OBERON_TYPE_CHAR)) + { + jvm_generate(p, 2, 1, "invokestatic SYSTEM/STRCMP([B[B)I"); + jvm_generate(p, 1, 0, "if%s L%i", cmpop, label_true); + } + else + { + jvm_generate(p, 1, 0, "if_acmp%s L%i", cmpop, label_true); + } + } else { jvm_generate(p, 2 * cell_size, 0, "if_%ccmp%s L%i", prefix, cmpop, label_true); @@ -1333,6 +1349,9 @@ jvm_generate_operator(gen_proc_t * p, oberon_type_t * t, int op) case OP_ABS: jvm_generate_abs(p, prefix); break; + case OP_CAP: + jvm_generate(p, cell_size, cell_size, "invokestatic java/lang/Character/toUpperCase(I)I"); + break; case OP_ADD: jvm_generate(p, 2 * cell_size, cell_size, "%cadd", prefix); @@ -1356,6 +1375,7 @@ jvm_generate_operator(gen_proc_t * p, oberon_type_t * t, int op) jvm_generate(p, 2 * cell_size, cell_size, "%cand", prefix); break; case OP_DIFFERENCE: + /* (a - b) == a & ~b */ jvm_generate_push_int_size(p, -1, t -> size); jvm_generate(p, 2 * cell_size, cell_size, "%cxor", prefix); jvm_generate(p, 2 * cell_size, cell_size, "%cand", prefix); @@ -1482,6 +1502,7 @@ jvm_generate_in(gen_proc_t * p, oberon_expr_t * a, oberon_expr_t * b) int label_else = jvm_new_label_id(p); int label_end = jvm_new_label_id(p); + /* (a IN b) == (1 << a) & b */ jvm_generate_push_int_size(p, 1, t -> size); push_expr(p, a); jvm_generate(p, 2 * cell_size, cell_size, "%cshl", prefix); @@ -1501,6 +1522,39 @@ jvm_generate_in(gen_proc_t * p, oberon_expr_t * a, oberon_expr_t * b) jvm_generate_label(p, label_end); } +static void +jvm_generate_ash(gen_proc_t * p, oberon_expr_t * a, oberon_expr_t * b) +{ + oberon_type_t * t = a -> result; + int cell_size = jvm_cell_size_for_type(t); + char prefix = jvm_get_prefix(t); + int label_else = jvm_new_label_id(p); + int label_end = jvm_new_label_id(p); + + /* if b < 0 then a << b else a >> b end */ + + push_expr(p, a); + push_expr(p, b); + if(cell_size == 1) + { + jvm_generate(p, cell_size, 2 * cell_size, "dup"); + } + else + { + jvm_generate(p, cell_size, 2 * cell_size, "dup2"); + } + jvm_generate_push_int_size(p, 0, t -> size); + jvm_generate_compare_op(p, t, OP_LSS); + + jvm_generate(p, cell_size, 0, "ifne L%i", label_else); + jvm_generate(p, 2 * cell_size, cell_size, "%cshl", prefix); + jvm_generate(p, 0, 0, "goto L%i", label_end); + jvm_generate_label(p, label_else); + jvm_generate_abs(p, prefix); + jvm_generate(p, 2 * cell_size, cell_size, "%cshr", prefix); + jvm_generate_label(p, label_end); +} + static void push_operator(gen_proc_t * p, oberon_oper_t * oper) { @@ -1516,6 +1570,7 @@ push_operator(gen_proc_t * p, oberon_oper_t * oper) case OP_UNARY_MINUS: case OP_LOGIC_NOT: case OP_ABS: + case OP_CAP: push_expr(p, oper -> left); jvm_generate_operator(p, preq, op); break; @@ -1561,6 +1616,10 @@ push_operator(gen_proc_t * p, oberon_oper_t * oper) case OP_IN: jvm_generate_in(p, oper -> left, oper -> right); break; + + case OP_ASH: + jvm_generate_ash(p, oper -> left, oper -> right); + break; default: gen_error("push_oper: unk op %i", op); break;