Commit eddc7bf7

eddc7bf75da7Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): bigint <=> dispatch returns mrb_int comparator

Details

Commit
eddc7bf75da7
Parent
37f253d3bfe9

spinel_codegen.rbmodifiedView file

@@ -14570,6 +14570,28 @@
1457014570 if recv_type == "bigint"
1457114571 # Cast away volatile from bigint locals (see compile_bigint_arg).
1457214572 rc_b = "(sp_Bigint *)" + rc
14573+ if mname == "<=>"
14574+ # 3-way compare on bigint. Returns mrb_int (-1 / 0 / 1) at C
14575+ # level; outer wrappers (return / push into bigint slot) will
14576+ # promote to bigint when needed.
14577+ args_id_cmp = @nd_arguments[nid]
14578+ if args_id_cmp >= 0
14579+ a_cmp = get_args(args_id_cmp)
14580+ if a_cmp.length > 0
14581+ other_t_cmp = infer_type(a_cmp[0])
14582+ other_c_cmp = compile_expr(a_cmp[0])
14583+ if other_t_cmp == "bigint" || expr_emit_is_bigint(a_cmp[0]) == 1
14584+ return "sp_bigint_cmp(" + rc_b + ", (sp_Bigint *)" + other_c_cmp + ")"
14585+ end
14586+ if other_t_cmp == "int"
14587+ return "sp_bigint_cmp(" + rc_b + ", sp_bigint_new_int(" + other_c_cmp + "))"
14588+ end
14589+ if other_t_cmp == "float"
14590+ return "(((mrb_float)sp_bigint_to_int(" + rc_b + ") < " + other_c_cmp + ") ? -1 : ((mrb_float)sp_bigint_to_int(" + rc_b + ") > " + other_c_cmp + " ? 1 : 0))"
14591+ end
14592+ end
14593+ end
14594+ end
1457314595 if mname == "[]"
1457414596 # Integer#[idx] bit-index on bigint receiver.
1457514597 args_id_bi = @nd_arguments[nid]