Skip to content

Commit

Permalink
Showing 23 changed files with 61 additions and 390 deletions.
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -1694,7 +1694,6 @@ private void initBuiltins() {
addLazyBuiltin("stringio.jar", "stringio", "org.jruby.ext.stringio.StringIOLibrary");
addLazyBuiltin("strscan.jar", "strscan", "org.jruby.ext.strscan.StringScannerLibrary");
addLazyBuiltin("zlib.jar", "zlib", "org.jruby.ext.zlib.ZlibLibrary");
addLazyBuiltin("enumerator.jar", "enumerator", "org.jruby.ext.enumerator.EnumeratorLibrary");
addLazyBuiltin("thread.jar", "thread", "org.jruby.ext.thread.ThreadLibrary");
addLazyBuiltin("thread.rb", "thread", "org.jruby.ext.thread.ThreadLibrary");
addLazyBuiltin("digest.jar", "digest.so", "org.jruby.ext.digest.DigestLibrary");
@@ -1731,6 +1730,14 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
addBuiltinIfAllowed("continuation.rb", dummy);
addBuiltinIfAllowed("io/nonblock.rb", dummy);

// rb_provide logic, in a roundabout way
addLazyBuiltin("enumerator.jar", "enumerator", "org.jruby.ext.enumerator.EnumeratorLibrary");
loadService.require("enumerator.jar");
addBuiltinIfAllowed("rational.jar", dummy);
loadService.require("rational.jar");
addBuiltinIfAllowed("complex.jar", dummy);
loadService.require("complex.jar");

if(RubyInstanceConfig.NATIVE_NET_PROTOCOL) {
addLazyBuiltin("net/protocol.rb", "net/protocol", "org.jruby.ext.net.protocol.NetProtocolBufferedIOLibrary");
}
40 changes: 0 additions & 40 deletions core/src/main/java/org/jruby/ast/ArgsNoArgNode.java

This file was deleted.

40 changes: 0 additions & 40 deletions core/src/main/java/org/jruby/ast/ArgsPreOneArgNode.java

This file was deleted.

40 changes: 0 additions & 40 deletions core/src/main/java/org/jruby/ast/ArgsPreTwoArgNode.java

This file was deleted.

8 changes: 0 additions & 8 deletions core/src/main/java/org/jruby/ast/ArrayNode.java
Original file line number Diff line number Diff line change
@@ -66,12 +66,4 @@ public NodeType getNodeType() {
public <T> T accept(NodeVisitor<T> iVisitor) {
return iVisitor.visitArrayNode(this);
}

public void setLightweight(boolean lightweight) {
this.lightweight = lightweight;
}

public boolean isLightweight() {
return lightweight;
}
}
65 changes: 3 additions & 62 deletions core/src/main/java/org/jruby/ast/AttrAssignNode.java
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ public AttrAssignNode(ISourcePosition position, Node receiverNode, String name,

this.receiverNode = receiverNode;
this.name = name;
setArgsInternal(argsNode);
this.argsNode = argsNode;
}

public NodeType getNodeType() {
@@ -95,74 +95,15 @@ public Node getArgsNode() {
return argsNode;
}


protected Node newAttrAssignNode(ArrayNode argsNode) {
int size = argsNode.size();

switch (size) {
case 1:
return new AttrAssignOneArgNode(getPosition(), receiverNode, name, argsNode);
case 2:
return new AttrAssignTwoArgNode(getPosition(), receiverNode, name, argsNode);
case 3:
return new AttrAssignThreeArgNode(getPosition(), receiverNode, name, argsNode);
default:
return new AttrAssignNode(getPosition(), receiverNode, name, argsNode);
}
}

protected Node newMutatedAttrAssignNode(ArrayNode argsNode) {
int size = argsNode.size();

switch (size) {
case 1:
if (!(this instanceof AttrAssignOneArgNode)) {
return new AttrAssignOneArgNode(getPosition(), receiverNode, name, argsNode);
} else {
return this;
}
case 2:
if (!(this instanceof AttrAssignTwoArgNode)) {
return new AttrAssignTwoArgNode(getPosition(), receiverNode, name, argsNode);
} else {
return this;
}
case 3:
if (!(this instanceof AttrAssignThreeArgNode)) {
return new AttrAssignThreeArgNode(getPosition(), receiverNode, name, argsNode);
} else {
return this;
}
default:
return new AttrAssignNode(getPosition(), receiverNode, name, argsNode);
}
}

/**
* Set the argsNode
*
* @param argsNode set the arguments for this node.
*/
public Node setArgsNode(Node argsNode) {
// Empirical Observations:
// null -> Some arity
// argsNode == this.argsNode then check for arity changes
// newline(splatnode) -> argspushnode
if (this.argsNode == null && argsNode instanceof ArrayNode) {
return newAttrAssignNode((ArrayNode) argsNode);
} else if (this.argsNode == argsNode) {
return newMutatedAttrAssignNode((ArrayNode)argsNode);
}

setArgsInternal(argsNode);

return this;
}

private void setArgsInternal(Node argsNode) {
this.argsNode = argsNode;
if (argsNode instanceof ArrayNode) ((ArrayNode)argsNode).setLightweight(true);

return this;
}

public List<Node> childNodes() {
29 changes: 0 additions & 29 deletions core/src/main/java/org/jruby/ast/AttrAssignOneArgNode.java

This file was deleted.

33 changes: 0 additions & 33 deletions core/src/main/java/org/jruby/ast/AttrAssignThreeArgNode.java

This file was deleted.

31 changes: 0 additions & 31 deletions core/src/main/java/org/jruby/ast/AttrAssignTwoArgNode.java

This file was deleted.

8 changes: 2 additions & 6 deletions core/src/main/java/org/jruby/ast/CallNode.java
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public CallNode(ISourcePosition position, Node receiverNode, String name, Node a

this.name = name;
this.receiverNode = receiverNode;
setArgsNode(argsNode);
this.argsNode = argsNode;
this.iterNode = iterNode;
}

@@ -96,11 +96,7 @@ public Node getArgsNode() {
*/
public Node setArgsNode(Node argsNode) {
this.argsNode = argsNode;
// If we have more than one arg, make sure the array created to contain them is not ObjectSpaced
if (argsNode instanceof ArrayNode) {
((ArrayNode)argsNode).setLightweight(true);
}


return argsNode;
}

11 changes: 3 additions & 8 deletions core/src/main/java/org/jruby/ast/FCallNode.java
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public FCallNode(ISourcePosition position, String name) {
public FCallNode(ISourcePosition position, String name, Node argsNode, Node iterNode) {
super(position);
this.name = name;
setArgsNode(argsNode);
this.argsNode = argsNode;
this.iterNode = iterNode;
}

@@ -89,16 +89,11 @@ public Node getArgsNode() {
}

/**
* Set the argsNode. This is for re-writer and general interpretation.
*
* @param argsNode set the arguments for this node.
* Set the argsNode. Changes to parser means fcall is made before actual
* args are associated with fcall so we need a setter.
*/
public Node setArgsNode(Node argsNode) {
this.argsNode = argsNode;
// If we have more than one arg, make sure the array created to contain them is not ObjectSpaced
if (argsNode instanceof ArrayNode) {
((ArrayNode)argsNode).setLightweight(true);
}

return argsNode;
}
3 changes: 0 additions & 3 deletions core/src/main/java/org/jruby/ast/OpElementAsgnNode.java
Original file line number Diff line number Diff line change
@@ -59,9 +59,6 @@ public OpElementAsgnNode(ISourcePosition position, Node receiverNode, String ope

this.receiverNode = receiverNode;
this.argsNode = argsNode;
if (argsNode instanceof ArrayNode) {
((ArrayNode)argsNode).setLightweight(true);
}
this.valueNode = valueNode;
this.operatorName = operatorName;
}
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ast/RescueBodyNode.java
Original file line number Diff line number Diff line change
@@ -50,10 +50,6 @@ public RescueBodyNode(ISourcePosition position, Node exceptionNodes, Node bodyNo
assert bodyNode != null : "bodyNode is not null";

this.exceptionNodes = exceptionNodes;
if (exceptionNodes instanceof ArrayNode) {
// array created for rescue args doesn't need to be in ObjectSpace.
((ArrayNode)exceptionNodes).setLightweight(true);
}
this.bodyNode = bodyNode;
this.optRescueNode = optRescueNode;
}
3 changes: 0 additions & 3 deletions core/src/main/java/org/jruby/ast/SuperNode.java
Original file line number Diff line number Diff line change
@@ -50,9 +50,6 @@ public SuperNode(ISourcePosition position, Node argsNode, Node iterNode) {
super(position);
this.argsNode = argsNode;
this.iterNode = iterNode;
if (argsNode instanceof ArrayNode) {
((ArrayNode)argsNode).setLightweight(true);
}
}

public NodeType getNodeType() {
9 changes: 3 additions & 6 deletions core/src/main/java/org/jruby/ast/WhenNode.java
Original file line number Diff line number Diff line change
@@ -45,15 +45,12 @@ public class WhenNode extends Node {

public WhenNode(ISourcePosition position, Node expressionNodes, Node bodyNode, Node nextCase) {
super(position);
this.expressionNodes = expressionNodes;
if (expressionNodes instanceof ArrayNode) {
((ArrayNode)expressionNodes).setLightweight(true);
}

assert bodyNode != null : "bodyNode is not null";

this.expressionNodes = expressionNodes;
this.bodyNode = bodyNode;
this.nextCase = nextCase;

assert bodyNode != null : "bodyNode is not null";
}

public NodeType getNodeType() {
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ast/YieldNode.java
Original file line number Diff line number Diff line change
@@ -58,10 +58,6 @@ public YieldNode(ISourcePosition position, Node argsNode, boolean expandedArgume
//assert argsNode != null : "argsNode is not null";

this.argsNode = argsNode;
// If we have more than one argument, then make sure the array is not ObjectSpaced.
if (argsNode instanceof ArrayNode) {
((ArrayNode)argsNode).setLightweight(true);
}
this.expandedArguments = expandedArguments;
}

15 changes: 4 additions & 11 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -558,8 +558,6 @@ protected Variable getValueInTemporaryVariable(IRScope s, Operand val) {

// Return the last argument in the list -- AttrAssign needs it
protected Operand buildCallArgs(List<Operand> argsList, Node args, IRScope s) {
// unwrap newline nodes to get their actual type
args = skipOverNewlines(s, args);
switch (args.getNodeType()) {
case ARGSCATNODE: {
ArgsCatNode argsCatNode = (ArgsCatNode)args;
@@ -581,15 +579,10 @@ protected Operand buildCallArgs(List<Operand> argsList, Node args, IRScope s) {
}
case ARRAYNODE: {
ArrayNode arrayNode = (ArrayNode)args;
if (arrayNode.isLightweight()) {
List<Node> children = arrayNode.childNodes();
List<Node> children = arrayNode.childNodes();
// explode array, it's an internal "args" array
for (Node n: children) {
argsList.add(build(n, s));
}
} else {
// use array as-is, it's a literal array
argsList.add(build(arrayNode, s));
for (Node n: children) {
argsList.add(build(n, s));
}
break;
}
@@ -599,7 +592,7 @@ protected Operand buildCallArgs(List<Operand> argsList, Node args, IRScope s) {
break;
}
default: {
throw new NotCompilableException("Use buildRoot(); Root node at: " + args.getPosition());
throw new NotCompilableException("Invalid node for callArgs: " + args.getClass().getSimpleName() + ":" + args.getPosition());
}
}

47 changes: 4 additions & 43 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -556,8 +556,8 @@ protected Node makeNullNil(Node node) {
private Node cond0(Node node) {
checkAssignmentInCondition(node);

Node leftNode = null;
Node rightNode = null;
Node leftNode;
Node rightNode;

// FIXME: DSTR,EVSTR,STR: warning "string literal in condition"
switch(node.getNodeType()) {
@@ -771,20 +771,7 @@ public Node new_opElementAsgnNode(Node receiverNode, String operatorName, Node a
}

public Node new_attrassign(ISourcePosition position, Node receiver, String name, Node args) {
if (!(args instanceof ArrayNode)) return new AttrAssignNode(position, receiver, name, args);

ArrayNode argsNode = (ArrayNode) args;

switch (argsNode.size()) {
case 1:
return new AttrAssignOneArgNode(position, receiver, name, argsNode);
case 2:
return new AttrAssignTwoArgNode(position, receiver, name, argsNode);
case 3:
return new AttrAssignThreeArgNode(position, receiver, name, argsNode);
default:
return new AttrAssignNode(position, receiver, name, argsNode);
}
return new AttrAssignNode(position, receiver, name, args);
}

private boolean isNumericOperator(String name) {
@@ -1064,27 +1051,9 @@ private Node checkForNilNode(Node node, ISourcePosition defaultPosition) {
return (node == null) ? new NilNode(defaultPosition) : node;
}

public Node new_args(ISourcePosition position, ListNode pre, ListNode optional, RestArgNode rest,
ListNode post, BlockArgNode block) {
// Zero-Argument declaration
if (optional == null && rest == null && post == null && block == null) {
if (pre == null || pre.size() == 0) return new ArgsNoArgNode(position);
if (pre.size() == 1 && !hasAssignableArgs(pre)) return new ArgsPreOneArgNode(position, pre);
if (pre.size() == 2 && !hasAssignableArgs(pre)) return new ArgsPreTwoArgNode(position, pre);
}
return new ArgsNode(position, pre, optional, rest, post, block);
}

public Node new_args(ISourcePosition position, ListNode pre, ListNode optional, RestArgNode rest,
ListNode post, ArgsTailHolder tail) {
if (tail == null) return new_args(position, pre, optional, rest, post, (BlockArgNode) null);

// Zero-Argument declaration
if (optional == null && rest == null && post == null && !tail.hasKeywordArgs() && tail.getBlockArg() == null) {
if (pre == null || pre.size() == 0) return new ArgsNoArgNode(position);
if (pre.size() == 1 && !hasAssignableArgs(pre)) return new ArgsPreOneArgNode(position, pre);
if (pre.size() == 2 && !hasAssignableArgs(pre)) return new ArgsPreTwoArgNode(position, pre);
}
if (tail == null) return new ArgsNode(position, pre, optional, rest, post, (BlockArgNode) null);

return new ArgsNode(position, pre, optional, rest, post,
tail.getKeywordArgs(), tail.getKeywordRestArgNode(), tail.getBlockArg());
@@ -1102,14 +1071,6 @@ public ArgsTailHolder new_args_tail(ISourcePosition position, ListNode keywordAr
KeywordRestArgNode keywordRestArg = new KeywordRestArgNode(position, restKwargsName, slot);

return new ArgsTailHolder(position, keywordArg, keywordRestArg, blockArg);
}

private boolean hasAssignableArgs(ListNode list) {
for (int i = 0; i < list.size(); i++) {
Node node = list.get(i);
if (node instanceof AssignableNode) return true;
}
return false;
}

public Node newAlias(ISourcePosition position, Node newNode, Node oldNode) {
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -1242,14 +1242,14 @@ opt_block_arg : ',' block_arg {
| none_block_pass

// [!null]
args : arg_value {
args : arg_value { // ArrayNode
ISourcePosition pos = $1 == null ? lexer.getPosition() : $1.getPosition();
$$ = support.newArrayNode(pos, $1);
}
| tSTAR arg_value {
| tSTAR arg_value { // SplatNode
$$ = support.newSplatNode(support.getPosition($2), $2);
}
| args ',' arg_value {
| args ',' arg_value { // ArgsCatNode, SplatNode, ArrayNode
Node node = support.splat_array($1);

if (node != null) {
@@ -1258,7 +1258,7 @@ args : arg_value {
$$ = support.arg_append($1, $3);
}
}
| args ',' tSTAR arg_value {
| args ',' tSTAR arg_value { // ArgsCatNode, SplatNode, ArrayNode
Node node = null;

// FIXME: lose syntactical elements here (and others like this)
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Original file line number Diff line number Diff line change
@@ -14,13 +14,16 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.TruffleBridge;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.TopLevelRaiseHandler;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.methods.SetFrameVisibilityNode;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
@@ -170,16 +173,18 @@ public Object execute(final TranslatorDriver.ParserContext parserContext, final
source = Source.fromBytes(bytes, inputFile, new BytesDecoder.UTF8BytesDecoder());
}

return truffleContext.execute(truffleContext, source, UTF8Encoding.INSTANCE, parserContext, self, parentFrame, null, new NodeWrapper() {
truffleContext.load(source, null, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
RubyContext context = node.getContext();
SourceSection sourceSection = node.getSourceSection();
return SequenceNode.sequence(context, sourceSection,
new SetTopLevelBindingNode(context, sourceSection),
new TopLevelRaiseHandler(context, sourceSection, node));
new TopLevelRaiseHandler(context, sourceSection,
SetFrameVisibilityNode.PRIVATE_VISIBILITY_WRAPPER.wrap(node)));
}
});
return truffleContext.getCoreLibrary().getNilObject();
}

@Override
Original file line number Diff line number Diff line change
@@ -12,13 +12,22 @@
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.translator.NodeWrapper;

public class SetFrameVisibilityNode extends RubyNode {

public static final NodeWrapper PRIVATE_VISIBILITY_WRAPPER = new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new SetFrameVisibilityNode(node.getContext(), node.getSourceSection(), node, Visibility.PRIVATE);
}
};

@Child protected RubyNode body;

final Visibility visibility;
21 changes: 14 additions & 7 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -18,17 +18,20 @@
import java.util.concurrent.atomic.*;

import com.oracle.truffle.api.object.Shape;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.*;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;

import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.TruffleHooks;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.methods.SetFrameVisibilityNode;
import org.jruby.truffle.runtime.control.*;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyArray;
@@ -139,10 +142,6 @@ public static String checkClassVariableName(RubyContext context, String name, Ru
return name;
}

public void load(Source source, RubyNode currentNode) {
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
}

public void loadFile(String fileName, RubyNode currentNode) {
if (new File(fileName).isAbsolute()) {
loadFileAbsolute(fileName, currentNode);
@@ -161,9 +160,17 @@ private void loadFileAbsolute(String fileName, RubyNode currentNode) {
}

// Assume UTF-8 for the moment

final Source source = Source.fromBytes(bytes, fileName, new BytesDecoder.UTF8BytesDecoder());
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);

load(source, currentNode, SetFrameVisibilityNode.PRIVATE_VISIBILITY_WRAPPER);
}

public void load(Source source, RubyNode currentNode) {
load(source, currentNode, NodeWrapper.IDENTITY);
}

public void load(Source source, RubyNode currentNode, NodeWrapper nodeWrapper) {
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode, nodeWrapper);
}

public RubySymbol.SymbolTable getSymbolTable() {
Original file line number Diff line number Diff line change
@@ -161,11 +161,6 @@ public RubyRootNode parse(RubyNode currentNode, RubyContext context, Source sour
truffleNode = rootNode.getBodyNode().accept(translator);
}

// Set default top-level visibility
if (parserContext == ParserContext.TOP_LEVEL) {
truffleNode = new SetFrameVisibilityNode(context, truffleNode.getSourceSection(), truffleNode, Visibility.PUBLIC);
}

// Load flip-flop states

if (environment.getFlipFlopStates().size() > 0) {

0 comments on commit a5b1f0a

Please sign in to comment.