|
34 | 34 | import org.truffleruby.language.control.RaiseException;
|
35 | 35 | import org.truffleruby.language.dispatch.DispatchNode;
|
36 | 36 | import org.truffleruby.language.locals.FindDeclarationVariableNodes.FindAndReadDeclarationVariableNode;
|
| 37 | +import org.truffleruby.language.methods.Arity; |
| 38 | +import org.truffleruby.language.methods.SharedMethodInfo; |
37 | 39 | import org.truffleruby.language.objects.AllocationTracing;
|
38 | 40 | import org.truffleruby.language.yield.CallBlockNode;
|
39 | 41 | import org.truffleruby.parser.ArgumentDescriptor;
|
@@ -256,19 +258,32 @@ public abstract static class ProcCreateSameArityNode extends PrimitiveArrayArgum
|
256 | 258 |
|
257 | 259 | @Specialization
|
258 | 260 | protected RubyProc createSameArityProc(RubyProc userProc, RubyProc block) {
|
259 |
| - final RubyProc composedProc = new RubyProc( |
260 |
| - coreLibrary().procClass, |
261 |
| - getLanguage().procShape, |
262 |
| - block.type, |
| 261 | + final RubyProc composedProc = block.withSharedMethodInfo( |
263 | 262 | userProc.sharedMethodInfo,
|
264 |
| - block.callTargets, |
265 |
| - block.callTarget, |
266 |
| - block.declarationFrame, |
267 |
| - block.declarationVariables, |
268 |
| - block.method, |
269 |
| - block.block, |
270 |
| - block.frameOnStackMarker, |
271 |
| - block.declarationContext); |
| 263 | + coreLibrary().procClass, |
| 264 | + getLanguage().procShape); |
| 265 | + AllocationTracing.trace(composedProc, this); |
| 266 | + return composedProc; |
| 267 | + } |
| 268 | + } |
| 269 | + |
| 270 | + @Primitive(name = "proc_specify_arity", lowerFixnum = 1) |
| 271 | + public abstract static class ProcSpecifyArityNode extends PrimitiveArrayArgumentsNode { |
| 272 | + @Specialization |
| 273 | + protected RubyProc specifyArityProc(RubyProc block, int argc) { |
| 274 | + Arity oldArity = block.sharedMethodInfo.getArity(); |
| 275 | + final Arity newArity; |
| 276 | + if (argc <= -1) { |
| 277 | + newArity = new Arity(-(argc + 1), 0, true); |
| 278 | + } else { |
| 279 | + newArity = new Arity(argc, 0, false); |
| 280 | + } |
| 281 | + |
| 282 | + SharedMethodInfo newSharedMethodInfo = block.sharedMethodInfo.withArity(newArity); |
| 283 | + final RubyProc composedProc = block.withSharedMethodInfo( |
| 284 | + newSharedMethodInfo, |
| 285 | + coreLibrary().procClass, |
| 286 | + getLanguage().procShape); |
272 | 287 | AllocationTracing.trace(composedProc, this);
|
273 | 288 | return composedProc;
|
274 | 289 | }
|
|
0 commit comments