Commit e68173cb

e68173cb9f8aMerged

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

Description

Merge pull request #109 from ryanseys/rs-block-forward-self-call

fix(codegen): forward &block at self-call sites

Details

Commit
e68173cb9f8a
Parent
2dea1fbc799f
Merge parent
90c8e5c48b09

spinel_codegen.rbmodifiedView file

@@ -13955,23 +13955,35 @@
1395513955 if cidx >= 0
1395613956 owner = find_method_owner(@current_class_idx, mname)
1395713957 # Look up the method's owning class so we can fill in defaults
13958- # from @cls_meth_defaults (issue #49).
13958+ # from @cls_meth_defaults (issue #49) and check for a &block slot.
1395913959 owner_ci = find_class_idx(owner)
1396013960 owner_midx = -1
1396113961 if owner_ci >= 0
1396213962 owner_midx = cls_find_method_direct(owner_ci, mname)
1396313963 end
13964+ # Omit the trailing &block slot from default-padding when the
13965+ # callee declares one — we'll fill it explicitly from the
13966+ # call site's literal block below.
13967+ has_proc = cls_method_has_block_param(owner_ci, owner_midx)
1396413968 ca = ""
1396513969 if owner_midx >= 0
13966- ca = compile_typed_call_args(nid, owner_ci, owner_midx, 0)
13970+ ca = compile_typed_call_args(nid, owner_ci, owner_midx, has_proc)
1396713971 else
1396813972 ca = compile_call_args(nid)
1396913973 end
13970- if ca != ""
13971- return "sp_" + owner + "_" + sanitize_name(mname) + "(self, " + ca + ")"
13972- else
13973- return "sp_" + owner + "_" + sanitize_name(mname) + "(self)"
13974+ bp = ""
13975+ if has_proc == 1
13976+ if has_literal_block(nid) == 1
13977+ @needs_proc = 1
13978+ bp = compile_proc_literal(nid)
13979+ else
13980+ # The callee declares &block but the call site provides
13981+ # none — fill the slot with NULL so the C call has the
13982+ # right arity.
13983+ bp = "0"
13984+ end
1397413985 end
13986+ return "sp_" + owner + "_" + sanitize_name(mname) + "(self" + build_call_tail(ca, bp) + ")"
1397513987 end
1397613988 # Check attr_readers (bare method call like `x` meaning self.x)
1397713989 readers = @cls_attr_readers[@current_class_idx].split(";")