Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add anonkeyrest argument type for def foo(**).
Browse files Browse the repository at this point in the history
headius committed May 9, 2015
1 parent 21ea270 commit e3dd9c4
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -1799,7 +1799,7 @@ public void receiveRequiredArg(Node node, int argIndex, boolean post, int numPre
MultipleAsgnNode childNode = (MultipleAsgnNode) node;
Variable v = createTemporaryVariable();
addArgReceiveInstr(v, argIndex, post, numPreReqd, numPostRead);
if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.req, "");
if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.anonreq, null);
Variable tmp = createTemporaryVariable();
addInstr(new ToAryInstr(tmp, v));
buildMultipleAsgn19Assignment(childNode, tmp, null);
@@ -1963,8 +1963,13 @@ public void receiveArgs(final ArgsNode argsNode) {
KeywordRestArgNode keyRest = argsNode.getKeyRest();
if (keyRest != null) {
String argName = keyRest.getName();
ArgumentType type = ArgumentType.keyrest;

// anonymous keyrest
if (argName == null || argName.length() == 0) type = ArgumentType.anonkeyrest;

Variable av = getNewLocalVariable(argName, 0);
if (scope instanceof IRMethod) addArgumentDescription(ArgumentType.keyrest, argName);
if (scope instanceof IRMethod) addArgumentDescription(type, argName);
addInstr(new ReceiveKeywordRestArgInstr(av, required));
}

3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/runtime/ArgumentType.java
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@ public enum ArgumentType {
req("req", "q", false),
anonreq("req", "n", true),
anonopt("opt", "O", true),
anonrest("rest", "R", true);
anonrest("rest", "R", true),
anonkeyrest("keyrest", "N", true);

ArgumentType(String symbolicName, String prefix, boolean anonymous) {
this.symbolicName = symbolicName;
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -2470,7 +2470,14 @@ public static ArgumentDescriptor[] argsNodeToArgumentDescriptors(ArgsNode argsNo
}
}

if (argsNode.getKeyRest() != null) descs.add(new ArgumentDescriptor(ArgumentType.keyrest, argsNode.getKeyRest().getName()));
if (argsNode.getKeyRest() != null) {
String argName = argsNode.getKeyRest().getName();
if (argName == null || argName.length() == 0) {
descs.add(new ArgumentDescriptor(ArgumentType.anonkeyrest, argName));
} else {
descs.add(new ArgumentDescriptor(ArgumentType.keyrest, argsNode.getKeyRest().getName()));
}
}
if (argsNode.getBlock() != null) descs.add(new ArgumentDescriptor(ArgumentType.block, argsNode.getBlock().getName()));

return descs.toArray(new ArgumentDescriptor[descs.size()]);

0 comments on commit e3dd9c4

Please sign in to comment.