Commit f74117ab

f74117abddc2Merged

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

Description

fix(codegen): typed call args / expected_type cast bigint to obj pointer

Details

Commit
f74117abddc2
Parent
1a0cd1bcab75

spinel_codegen.rbmodifiedView file

@@ -5858,6 +5858,16 @@
58585858 @needs_bigint = 1
58595859 return "sp_bigint_to_int((sp_Bigint *)" + val + ")"
58605860 end
5861+ # bigint -> obj_<C>: an int-returning user method whose return
5862+ # widened to bigint under promote, but the caller's param slot is
5863+ # still typed obj_<C>?. Unbox via sp_bigint_to_int then cast to
5864+ # the pointer type (mirrors the int -> obj_<C> path in
5865+ # compile_typed_call_args).
5866+ if at == "bigint" && is_obj_type(expected_base) == 1
5867+ @needs_bigint = 1
5868+ cname_b2o = expected_base[4, expected_base.length - 4]
5869+ return "(sp_" + cname_b2o + " *)(uintptr_t)sp_bigint_to_int((sp_Bigint *)" + val + ")"
5870+ end
58615871 # `*_ptr_array → poly_array` at the call boundary. The callee
58625872 # was inferred to take poly_array (because at least one caller
58635873 # passes a heterogeneous literal) but this caller passes a
@@ -24382,10 +24392,15 @@
2438224392 # `incompatible integer to pointer conversion`.
2438324393 if is_obj_type(ptypes[k]) == 1
2438424394 arg_at = infer_type(positional_ids[k])
24385- if arg_at == "int"
24395+ if arg_at == "int" || arg_at == "bigint" || expr_emit_is_bigint(positional_ids[k]) == 1
2438624396 bt_arg = base_type(ptypes[k])
2438724397 arg_cname = bt_arg[4, bt_arg.length - 4]
24388- result = result + "(sp_" + arg_cname + " *)" + compile_expr(positional_ids[k])
24398+ arg_v_ito = compile_expr(positional_ids[k])
24399+ if arg_at == "bigint" || expr_emit_is_bigint(positional_ids[k]) == 1
24400+ @needs_bigint = 1
24401+ arg_v_ito = "sp_bigint_to_int((sp_Bigint *)" + arg_v_ito + ")"
24402+ end
24403+ result = result + "(sp_" + arg_cname + " *)(uintptr_t)" + arg_v_ito
2438924404 k = k + 1
2439024405 next
2439124406 end
@@ -25042,18 +25057,23 @@
2504225057 next
2504325058 end
2504425059 aexpr = compile_expr(arg_ids[k])
25045- if at == "int"
25060+ if at == "int" || at == "bigint" || expr_emit_is_bigint(arg_ids[k]) == 1
2504625061 if is_obj_type(pt) == 1
25047- # Cast int to object pointer. Strip the nullable `?`
25048- # marker before deriving the C class name — a param
25049- # type like `obj_BoundMethod?` would otherwise produce
25050- # `(sp_BoundMethod? *)0` and gcc chokes on the stray `?`.
25062+ # Cast int / bigint to object pointer. Strip the nullable
25063+ # `?` marker before deriving the C class name. For bigint,
25064+ # unbox first via sp_bigint_to_int (the int value is then
25065+ # cast to pointer; NULL/0 stays NULL).
2505125066 pt_base = pt
2505225067 if is_nullable_type(pt) == 1
2505325068 pt_base = base_type(pt)
2505425069 end
2505525070 pcname = pt_base[4, pt_base.length - 4]
25056- aexpr = "(sp_" + pcname + " *)" + aexpr
25071+ if at == "bigint" || expr_emit_is_bigint(arg_ids[k]) == 1
25072+ @needs_bigint = 1
25073+ aexpr = "(sp_" + pcname + " *)(uintptr_t)sp_bigint_to_int((sp_Bigint *)" + aexpr + ")"
25074+ else
25075+ aexpr = "(sp_" + pcname + " *)(uintptr_t)" + aexpr
25076+ end
2505725077 end
2505825078 end
2505925079 if is_obj_type(at) == 1