-
-
Save headius/ba549ca46a091c5a844319f105e7b187 to your computer and use it in GitHub Desktop.
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
diff --git a/core/src/main/java/org/jruby/Ruby.java b/core/src/main/java/org/jruby/Ruby.java | |
index ace5528c2e..33c6b7a335 100644 | |
--- a/core/src/main/java/org/jruby/Ruby.java | |
+++ b/core/src/main/java/org/jruby/Ruby.java | |
@@ -40,6 +40,7 @@ | |
package org.jruby; | |
+import org.jcodings.specific.USASCIIEncoding; | |
import org.jcodings.specific.UTF8Encoding; | |
import org.jruby.anno.TypePopulator; | |
import org.jruby.ast.ArrayNode; | |
@@ -696,7 +697,7 @@ public final class Ruby implements Constantizable { | |
// we do pre and post load outside the "body" versions to pre-prepare | |
// and pre-push the dynamic scope we need for lastline | |
- Helpers.preLoad(context, ((RootNode) scriptNode).getStaticScope().getVariables()); | |
+ Helpers.preLoad(context, ((RootNode) scriptNode).getStaticScope().getByteVariables()); | |
try { | |
if (script != null) { | |
@@ -716,17 +717,17 @@ public final class Ruby implements Constantizable { | |
private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean processLineEndings, boolean split) { | |
ISourcePosition pos = oldRoot.getPosition(); | |
BlockNode newBody = new BlockNode(pos); | |
- newBody.add(new GlobalAsgnNode(pos, "$/", new StrNode(pos, ((RubyString) globalVariables.get("$/")).getByteList()))); | |
+ newBody.add(new GlobalAsgnNode(pos, "$/", USASCIIEncoding.INSTANCE, new StrNode(pos, ((RubyString) globalVariables.get("$/")).getByteList()))); | |
- if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", new GlobalVarNode(pos, "$/"))); | |
+ if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", USASCIIEncoding.INSTANCE, new GlobalVarNode(pos, "$/", USASCIIEncoding.INSTANCE))); | |
- GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, "$_"); | |
+ GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, "$_", USASCIIEncoding.INSTANCE); | |
BlockNode whileBody = new BlockNode(pos); | |
- newBody.add(new WhileNode(pos, new VCallNode(pos, "gets"), whileBody)); | |
+ newBody.add(new WhileNode(pos, new VCallNode(pos, "gets", USASCIIEncoding.INSTANCE), whileBody)); | |
- if (processLineEndings) whileBody.add(new CallNode(pos, dollarUnderscore, "chop!", null, null)); | |
- if (split) whileBody.add(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null))); | |
+ if (processLineEndings) whileBody.add(new CallNode(pos, dollarUnderscore, "chop!", USASCIIEncoding.INSTANCE, null, null)); | |
+ if (split) whileBody.add(new GlobalAsgnNode(pos, "$F", USASCIIEncoding.INSTANCE, new CallNode(pos, dollarUnderscore, "split", USASCIIEncoding.INSTANCE, null, null))); | |
if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts | |
whileBody.addAll(((BlockNode) oldRoot.getBodyNode())); | |
@@ -734,7 +735,7 @@ public final class Ruby implements Constantizable { | |
whileBody.add(oldRoot.getBodyNode()); | |
} | |
- if (printing) whileBody.add(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null)); | |
+ if (printing) whileBody.add(new FCallNode(pos, "puts", USASCIIEncoding.INSTANCE, new ArrayNode(pos, dollarUnderscore), null)); | |
return new RootNode(pos, oldRoot.getScope(), newBody, oldRoot.getFile()); | |
} | |
@@ -4247,7 +4248,8 @@ public final class Ruby implements Constantizable { | |
} | |
if ( message == null ) message = STOPIERATION_BACKTRACE_MESSAGE; | |
RubyException ex = RubyStopIteration.newInstance(context, result, message); | |
- return RaiseException.from(ex, disabledBacktrace()); | |
+ ex.set_backtrace(disabledBacktrace()); | |
+ return ex.toThrowable(); | |
} | |
@Deprecated | |
diff --git a/core/src/main/java/org/jruby/RubyArray.java b/core/src/main/java/org/jruby/RubyArray.java | |
index b17732afb2..bcaac3ae68 100644 | |
--- a/core/src/main/java/org/jruby/RubyArray.java | |
+++ b/core/src/main/java/org/jruby/RubyArray.java | |
@@ -4565,7 +4565,7 @@ rational_loop: | |
if (result instanceof RubyInteger) { | |
result = ((RubyInteger) result).op_plus(context, value); | |
} else if (result instanceof RubyRational) { | |
- result = ((RubyRational) result).op_add(context, value); | |
+ result = ((RubyRational) result).op_plus(context, value); | |
} else { | |
throw runtime.newTypeError("BUG: unexpected type in rational part of Array#sum"); | |
} | |
diff --git a/core/src/main/java/org/jruby/RubyBasicObject.java b/core/src/main/java/org/jruby/RubyBasicObject.java | |
index 59cfb192a5..c503b6c9e9 100644 | |
--- a/core/src/main/java/org/jruby/RubyBasicObject.java | |
+++ b/core/src/main/java/org/jruby/RubyBasicObject.java | |
@@ -1097,14 +1097,6 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co | |
return getInternalVariable("__wrap_struct__"); | |
} | |
- // Equivalent of Data_Get_Struct | |
- // This will first check that the object in question is actually a T_DATA equivalent. | |
- @Override | |
- public synchronized Object dataGetStructChecked() { | |
- TypeConverter.checkData(this); | |
- return getInternalVariable("__wrap_struct__"); | |
- } | |
- | |
/** rb_obj_id | |
* | |
* Return the internal id of an object. | |
@@ -3223,6 +3215,13 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co | |
public final void setNativeHandle(Object value) { | |
} | |
+ @Override | |
+ @Deprecated | |
+ public synchronized Object dataGetStructChecked() { | |
+ TypeConverter.checkData(this); | |
+ return getInternalVariable("__wrap_struct__"); | |
+ } | |
+ | |
@Deprecated | |
public static final int FL_USHIFT = 4; | |
@Deprecated | |
diff --git a/core/src/main/java/org/jruby/RubyBinding.java b/core/src/main/java/org/jruby/RubyBinding.java | |
index 6f214fbce4..b2377705d6 100644 | |
--- a/core/src/main/java/org/jruby/RubyBinding.java | |
+++ b/core/src/main/java/org/jruby/RubyBinding.java | |
@@ -45,6 +45,7 @@ import org.jruby.runtime.ObjectAllocator; | |
import org.jruby.runtime.ThreadContext; | |
import org.jruby.runtime.Visibility; | |
import org.jruby.runtime.builtin.IRubyObject; | |
+import org.jruby.util.ByteList; | |
import org.jruby.util.IdUtil; | |
/** | |
@@ -142,28 +143,44 @@ public class RubyBinding extends RubyObject { | |
@JRubyMethod(name = "local_variable_defined?") | |
public IRubyObject local_variable_defined_p(ThreadContext context, IRubyObject symbol) { | |
- return context.runtime.newBoolean(binding.getEvalScope(context.runtime).getStaticScope().isDefined(symbol.asJavaString()) != -1); | |
+ ByteList name; | |
+ if (symbol instanceof RubySymbol) { | |
+ name = ((RubySymbol) symbol).getBytes(); | |
+ } else { | |
+ name = symbol.convertToString().getByteList(); | |
+ } | |
+ return context.runtime.newBoolean(binding.getEvalScope(context.runtime).getStaticScope().isDefined(name) != -1); | |
} | |
@JRubyMethod | |
public IRubyObject local_variable_get(ThreadContext context, IRubyObject symbol) { | |
- String name = symbol.asJavaString().intern(); | |
+ ByteList name; | |
+ if (symbol instanceof RubySymbol) { | |
+ name = ((RubySymbol) symbol).getBytes(); | |
+ } else { | |
+ name = symbol.convertToString().getByteList(); | |
+ } | |
DynamicScope evalScope = binding.getEvalScope(context.runtime); | |
int slot = evalScope.getStaticScope().isDefined(name); | |
- if (slot == -1) throw context.runtime.newNameError("local variable `" + name + "' not defined for " + inspect(), name); | |
+ if (slot == -1) throw context.runtime.newNameError("local variable `" + symbol + "' not defined for " + inspect(), symbol.toString()); | |
return evalScope.getValue(slot & 0xffff, slot >> 16); | |
} | |
@JRubyMethod | |
public IRubyObject local_variable_set(ThreadContext context, IRubyObject symbol, IRubyObject value) { | |
- String name = symbol.asJavaString().intern(); | |
+ ByteList name; | |
+ if (symbol instanceof RubySymbol) { | |
+ name = ((RubySymbol) symbol).getBytes(); | |
+ } else { | |
+ name = symbol.convertToString().getByteList(); | |
+ } | |
DynamicScope evalScope = binding.getEvalScope(context.runtime); | |
int slot = evalScope.getStaticScope().isDefined(name); | |
if (slot == -1) { // Yay! New variable associated with this binding | |
- slot = evalScope.getStaticScope().addVariable(name.intern()); | |
+ slot = evalScope.getStaticScope().addVariable(name); | |
evalScope.growIfNeeded(); | |
} | |
@@ -173,12 +190,12 @@ public class RubyBinding extends RubyObject { | |
@JRubyMethod | |
public IRubyObject local_variables(ThreadContext context) { | |
final Ruby runtime = context.runtime; | |
- HashSet<String> encounteredLocalVariables = new HashSet<>(); | |
+ HashSet<ByteList> encounteredLocalVariables = new HashSet<>(); | |
RubyArray allLocalVariables = runtime.newArray(); | |
DynamicScope currentScope = binding.getEvalScope(context.runtime); | |
while (currentScope != null) { | |
- for (String name : currentScope.getStaticScope().getVariables()) { | |
+ for (ByteList name : currentScope.getStaticScope().getByteVariables()) { | |
if (IdUtil.isLocal(name) && !encounteredLocalVariables.contains(name)) { | |
allLocalVariables.push(runtime.newSymbol(name)); | |
encounteredLocalVariables.add(name); | |
diff --git a/core/src/main/java/org/jruby/ast/CallNode.java b/core/src/main/java/org/jruby/ast/CallNode.java | |
index 82d03db4a9..58eabf3125 100644 | |
--- a/core/src/main/java/org/jruby/ast/CallNode.java | |
+++ b/core/src/main/java/org/jruby/ast/CallNode.java | |
@@ -35,6 +35,8 @@ package org.jruby.ast; | |
import java.util.List; | |
+import org.jcodings.Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
@@ -51,11 +53,17 @@ public class CallNode extends Node implements INameNode, IArgumentNode, BlockAcc | |
private ByteList name; | |
private final boolean isLazy; | |
+ @Deprecated | |
public CallNode(ISourcePosition position, Node receiverNode, String name, Node argsNode, | |
Node iterNode) { | |
this(position, receiverNode, name, argsNode, iterNode, false); | |
} | |
+ public CallNode(ISourcePosition position, Node receiverNode, String name, Encoding encoding, Node argsNode, | |
+ Node iterNode) { | |
+ this(position, receiverNode, RubyString.encodeBytelist(name, encoding), argsNode, iterNode, false); | |
+ } | |
+ | |
@Deprecated | |
public CallNode(ISourcePosition position, Node receiverNode, String name, Node argsNode, | |
Node iterNode, boolean isLazy) { | |
diff --git a/core/src/main/java/org/jruby/ast/Colon3Node.java b/core/src/main/java/org/jruby/ast/Colon3Node.java | |
index f114ea8aea..3c015f539f 100644 | |
--- a/core/src/main/java/org/jruby/ast/Colon3Node.java | |
+++ b/core/src/main/java/org/jruby/ast/Colon3Node.java | |
@@ -34,6 +34,8 @@ package org.jruby.ast; | |
import java.util.List; | |
+import org.jcodings.specific.UTF8Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
@@ -90,6 +92,6 @@ public class Colon3Node extends Node implements INameNode { | |
} | |
public void setName(String name) { | |
- this.name = StringSupport.stringAsByteList(name); | |
+ this.name = RubyString.encodeBytelist(name, UTF8Encoding.INSTANCE); | |
} | |
} | |
diff --git a/core/src/main/java/org/jruby/ast/FCallNode.java b/core/src/main/java/org/jruby/ast/FCallNode.java | |
index 90977a94e4..1b915f86a0 100644 | |
--- a/core/src/main/java/org/jruby/ast/FCallNode.java | |
+++ b/core/src/main/java/org/jruby/ast/FCallNode.java | |
@@ -35,6 +35,8 @@ package org.jruby.ast; | |
import java.util.List; | |
+import org.jcodings.Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
@@ -63,6 +65,10 @@ public class FCallNode extends Node implements INameNode, IArgumentNode, BlockAc | |
this(position, StringSupport.stringAsByteList(name), argsNode, iterNode); | |
} | |
+ public FCallNode(ISourcePosition position, String name, Encoding encoding, Node argsNode, Node iterNode) { | |
+ this(position, RubyString.encodeBytelist(name, encoding), argsNode, iterNode); | |
+ } | |
+ | |
public FCallNode(ISourcePosition position, ByteList name, Node argsNode, Node iterNode) { | |
super(position, argsNode != null && argsNode.containsVariableAssignment() || iterNode != null && iterNode.containsVariableAssignment()); | |
this.name = name; | |
diff --git a/core/src/main/java/org/jruby/ast/GlobalAsgnNode.java b/core/src/main/java/org/jruby/ast/GlobalAsgnNode.java | |
index 455bd63c88..58a9a5e79f 100644 | |
--- a/core/src/main/java/org/jruby/ast/GlobalAsgnNode.java | |
+++ b/core/src/main/java/org/jruby/ast/GlobalAsgnNode.java | |
@@ -36,6 +36,8 @@ package org.jruby.ast; | |
import java.util.List; | |
+import org.jcodings.Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
@@ -54,6 +56,10 @@ public class GlobalAsgnNode extends AssignableNode implements INameNode { | |
this.name = name; | |
} | |
+ public GlobalAsgnNode(ISourcePosition position, String name, Encoding enc, Node valueNode) { | |
+ this(position, RubyString.encodeBytelist(name, enc), valueNode); | |
+ } | |
+ | |
@Deprecated | |
public GlobalAsgnNode(ISourcePosition position, String name, Node valueNode) { | |
this(position, StringSupport.stringAsByteList(name), valueNode); | |
diff --git a/core/src/main/java/org/jruby/ast/GlobalVarNode.java b/core/src/main/java/org/jruby/ast/GlobalVarNode.java | |
index 4fa7437fb9..34a2faa859 100644 | |
--- a/core/src/main/java/org/jruby/ast/GlobalVarNode.java | |
+++ b/core/src/main/java/org/jruby/ast/GlobalVarNode.java | |
@@ -34,6 +34,8 @@ package org.jruby.ast; | |
import java.util.List; | |
+import org.jcodings.Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
@@ -51,6 +53,10 @@ public class GlobalVarNode extends Node implements INameNode, SideEffectFree { | |
this.name = name; | |
} | |
+ public GlobalVarNode(ISourcePosition position, String name, Encoding enc) { | |
+ this(position, RubyString.encodeBytelist(name, enc)); | |
+ } | |
+ | |
@Deprecated | |
public GlobalVarNode(ISourcePosition position, String name) { | |
this(position, StringSupport.stringAsByteList(name)); | |
diff --git a/core/src/main/java/org/jruby/ast/RestArgNode.java b/core/src/main/java/org/jruby/ast/RestArgNode.java | |
index c7977fb122..ebac30b055 100644 | |
--- a/core/src/main/java/org/jruby/ast/RestArgNode.java | |
+++ b/core/src/main/java/org/jruby/ast/RestArgNode.java | |
@@ -32,18 +32,24 @@ package org.jruby.ast; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
+import org.jruby.util.ByteList; | |
/* | |
* The rest argument for a method (def foo(a, *b, c)). | |
*/ | |
public class RestArgNode extends ArgumentNode implements INameNode { | |
+ @Deprecated | |
public RestArgNode(ISourcePosition position, String name, int index) { | |
super(position, name, index); | |
} | |
+ public RestArgNode(ISourcePosition position, ByteList name, int index) { | |
+ super(position, name, index); | |
+ } | |
+ | |
// 1.9 only - lvar assign logic returns an Argument node | |
public RestArgNode(ArgumentNode argNode) { | |
- this(argNode.getPosition(), argNode.getName(), argNode.getIndex()); | |
+ this(argNode.getPosition(), argNode.getByteName(), argNode.getIndex()); | |
} | |
@Override | |
diff --git a/core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java b/core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java | |
index e09b2f28ec..1d95fc8370 100644 | |
--- a/core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java | |
+++ b/core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java | |
@@ -30,15 +30,21 @@ | |
package org.jruby.ast; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
+import org.jruby.util.ByteList; | |
/** | |
* a bare '*' or nothing. Name is "" if it is '*' and null if it is nothing. | |
*/ | |
public class UnnamedRestArgNode extends RestArgNode { | |
+ @Deprecated | |
public UnnamedRestArgNode(ISourcePosition position, String name, int index) { | |
super(position, name, index); | |
} | |
+ public UnnamedRestArgNode(ISourcePosition position, ByteList name, int index) { | |
+ super(position, name, index); | |
+ } | |
+ | |
public boolean isStar() { | |
return getByteName() != null; | |
} | |
diff --git a/core/src/main/java/org/jruby/ast/VCallNode.java b/core/src/main/java/org/jruby/ast/VCallNode.java | |
index 03f9cb5f21..8564b6356f 100644 | |
--- a/core/src/main/java/org/jruby/ast/VCallNode.java | |
+++ b/core/src/main/java/org/jruby/ast/VCallNode.java | |
@@ -35,6 +35,8 @@ package org.jruby.ast; | |
import java.util.List; | |
+import org.jcodings.Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.types.INameNode; | |
import org.jruby.ast.visitor.NodeVisitor; | |
import org.jruby.lexer.yacc.ISourcePosition; | |
@@ -55,6 +57,10 @@ public class VCallNode extends Node implements INameNode { | |
setNewline(); | |
} | |
+ public VCallNode(ISourcePosition position, String name, Encoding enc) { | |
+ this(position, RubyString.encodeBytelist(name, enc)); | |
+ } | |
+ | |
@Deprecated | |
public VCallNode(ISourcePosition position, String name) { | |
this(position, StringSupport.stringAsByteList(name)); | |
diff --git a/core/src/main/java/org/jruby/ast/visitor/AbstractNodeVisitor.java b/core/src/main/java/org/jruby/ast/visitor/AbstractNodeVisitor.java | |
index 72f89a05e0..21016b8a3f 100644 | |
--- a/core/src/main/java/org/jruby/ast/visitor/AbstractNodeVisitor.java | |
+++ b/core/src/main/java/org/jruby/ast/visitor/AbstractNodeVisitor.java | |
@@ -145,6 +145,7 @@ public abstract class AbstractNodeVisitor<T> implements NodeVisitor<T> { | |
} | |
@Override | |
+ @Deprecated | |
public T visitClassVarDeclNode(ClassVarDeclNode node) { | |
return defaultVisit(node); | |
} | |
diff --git a/core/src/main/java/org/jruby/ast/visitor/NodeVisitor.java b/core/src/main/java/org/jruby/ast/visitor/NodeVisitor.java | |
index c37294d01b..d4c2aeea72 100644 | |
--- a/core/src/main/java/org/jruby/ast/visitor/NodeVisitor.java | |
+++ b/core/src/main/java/org/jruby/ast/visitor/NodeVisitor.java | |
@@ -59,6 +59,7 @@ public interface NodeVisitor<T> { | |
T visitBreakNode(BreakNode iVisited); | |
T visitConstDeclNode(ConstDeclNode iVisited); | |
T visitClassVarAsgnNode(ClassVarAsgnNode iVisited); | |
+ @Deprecated | |
T visitClassVarDeclNode(ClassVarDeclNode iVisited); | |
T visitClassVarNode(ClassVarNode iVisited); | |
T visitCallNode(CallNode iVisited); | |
diff --git a/core/src/main/java/org/jruby/ir/IRClosure.java b/core/src/main/java/org/jruby/ir/IRClosure.java | |
index a96af6a070..5b13cc21b0 100644 | |
--- a/core/src/main/java/org/jruby/ir/IRClosure.java | |
+++ b/core/src/main/java/org/jruby/ir/IRClosure.java | |
@@ -4,6 +4,8 @@ import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.Callable; | |
+import org.jcodings.specific.UTF8Encoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.DefNode; | |
import org.jruby.ast.IterNode; | |
import org.jruby.ir.instructions.*; | |
@@ -244,7 +246,7 @@ public class IRClosure extends IRScope { | |
public LocalVariable getNewLocalVariable(String name, int depth) { | |
if (depth == 0 && !(this instanceof IRFor)) { | |
- LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(name)); | |
+ LocalVariable lvar = new ClosureLocalVariable(name, 0, getStaticScope().addVariableThisScope(RubyString.encodeBytelist(name, UTF8Encoding.INSTANCE)); | |
localVars.put(name, lvar); | |
return lvar; | |
} else { | |
diff --git a/core/src/main/java/org/jruby/ir/IRScope.java b/core/src/main/java/org/jruby/ir/IRScope.java | |
index f3aa31d4d2..b8d106a0fd 100644 | |
--- a/core/src/main/java/org/jruby/ir/IRScope.java | |
+++ b/core/src/main/java/org/jruby/ir/IRScope.java | |
@@ -1,8 +1,12 @@ | |
package org.jruby.ir; | |
+import org.jcodings.specific.USASCIIEncoding; | |
+import org.jcodings.specific.UTF8Encoding; | |
import org.jruby.ParseResult; | |
+import org.jruby.RubyEncoding; | |
import org.jruby.RubyInstanceConfig; | |
import org.jruby.RubyModule; | |
+import org.jruby.RubyString; | |
import org.jruby.ir.dataflow.analyses.LiveVariablesProblem; | |
import org.jruby.ir.dataflow.analyses.StoreLocalVarPlacementProblem; | |
import org.jruby.ir.dataflow.analyses.UnboxableOpsAnalysisProblem; | |
@@ -24,6 +28,7 @@ import java.util.concurrent.Callable; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import org.jruby.runtime.Helpers; | |
+import org.jruby.util.ByteList; | |
import org.jruby.util.log.Logger; | |
import org.jruby.util.log.LoggerFactory; | |
@@ -863,7 +868,7 @@ public abstract class IRScope implements ParseResult { | |
public LocalVariable getNewLocalVariable(String name, int scopeDepth) { | |
assert scopeDepth == 0: "Scope depth is non-zero for new-var request " + name + " in " + this; | |
- LocalVariable lvar = new LocalVariable(name, scopeDepth, getStaticScope().addVariable(name)); | |
+ LocalVariable lvar = new LocalVariable(name, scopeDepth, getStaticScope().addVariable(RubyString.encodeBytelist(name, UTF8Encoding.INSTANCE))); | |
localVars.put(name, lvar); | |
return lvar; | |
} | |
diff --git a/core/src/main/java/org/jruby/ir/instructions/BuildCompoundArrayInstr.java b/core/src/main/java/org/jruby/ir/instructions/BuildCompoundArrayInstr.java | |
index f6f17d30b0..561c4ba9f0 100644 | |
--- a/core/src/main/java/org/jruby/ir/instructions/BuildCompoundArrayInstr.java | |
+++ b/core/src/main/java/org/jruby/ir/instructions/BuildCompoundArrayInstr.java | |
@@ -58,7 +58,7 @@ public class BuildCompoundArrayInstr extends TwoOperandResultBaseInstr { | |
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { | |
IRubyObject v1 = (IRubyObject)getAppendingArg().retrieve(context, self, currScope, currDynScope, temp); | |
IRubyObject v2 = (IRubyObject)getAppendedArg().retrieve(context, self, currScope, currDynScope, temp); | |
- return isArgsPush ? Helpers.argsPush(context, (RubyArray) v1, v2) : Helpers.argsCat(context, v1, v2); | |
+ return isArgsPush ? Helpers.argsPush(v1, v2) : Helpers.argsCat(context, v1, v2); | |
} | |
@Override | |
diff --git a/core/src/main/java/org/jruby/ir/operands/UndefinedValue.java b/core/src/main/java/org/jruby/ir/operands/UndefinedValue.java | |
index 36f49f6c78..1b5aef38f0 100644 | |
--- a/core/src/main/java/org/jruby/ir/operands/UndefinedValue.java | |
+++ b/core/src/main/java/org/jruby/ir/operands/UndefinedValue.java | |
@@ -251,6 +251,7 @@ public class UndefinedValue extends Operand implements IRubyObject { | |
* | |
* @return | |
*/ | |
+ @Deprecated | |
public IRubyObject checkStringType19() { throw undefinedOperation(); } | |
/** | |
@@ -314,6 +315,7 @@ public class UndefinedValue extends Operand implements IRubyObject { | |
* @return the object wrapped. | |
*/ | |
public Object dataGetStruct() { throw undefinedOperation(); } | |
+ @Deprecated | |
public Object dataGetStructChecked() { throw undefinedOperation(); } | |
/** | |
diff --git a/core/src/main/java/org/jruby/parser/RubyParser.java b/core/src/main/java/org/jruby/parser/RubyParser.java | |
index 32507321b7..20cb341745 100644 | |
--- a/core/src/main/java/org/jruby/parser/RubyParser.java | |
+++ b/core/src/main/java/org/jruby/parser/RubyParser.java | |
@@ -34,6 +34,8 @@ package org.jruby.parser; | |
import java.io.IOException; | |
+import org.jcodings.specific.USASCIIEncoding; | |
+import org.jruby.RubyString; | |
import org.jruby.ast.ArgsNode; | |
import org.jruby.ast.ArgumentNode; | |
import org.jruby.ast.ArrayNode; | |
@@ -131,6 +133,7 @@ import static org.jruby.lexer.LexingCommon.EXPR_ENDFN; | |
import static org.jruby.lexer.LexingCommon.EXPR_ENDARG; | |
import static org.jruby.lexer.LexingCommon.EXPR_END; | |
import static org.jruby.lexer.LexingCommon.EXPR_LABEL; | |
+import static org.jruby.lexer.LexingCommon.USASCII_ENCODING; | |
import static org.jruby.parser.ParserSupport.value_expr; | |
@@ -4177,7 +4180,7 @@ states[399] = new ParserState() { | |
}; | |
states[400] = new ParserState() { | |
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { | |
- RestArgNode rest = new UnnamedRestArgNode(((ListNode)yyVals[-1+yyTop]).getPosition(), null, support.getCurrentScope().addVariable("*")); | |
+ RestArgNode rest = new UnnamedRestArgNode(((ListNode)yyVals[-1+yyTop]).getPosition(), (ByteList)null, support.getCurrentScope().addVariable(RubyString.encodeBytelist("*", USASCIIEncoding.INSTANCE))); | |
yyVal = support.new_args(((ListNode)yyVals[-1+yyTop]).getPosition(), ((ListNode)yyVals[-1+yyTop]), null, rest, null, (ArgsTailHolder) null); | |
return yyVal; | |
} | |
@@ -5483,7 +5486,7 @@ states[599] = new ParserState() { | |
}; | |
states[600] = new ParserState() { | |
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { | |
- yyVal = new UnnamedRestArgNode(lexer.getPosition(), "", support.getCurrentScope().addVariable("*")); | |
+ yyVal = new UnnamedRestArgNode(lexer.getPosition(), new ByteList("".getBytes(), USASCII_ENCODING), support.getCurrentScope().addVariable(new ByteList("*".getBytes(), USASCII_ENCODING))); | |
return yyVal; | |
} | |
}; | |
diff --git a/core/src/main/java/org/jruby/parser/StaticScopeFactory.java b/core/src/main/java/org/jruby/parser/StaticScopeFactory.java | |
index c00096706f..a7dfdfb500 100644 | |
--- a/core/src/main/java/org/jruby/parser/StaticScopeFactory.java | |
+++ b/core/src/main/java/org/jruby/parser/StaticScopeFactory.java | |
@@ -59,7 +59,7 @@ public class StaticScopeFactory { | |
} | |
@Deprecated | |
- public StaticScope newLocalScope(StaticScope parent, String[] names) { | |
+ public StaticScope newLocalScope(StaticScope parent, String[] names) { | |
return new StaticScope(StaticScope.Type.LOCAL, parent, StringSupport.stringsAsByteLists(names)); | |
} | |
diff --git a/core/src/main/java/org/jruby/runtime/DynamicScope.java b/core/src/main/java/org/jruby/runtime/DynamicScope.java | |
index 99ef2c1e23..2b826592c9 100644 | |
--- a/core/src/main/java/org/jruby/runtime/DynamicScope.java | |
+++ b/core/src/main/java/org/jruby/runtime/DynamicScope.java | |
@@ -28,9 +28,11 @@ | |
package org.jruby.runtime; | |
import org.jruby.EvalType; | |
+import org.jruby.RubyString; | |
import org.jruby.ir.JIT; | |
import org.jruby.parser.StaticScope; | |
import org.jruby.runtime.builtin.IRubyObject; | |
+import org.jruby.util.ByteList; | |
public abstract class DynamicScope implements Cloneable { | |
// Static scoping information for this scope | |
@@ -519,9 +521,9 @@ public abstract class DynamicScope implements Cloneable { | |
IRubyObject[] variableValues = getValues(); | |
if (size != 0) { | |
- String names[] = staticScope.getVariables(); | |
+ ByteList names[] = staticScope.getByteVariables(); | |
for (int i = 0; i < size-1; i++) { | |
- buf.append(names[i]).append("="); | |
+ buf.append(RubyString.byteListToString(names[i])).append("="); | |
if (variableValues[i] == null) { | |
buf.append("null"); | |
@@ -531,7 +533,7 @@ public abstract class DynamicScope implements Cloneable { | |
buf.append(","); | |
} | |
- buf.append(names[size-1]).append("="); | |
+ buf.append(RubyString.byteListToString(names[size-1])).append("="); | |
assert variableValues.length == names.length : "V: " + variableValues.length + | |
" != N: " + names.length + " for " + buf; | |
diff --git a/core/src/main/java/org/jruby/runtime/Helpers.java b/core/src/main/java/org/jruby/runtime/Helpers.java | |
index 047d7bf463..af2a9a8d8e 100644 | |
--- a/core/src/main/java/org/jruby/runtime/Helpers.java | |
+++ b/core/src/main/java/org/jruby/runtime/Helpers.java | |
@@ -1332,8 +1332,7 @@ public class Helpers { | |
return RubyString.newStringShared(context.runtime, value); | |
} | |
- @SuppressWarnings("deprecation") | |
- public static StaticScope preLoad(ThreadContext context, String[] varNames) { | |
+ public static StaticScope preLoad(ThreadContext context, ByteList[] varNames) { | |
StaticScope staticScope = context.runtime.getStaticScopeFactory().newLocalScope(null, varNames); | |
preLoadCommon(context, staticScope, false); | |
diff --git a/core/src/main/java/org/jruby/util/IdUtil.java b/core/src/main/java/org/jruby/util/IdUtil.java | |
index 2fbf9cc91e..c34fcdac66 100644 | |
--- a/core/src/main/java/org/jruby/util/IdUtil.java | |
+++ b/core/src/main/java/org/jruby/util/IdUtil.java | |
@@ -33,11 +33,15 @@ package org.jruby.util; | |
public final class IdUtil { | |
/** | |
* rb_is_const_id and is_const_id | |
- */ | |
+ */ | |
public static boolean isConstant(String id) { | |
return Character.isUpperCase(id.charAt(0)); | |
} | |
+ public static boolean isConstant(ByteList id) { | |
+ return Character.isUpperCase(id.get(0)); | |
+ } | |
+ | |
/** | |
* rb_is_class_id and is_class_id | |
*/ | |
@@ -45,13 +49,21 @@ public final class IdUtil { | |
return id.length() > 1 && id.charAt(0) == '@' && id.charAt(1) == '@'; | |
} | |
+ public static boolean isClassVariable(ByteList id) { | |
+ return id.length() > 1 && id.get(0) == '@' && id.get(1) == '@'; | |
+ } | |
+ | |
/** | |
* rb_is_instance_id and is_instance_id | |
- */ | |
+ */ | |
public static boolean isInstanceVariable(String id) { | |
return id.length() > 0 && id.charAt(0) == '@' && (id.length() < 2 || id.charAt(1) != '@'); | |
} | |
- | |
+ | |
+ public static boolean isInstanceVariable(ByteList id) { | |
+ return id.length() > 0 && id.get(0) == '@' && (id.length() < 2 || id.get(1) != '@'); | |
+ } | |
+ | |
/** | |
* rb_is_global_id and is_global_id | |
*/ | |
@@ -59,9 +71,17 @@ public final class IdUtil { | |
return id.length()>0 && id.charAt(0) == '$'; | |
} | |
+ public static boolean isGlobal(ByteList id) { | |
+ return id.length()>0 && id.get(0) == '$'; | |
+ } | |
+ | |
public static boolean isPredicate(String id) { | |
return id.endsWith("?"); | |
} | |
+ | |
+ public static boolean isPredicate(ByteList id) { | |
+ return id.get(id.realSize() - 1) == '?'; | |
+ } | |
/** | |
* rb_is_local_id and is_local_id | |
@@ -70,6 +90,10 @@ public final class IdUtil { | |
return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id); | |
} | |
+ public static boolean isLocal(ByteList id) { | |
+ return !isGlobal(id) && !isClassVariable(id) && !isInstanceVariable(id) && !isConstant(id) && !isPredicate(id) && !isSpecial(id); | |
+ } | |
+ | |
/** | |
* We store IR special variables (e.g. %block) in scope and we want reflective Ruby methods to | |
* not see these since they are not real variables...they're special. | |
@@ -78,6 +102,10 @@ public final class IdUtil { | |
return id.startsWith("%"); | |
} | |
+ public static boolean isSpecial(ByteList id) { | |
+ return id.get(0) == '%'; | |
+ } | |
+ | |
public static boolean isAttrSet(String id) { | |
return id.endsWith("="); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment