Commit 48ac4966

48ac49664a7bMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

Merge pull request #160 from mame/pr/box-pointer-types-to-poly

fix(codegen): box pointer-typed values to poly via sp_box_obj

Details

Commit
48ac49664a7b
Parent
78c568dfd64b
Merge parent
a7f1d9b68dca

spinel_codegen.rbmodifiedView file

@@ -19320,6 +19320,11 @@
1932019320 if at == "proc" || at == "lambda"
1932119321 return "sp_box_proc(" + val + ")"
1932219322 end
19323+ # Other pointer types (hashes, mutable strings, etc.) — box with a
19324+ # neutral cls_id of 0 rather than truncating the pointer to int.
19325+ if type_is_pointer(at) == 1
19326+ return "sp_box_obj((void *)(" + val + "), 0)"
19327+ end
1932319328 "sp_box_int(" + val + ")"
1932419329 end
1932519330
@@ -19345,6 +19350,33 @@
1934519350 if at == "symbol"
1934619351 return "sp_box_sym(" + val + ")"
1934719352 end
19353+ if at == "int_array"
19354+ return "sp_box_int_array(" + val + ")"
19355+ end
19356+ if at == "float_array"
19357+ return "sp_box_float_array(" + val + ")"
19358+ end
19359+ if at == "str_array"
19360+ return "sp_box_str_array(" + val + ")"
19361+ end
19362+ if at == "sym_array"
19363+ return "sp_box_sym_array(" + val + ")"
19364+ end
19365+ if is_ptr_array_type(at) == 1
19366+ return "sp_box_ptr_array(" + val + ")"
19367+ end
19368+ if is_obj_type(at) == 1
19369+ cname = at[4, at.length - 4]
19370+ ci = find_class_idx(cname)
19371+ return "sp_box_obj(" + val + ", " + ci.to_s + ")"
19372+ end
19373+ # Other pointer types (hashes, mutable strings, etc.) — box with a
19374+ # neutral cls_id of 0. Round-tripping back to the original concrete
19375+ # type is the caller's problem; this just makes the assignment
19376+ # type-check rather than silently truncating a pointer to mrb_int.
19377+ if type_is_pointer(at) == 1
19378+ return "sp_box_obj((void *)(" + val + "), 0)"
19379+ end
1934819380 "sp_box_int(" + val + ")"
1934919381 end
1935019382