Skip to content

Commit

Permalink
Go to type for argument descriptor from ByteList.
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Apr 24, 2018
1 parent 6f74142 commit 69dc167
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -2063,10 +2063,8 @@ protected InterpreterContext defineMethodInner(DefNode defNode, IRScope parent,
argDesc = new ArgumentDescriptor[argumentDescriptions.size() / 2];
for (int i = 0; i < argumentDescriptions.size(); i += 2) {
ArgumentType type = (ArgumentType) argumentDescriptions.get(i);
// FIXME: bytelist_love we should probably push symbol through here instead of bytelsit?
RubySymbol symbol = (RubySymbol) argumentDescriptions.get(i+1);
ByteList name = symbol == null ? null : symbol.getBytes();
argDesc[i / 2] = new ArgumentDescriptor(type, name);
argDesc[i / 2] = new ArgumentDescriptor(type, symbol);
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/runtime/ArgumentDescriptor.java
Expand Up @@ -2,7 +2,7 @@

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.util.ByteList;
import org.jruby.RubySymbol;

/**
* A description of a single argument in a Ruby argument list.
Expand All @@ -12,12 +12,12 @@ public class ArgumentDescriptor {
public final ArgumentType type;

/** The name of the argument */
public final ByteList name;
public final RubySymbol name;

public static final ArgumentDescriptor[] EMPTY_ARRAY = new ArgumentDescriptor[0];
public static final ArgumentDescriptor[] ANON_REST = {new ArgumentDescriptor(ArgumentType.anonrest)};

public ArgumentDescriptor(ArgumentType type, ByteList name) {
public ArgumentDescriptor(ArgumentType type, RubySymbol name) {
if (name == null && !type.anonymous) {
throw new RuntimeException("null argument name given for non-anonymous argument type");
}
Expand Down
18 changes: 8 additions & 10 deletions core/src/main/java/org/jruby/runtime/ArgumentType.java
@@ -1,10 +1,8 @@
package org.jruby.runtime;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubySymbol;
import org.jruby.util.ByteList;

/**
* The diffierent types of arguments identified in a method.
Expand All @@ -22,10 +20,10 @@ public enum ArgumentType {
anonrest("rest", true),
anonkeyrest("keyrest", true);

ArgumentType(String typeName, boolean anonymous) {
this.typeName = new ByteList(typeName.getBytes(), USASCIIEncoding.INSTANCE);
ArgumentType(String typeId, boolean anonymous) {
this.typeId = typeId;
this.anonymous = anonymous;
this.name = new ByteList(toString().getBytes(), USASCIIEncoding.INSTANCE);
this.name = toString();
}

public static ArgumentType valueOf(char prefix) {
Expand All @@ -45,10 +43,10 @@ public static ArgumentType valueOf(char prefix) {
}
}

public RubyArray toArrayForm(Ruby runtime, ByteList name) {
RubySymbol typeName = runtime.newSymbol(this.typeName);
public RubyArray toArrayForm(Ruby runtime, RubySymbol name) {
RubySymbol typeName = runtime.newSymbol(typeId);

return anonymous ? runtime.newArray(typeName) : runtime.newArray(typeName, runtime.newSymbol(name));
return anonymous ? runtime.newArray(typeName) : runtime.newArray(typeName, name);
}

public ArgumentType anonymousForm() {
Expand All @@ -61,7 +59,7 @@ public ArgumentType anonymousForm() {
return this;
}

public final ByteList name;
public final ByteList typeName;
public final String name;
public final String typeId;
public final boolean anonymous;
}
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Expand Up @@ -2083,7 +2083,7 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
if (args[i] instanceof MultipleAsgnNode) {
descs.add(new ArgumentDescriptor(ArgumentType.anonreq));
} else {
descs.add(new ArgumentDescriptor(ArgumentType.req, ((ArgumentNode) args[i]).getName().getBytes()));
descs.add(new ArgumentDescriptor(ArgumentType.req, ((ArgumentNode) args[i]).getName()));
}
}
}
Expand All @@ -2096,7 +2096,7 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
for (int i = 0; i < optCount; i++) {
Node optNode = args[optIndex + i];
if (optNode instanceof INameNode) {
descs.add(new ArgumentDescriptor(ArgumentType.opt, ((INameNode) optNode).getName().getBytes()));
descs.add(new ArgumentDescriptor(ArgumentType.opt, ((INameNode) optNode).getName()));
} else {
descs.add(new ArgumentDescriptor(ArgumentType.anonopt));
}
Expand All @@ -2108,7 +2108,7 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
if (restArg instanceof UnnamedRestArgNode) {
if (((UnnamedRestArgNode) restArg).isStar()) descs.add(new ArgumentDescriptor(ArgumentType.anonrest));
} else {
descs.add(new ArgumentDescriptor(ArgumentType.rest, restArg.getName().getBytes()));
descs.add(new ArgumentDescriptor(ArgumentType.rest, restArg.getName()));
}
}

Expand All @@ -2120,7 +2120,7 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
if (postNode instanceof MultipleAsgnNode) {
descs.add(new ArgumentDescriptor(ArgumentType.anonreq));
} else {
descs.add(new ArgumentDescriptor(ArgumentType.req, ((ArgumentNode)postNode).getName().getBytes()));
descs.add(new ArgumentDescriptor(ArgumentType.req, ((ArgumentNode)postNode).getName()));
}
}
}
Expand All @@ -2132,18 +2132,18 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
Node keyWordNode = args[keywordsIndex + i];
for (Node asgnNode : keyWordNode.childNodes()) {
ArgumentType type = isRequiredKeywordArgumentValueNode(asgnNode) ? ArgumentType.keyreq : ArgumentType.key;
descs.add(new ArgumentDescriptor(type, ((INameNode) asgnNode).getName().getBytes()));
descs.add(new ArgumentDescriptor(type, ((INameNode) asgnNode).getName()));
}
}
}

if (argsNode.getKeyRest() != null) {
ByteList argName = argsNode.getKeyRest().getName().getBytes();
RubySymbol argName = argsNode.getKeyRest().getName();
// FIXME: Should a argName of "" really get saved that way here?
ArgumentType type = argName == null || argName.length() == 0 ? ArgumentType.anonkeyrest : ArgumentType.keyrest;
ArgumentType type = argName == null || argName.getBytes().length() == 0 ? ArgumentType.anonkeyrest : ArgumentType.keyrest;
descs.add(new ArgumentDescriptor(type, argName));
}
if (argsNode.getBlock() != null) descs.add(new ArgumentDescriptor(ArgumentType.block, argsNode.getBlock().getName().getBytes()));
if (argsNode.getBlock() != null) descs.add(new ArgumentDescriptor(ArgumentType.block, argsNode.getBlock().getName()));

return descs.toArray(new ArgumentDescriptor[descs.size()]);
}
Expand All @@ -2152,7 +2152,7 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
* Convert a parameter list from prefix format to ArgumentDescriptor format. This source is expected to come
* from a native path. Therefore we will be assuming parameterList is UTF-8.
*/
public static ArgumentDescriptor[] parameterListToArgumentDescriptors(String[] parameterList, boolean isLambda) {
public static ArgumentDescriptor[] parameterListToArgumentDescriptors(Ruby runtime, String[] parameterList, boolean isLambda) {
ArgumentDescriptor[] parms = new ArgumentDescriptor[parameterList.length];

for (int i = 0; i < parameterList.length; i++) {
Expand All @@ -2168,7 +2168,7 @@ public static ArgumentDescriptor[] parameterListToArgumentDescriptors(String[] p

// 'R', 'o', 'n' forms can get here without a name
if (param.length() > 1) {
parms[i] = new ArgumentDescriptor(type, new ByteList(param.substring(1).getBytes(), UTF8Encoding.INSTANCE));
parms[i] = new ArgumentDescriptor(type, runtime.newSymbol(param.substring(1)));
} else {
parms[i] = new ArgumentDescriptor(type.anonymousForm());
}
Expand All @@ -2195,7 +2195,7 @@ public static ArgumentDescriptor[] methodToArgumentDescriptors(DynamicMethod met
method = method.getRealMethod();

if (method instanceof MethodArgs2) {
return parameterListToArgumentDescriptors(((MethodArgs2) method).getParameterList(), true);
return parameterListToArgumentDescriptors(method.getImplementationClass().getRuntime(), ((MethodArgs2) method).getParameterList(), true);
} else if (method instanceof IRMethodArgs) {
return ((IRMethodArgs) method).getArgumentDescriptors();
} else {
Expand Down

0 comments on commit 69dc167

Please sign in to comment.