LambdaNode.java

  1. /*
  2.  * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
  3.  * code is released under a tri EPL/GPL/LGPL license. You can use it,
  4.  * redistribute it and/or modify it under the terms of the:
  5.  *
  6.  * Eclipse Public License version 1.0
  7.  * GNU General Public License version 2
  8.  * GNU Lesser General Public License version 2.1
  9.  */
  10. package org.jruby.truffle.nodes.cast;

  11. import com.oracle.truffle.api.frame.VirtualFrame;
  12. import com.oracle.truffle.api.source.SourceSection;
  13. import org.jruby.truffle.nodes.RubyNode;
  14. import org.jruby.truffle.runtime.RubyArguments;
  15. import org.jruby.truffle.runtime.RubyContext;
  16. import org.jruby.truffle.runtime.core.RubyProc;
  17. import org.jruby.truffle.runtime.methods.RubyMethod;

  18. public class LambdaNode extends RubyNode {

  19.     // TODO(CS): this should be a lambda definition node, alongside block definition node

  20.     @Child protected RubyNode definition;

  21.     public LambdaNode(RubyContext context, SourceSection sourceSection, RubyNode definition) {
  22.         super(context, sourceSection);
  23.         this.definition = definition;
  24.     }

  25.     @Override
  26.     public Object execute(VirtualFrame frame) {
  27.         notDesignedForCompilation();

  28.         final RubyMethod method = (RubyMethod) definition.execute(frame);

  29.         // TODO(CS): not sure we're closing over the correct state here

  30.         return new RubyProc(getContext().getCoreLibrary().getProcClass(), RubyProc.Type.LAMBDA,
  31.                 method.getSharedMethodInfo(), method.getCallTarget(), method.getCallTarget(),
  32.                 method.getDeclarationFrame(), method.getDeclaringModule(), method, RubyArguments.getSelf(frame.getArguments()), null);
  33.     }

  34.     @Override
  35.     public void executeVoid(VirtualFrame frame) {
  36.         definition.executeVoid(frame);
  37.     }

  38. }