|
6 | 6 | * Eclipse Public License version 1.0
|
7 | 7 | * GNU General Public License version 2
|
8 | 8 | * GNU Lesser General Public License version 2.1
|
| 9 | + * |
| 10 | + * Some of the code in this class is transliterated from C++ code in Rubinius. |
| 11 | + * |
| 12 | + * Copyright (c) 2007-2014, Evan Phoenix and contributors |
| 13 | + * All rights reserved. |
| 14 | + * |
| 15 | + * Redistribution and use in source and binary forms, with or without |
| 16 | + * modification, are permitted provided that the following conditions are met: |
| 17 | + * |
| 18 | + * * Redistributions of source code must retain the above copyright notice, this |
| 19 | + * list of conditions and the following disclaimer. |
| 20 | + * * Redistributions in binary form must reproduce the above copyright notice |
| 21 | + * this list of conditions and the following disclaimer in the documentation |
| 22 | + * and/or other materials provided with the distribution. |
| 23 | + * * Neither the name of Rubinius nor the names of its contributors |
| 24 | + * may be used to endorse or promote products derived from this software |
| 25 | + * without specific prior written permission. |
| 26 | + * |
| 27 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 28 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 29 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 30 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 31 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 33 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 34 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 35 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 36 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
9 | 37 | */
|
10 | 38 | package org.jruby.truffle.nodes.rubinius;
|
11 | 39 |
|
@@ -136,6 +164,44 @@ public Object read(RubyBasicObject dir) {
|
136 | 164 |
|
137 | 165 | }
|
138 | 166 |
|
| 167 | + |
| 168 | + @RubiniusPrimitive(name = "dir_control") |
| 169 | + public static abstract class DirControlPrimitiveNode extends RubiniusPrimitiveNode { |
| 170 | + |
| 171 | + @Child private ReadHeadObjectFieldNode readPositionNode; |
| 172 | + @Child private WriteHeadObjectFieldNode writePositionNode; |
| 173 | + |
| 174 | + public DirControlPrimitiveNode(RubyContext context, SourceSection sourceSection) { |
| 175 | + super(context, sourceSection); |
| 176 | + readPositionNode = new ReadHeadObjectFieldNode(positionKey); |
| 177 | + writePositionNode = new WriteHeadObjectFieldNode(positionKey); |
| 178 | + } |
| 179 | + |
| 180 | + @CompilerDirectives.TruffleBoundary |
| 181 | + @Specialization |
| 182 | + public Object control(RubyBasicObject dir, int kind, int position) { |
| 183 | + switch (kind) { |
| 184 | + case 0: |
| 185 | + writePositionNode.execute(dir, position); |
| 186 | + return true; |
| 187 | + case 1: |
| 188 | + writePositionNode.execute(dir, -2); |
| 189 | + return true; |
| 190 | + case 2: |
| 191 | + try { |
| 192 | + return readPositionNode.executeInteger(dir); |
| 193 | + } catch (UnexpectedResultException e) { |
| 194 | + throw new IllegalStateException(); |
| 195 | + } |
| 196 | + |
| 197 | + } |
| 198 | + return nil(); |
| 199 | + } |
| 200 | + |
| 201 | + } |
| 202 | + |
| 203 | + |
| 204 | + |
139 | 205 | @RubiniusPrimitive(name = "dir_close")
|
140 | 206 | public static abstract class DirClosePrimitiveNode extends RubiniusPrimitiveNode {
|
141 | 207 |
|
|
0 commit comments