13514
|
1 /*
|
|
2 * Copyright (c) 2013 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 com.oracle.truffle.ruby.nodes.cast;
|
|
11
|
|
12 import com.oracle.truffle.api.*;
|
|
13 import com.oracle.truffle.api.dsl.*;
|
|
14 import com.oracle.truffle.api.frame.*;
|
|
15 import com.oracle.truffle.api.nodes.*;
|
|
16 import com.oracle.truffle.ruby.nodes.*;
|
|
17 import com.oracle.truffle.ruby.nodes.call.*;
|
|
18 import com.oracle.truffle.ruby.runtime.*;
|
|
19 import com.oracle.truffle.ruby.runtime.core.*;
|
|
20 import com.oracle.truffle.ruby.runtime.objects.*;
|
|
21
|
|
22 /**
|
|
23 * Casts an object to a Ruby Proc object.
|
|
24 */
|
|
25 @NodeInfo(shortName = "cast-proc")
|
|
26 @NodeChild("child")
|
|
27 public abstract class ProcCastNode extends RubyNode {
|
|
28
|
|
29 @Child protected DispatchHeadNode toProc;
|
|
30
|
|
31 public ProcCastNode(RubyContext context, SourceSection sourceSection) {
|
|
32 super(context, sourceSection);
|
|
33 toProc = adoptChild(new DispatchHeadNode(context, getSourceSection(), "to_proc", false));
|
|
34 }
|
|
35
|
|
36 public ProcCastNode(ProcCastNode prev) {
|
|
37 super(prev);
|
|
38 toProc = adoptChild(prev.toProc);
|
|
39 }
|
|
40
|
|
41 @Specialization
|
|
42 public NilPlaceholder doNil(NilPlaceholder nil) {
|
|
43 return nil;
|
|
44 }
|
|
45
|
|
46 @Specialization
|
|
47 public RubyProc doRubyProc(RubyProc proc) {
|
|
48 return proc;
|
|
49 }
|
|
50
|
|
51 @Specialization
|
|
52 public RubyProc doObject(VirtualFrame frame, RubyBasicObject object) {
|
|
53 return (RubyProc) toProc.dispatch(frame, object, null);
|
|
54 }
|
|
55
|
|
56 }
|