reduce mcode
This commit is contained in:
25
mcode.cm
25
mcode.cm
@@ -557,7 +557,7 @@ var mcode = function(ast) {
|
||||
|
||||
// emit_relational: int -> float -> text -> disrupt
|
||||
// reads _bp_dest, _bp_left, _bp_right, _bp_ln, _bp_rn from closure
|
||||
var emit_relational = function(int_op, float_op, text_op) {
|
||||
var emit_relational = function(poly_op, int_op, float_op, text_op) {
|
||||
var dest = _bp_dest
|
||||
var left = _bp_left
|
||||
var right = _bp_right
|
||||
@@ -590,26 +590,17 @@ var mcode = function(ast) {
|
||||
return null
|
||||
}
|
||||
|
||||
not_int = gen_label("rel_ni")
|
||||
not_num = gen_label("rel_nn")
|
||||
done = gen_label("rel_done")
|
||||
err = gen_label("rel_err")
|
||||
|
||||
t0 = alloc_slot()
|
||||
emit_2("is_int", t0, left)
|
||||
emit_jump_cond("jump_false", t0, not_int)
|
||||
t1 = alloc_slot()
|
||||
emit_2("is_int", t1, right)
|
||||
emit_jump_cond("jump_false", t1, not_int)
|
||||
emit_3(int_op, dest, left, right)
|
||||
emit_jump(done)
|
||||
|
||||
emit_label(not_int)
|
||||
emit_2("is_num", t0, left)
|
||||
emit_jump_cond("jump_false", t0, not_num)
|
||||
t1 = alloc_slot()
|
||||
emit_2("is_num", t1, right)
|
||||
emit_jump_cond("jump_false", t1, not_num)
|
||||
emit_3(float_op, dest, left, right)
|
||||
emit_3(poly_op, dest, left, right)
|
||||
emit_jump(done)
|
||||
|
||||
emit_label(not_num)
|
||||
@@ -651,10 +642,10 @@ var mcode = function(ast) {
|
||||
// Central router: maps op string to decomposition helper
|
||||
// Sets _bp_* closure vars then calls helper with reduced args
|
||||
var relational_ops = {
|
||||
lt: ["lt_int", "lt_float", "lt_text"],
|
||||
le: ["le_int", "le_float", "le_text"],
|
||||
gt: ["gt_int", "gt_float", "gt_text"],
|
||||
ge: ["ge_int", "ge_float", "ge_text"]
|
||||
lt: ["lt", "lt_int", "lt_float", "lt_text"],
|
||||
le: ["le", "le_int", "le_float", "le_text"],
|
||||
gt: ["gt", "gt_int", "gt_float", "gt_text"],
|
||||
ge: ["ge", "ge_int", "ge_float", "ge_text"]
|
||||
}
|
||||
var emit_binop = function(op_str, dest, left, right) {
|
||||
var rel = null
|
||||
@@ -671,7 +662,7 @@ var mcode = function(ast) {
|
||||
} else {
|
||||
rel = relational_ops[op_str]
|
||||
if (rel != null) {
|
||||
emit_relational(rel[0], rel[1], rel[2])
|
||||
emit_relational(rel[0], rel[1], rel[2], rel[3])
|
||||
} else if (op_str == "subtract" || op_str == "multiply" ||
|
||||
op_str == "divide" || op_str == "modulo" || op_str == "remainder" ||
|
||||
op_str == "pow") {
|
||||
|
||||
Reference in New Issue
Block a user