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 = 158595859
return "sp_bigint_to_int((sp_Bigint *)" + val + ")"58605860
end5861+
# bigint -> obj_<C>: an int-returning user method whose return5862+
# widened to bigint under promote, but the caller's param slot is5863+
# still typed obj_<C>?. Unbox via sp_bigint_to_int then cast to5864+
# the pointer type (mirrors the int -> obj_<C> path in5865+
# compile_typed_call_args).5866+
if at == "bigint" && is_obj_type(expected_base) == 15867+
@needs_bigint = 15868+
cname_b2o = expected_base[4, expected_base.length - 4]5869+
return "(sp_" + cname_b2o + " *)(uintptr_t)sp_bigint_to_int((sp_Bigint *)" + val + ")"5870+
end58615871
# `*_ptr_array → poly_array` at the call boundary. The callee58625872
# was inferred to take poly_array (because at least one caller58635873
# 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]) == 12438424394
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]) == 12438624396
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]) == 124400+
@needs_bigint = 124401+
arg_v_ito = "sp_bigint_to_int((sp_Bigint *)" + arg_v_ito + ")"24402+
end24403+
result = result + "(sp_" + arg_cname + " *)(uintptr_t)" + arg_v_ito2438924404
k = k + 12439024405
next2439124406
end@@ -25042,18 +25057,23 @@
2504225057
next2504325058
end2504425059
aexpr = compile_expr(arg_ids[k])25045-
if at == "int"25060+
if at == "int" || at == "bigint" || expr_emit_is_bigint(arg_ids[k]) == 12504625061
if is_obj_type(pt) == 125047-
# Cast int to object pointer. Strip the nullable `?`25048-
# marker before deriving the C class name — a param25049-
# type like `obj_BoundMethod?` would otherwise produce25050-
# `(sp_BoundMethod? *)0` and gcc chokes on the stray `?`.25062+
# Cast int / bigint to object pointer. Strip the nullable25063+
# `?` marker before deriving the C class name. For bigint,25064+
# unbox first via sp_bigint_to_int (the int value is then25065+
# cast to pointer; NULL/0 stays NULL).2505125066
pt_base = pt2505225067
if is_nullable_type(pt) == 12505325068
pt_base = base_type(pt)2505425069
end2505525070
pcname = pt_base[4, pt_base.length - 4]25056-
aexpr = "(sp_" + pcname + " *)" + aexpr25071+
if at == "bigint" || expr_emit_is_bigint(arg_ids[k]) == 125072+
@needs_bigint = 125073+
aexpr = "(sp_" + pcname + " *)(uintptr_t)sp_bigint_to_int((sp_Bigint *)" + aexpr + ")"25074+
else25075+
aexpr = "(sp_" + pcname + " *)(uintptr_t)" + aexpr25076+
end2505725077
end2505825078
end2505925079
if is_obj_type(at) == 1