Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Truffle] New primitive array node for writing to an array by simple …
…index.
- Loading branch information
1 parent
4a5a146
commit a294f73
Showing
7 changed files
with
583 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
truffle/src/main/java/org/jruby/truffle/nodes/array/ArrayWriteDenormalizedNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.nodes.array; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.NodeChildren; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.nodes.RubyNode; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.core.RubyArray; | ||
|
||
@NodeChildren({ | ||
@NodeChild(value="array", type=RubyNode.class), | ||
@NodeChild(value="index", type=RubyNode.class), | ||
@NodeChild(value="value", type=RubyNode.class) | ||
}) | ||
public abstract class ArrayWriteDenormalizedNode extends RubyNode { | ||
|
||
@Child private ArrayWriteNormalizedNode readNode; | ||
|
||
public ArrayWriteDenormalizedNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public ArrayWriteDenormalizedNode(ArrayWriteDenormalizedNode prev) { | ||
super(prev); | ||
readNode = prev.readNode; | ||
} | ||
|
||
public abstract Object executeWrite(VirtualFrame frame, RubyArray array, int index, Object value); | ||
|
||
@Specialization | ||
public Object read(VirtualFrame frame, RubyArray array, int index, Object value) { | ||
if (readNode == null) { | ||
CompilerDirectives.transferToInterpreter(); | ||
readNode = insert(ArrayWriteNormalizedNodeFactory.create(getContext(), getSourceSection(), null, null, null)); | ||
} | ||
|
||
final int normalizedIndex = array.normalizeIndex(index); | ||
|
||
return readNode.executeWrite(frame, array, normalizedIndex, value); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
} |
Oops, something went wrong.
This reads in a interesting way 😉