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 end
25257+ if mname == "to_i"
25258+ # Unbox the poly value's int payload. For SP_TAG_INT it's the
25259+ # raw `v.i`. For SP_TAG_OBJ branches the runtime values are
25260+ # always pointers — `.to_i` on a class that doesn't define
25261+ # `to_i` is the obj-id in Ruby; we approximate as 0 since
25262+ # spinel doesn't expose a stable obj-id and the only practical
25263+ # use is unboxing a poly-with-int payload (e.g. the result of
25264+ # `arr[i][j]` over a heterogeneous IntArray + Method array,
25265+ # whose dispatch arms all box back to SP_TAG_INT).
25266+ tmp = new_temp
25267+ recv_tmp = new_temp
25268+ emit(" sp_RbVal " + recv_tmp + " = " + rc + ";")
25269+ emit(" mrb_int " + tmp + " = (" + recv_tmp + ".tag == SP_TAG_INT) ? " + recv_tmp + ".v.i : 0;")
25270+ return tmp
25271+ end
2525725272 # For object method calls, dispatch based on cls_id. Two namespaces
2525825273 # of cls_id share SP_TAG_OBJ:
2525925274 # - non-negative: index into @cls_names (user-defined classes)