Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/FiberNodes.java @ 13514:0fbee3eb71f0
Ruby: import project.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Mon, 06 Jan 2014 17:12:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13513:64a23ce736a0 | 13514:0fbee3eb71f0 |
---|---|
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.core; | |
11 | |
12 import com.oracle.truffle.api.*; | |
13 import com.oracle.truffle.api.dsl.*; | |
14 import com.oracle.truffle.ruby.runtime.*; | |
15 import com.oracle.truffle.ruby.runtime.core.*; | |
16 | |
17 @CoreClass(name = "Fiber") | |
18 public abstract class FiberNodes { | |
19 | |
20 @CoreMethod(names = "resume", isSplatted = true) | |
21 public abstract static class ResumeNode extends CoreMethodNode { | |
22 | |
23 public ResumeNode(RubyContext context, SourceSection sourceSection) { | |
24 super(context, sourceSection); | |
25 } | |
26 | |
27 public ResumeNode(ResumeNode prev) { | |
28 super(prev); | |
29 } | |
30 | |
31 @Specialization | |
32 public Object resume(RubyFiber fiberBeingResumed, Object[] args) { | |
33 final RubyFiber sendingFiber = getContext().getFiberManager().getCurrentFiber(); | |
34 | |
35 fiberBeingResumed.resume(sendingFiber, args); | |
36 | |
37 return sendingFiber.waitForResume(); | |
38 } | |
39 | |
40 } | |
41 | |
42 @CoreMethod(names = "initialize", needsBlock = true, maxArgs = 0) | |
43 public abstract static class InitializeNode extends CoreMethodNode { | |
44 | |
45 public InitializeNode(RubyContext context, SourceSection sourceSection) { | |
46 super(context, sourceSection); | |
47 } | |
48 | |
49 public InitializeNode(InitializeNode prev) { | |
50 super(prev); | |
51 } | |
52 | |
53 @Specialization | |
54 public NilPlaceholder initialize(RubyFiber fiber, RubyProc block) { | |
55 fiber.initialize(block); | |
56 return NilPlaceholder.INSTANCE; | |
57 } | |
58 | |
59 } | |
60 | |
61 @CoreMethod(names = "yield", isModuleMethod = true, needsSelf = false, isSplatted = true) | |
62 public abstract static class YieldNode extends CoreMethodNode { | |
63 | |
64 public YieldNode(RubyContext context, SourceSection sourceSection) { | |
65 super(context, sourceSection); | |
66 } | |
67 | |
68 public YieldNode(YieldNode prev) { | |
69 super(prev); | |
70 } | |
71 | |
72 @Specialization | |
73 public Object yield(Object[] args) { | |
74 final RubyFiber yieldingFiber = getContext().getFiberManager().getCurrentFiber(); | |
75 final RubyFiber fiberYieldedTo = yieldingFiber.lastResumedByFiber; | |
76 | |
77 fiberYieldedTo.resume(yieldingFiber, args); | |
78 | |
79 return yieldingFiber.waitForResume(); | |
80 } | |
81 | |
82 } | |
83 | |
84 } |