Commit 42c00eb0
42c00eb066d0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #316 from mame/pr/poly-to-i
fix(codegen): poly to_i unboxes SP_TAG_INT payload directly
Details
- Commit
- 42c00eb066d0
- Parent
- f068407724a9
- Merge parent
- 3c77e34ed8e6
spinel_codegen.rbmodifiedView file
@@ -25254,6 +25254,21 @@
2525425254
if mname == "to_s"2525525255
return "sp_poly_to_s(" + rc + ")"2525625256
end25257+
if mname == "to_i"25258+
# Unbox the poly value's int payload. For SP_TAG_INT it's the25259+
# raw `v.i`. For SP_TAG_OBJ branches the runtime values are25260+
# always pointers — `.to_i` on a class that doesn't define25261+
# `to_i` is the obj-id in Ruby; we approximate as 0 since25262+
# spinel doesn't expose a stable obj-id and the only practical25263+
# use is unboxing a poly-with-int payload (e.g. the result of25264+
# `arr[i][j]` over a heterogeneous IntArray + Method array,25265+
# whose dispatch arms all box back to SP_TAG_INT).25266+
tmp = new_temp25267+
recv_tmp = new_temp25268+
emit(" sp_RbVal " + recv_tmp + " = " + rc + ";")25269+
emit(" mrb_int " + tmp + " = (" + recv_tmp + ".tag == SP_TAG_INT) ? " + recv_tmp + ".v.i : 0;")25270+
return tmp25271+
end2525725272
# For object method calls, dispatch based on cls_id. Two namespaces2525825273
# of cls_id share SP_TAG_OBJ:2525925274
# - non-negative: index into @cls_names (user-defined classes)test/poly_to_i_via_str_poly_hash.rbaddedView file
Loading diff…
test/poly_to_i_via_str_poly_hash.rb.expectedaddedView file
Loading diff…