Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5bceb42487d7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f08edcab6018
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 13, 2015

  1. Copy the full SHA
    8ed5651 View commit details
  2. Copy the full SHA
    f08edca View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/persistence/IRReader.java
Original file line number Diff line number Diff line change
@@ -58,9 +58,9 @@ private static IRScope decodeScopeHeader(IRManager manager, IRReaderDecoder deco
IRScope parent = type != IRScopeType.SCRIPT_BODY ? decoder.decodeScope() : null;
Signature signature;
if (type == IRScopeType.CLOSURE || type == IRScopeType.FOR) {
signature = Signature.from(decoder.decodeInt(), decoder.decodeInt(), decoder.decodeInt(), decoder.decodeBoolean());
signature = Signature.decode(decoder.decodeInt());
} else {
signature = Signature.from(0, 0, 0, true);
signature = Signature.OPTIONAL;
}
int argumentType = type == IRScopeType.CLOSURE ? decoder.decodeInt() : -1;
StaticScope parentScope = parent == null ? null : parent.getStaticScope();
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/persistence/IRWriter.java
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ private static void persistScopeHeader(IRWriterEncoder file, IRScope scope) {
if (scope instanceof IRClosure) {
IRClosure closure = (IRClosure) scope;

file.encode(closure.getArity().getValue());
file.encode(closure.getSignature().encode());
file.encode(closure.getArgumentType());
}

46 changes: 46 additions & 0 deletions core/src/main/java/org/jruby/runtime/Signature.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,15 @@
public class Signature {
public enum Rest { NONE, NORM, ANON, STAR }

public static final Signature NO_ARGUMENTS = new Signature(0, 0, 0, Rest.NONE);
public static final Signature ONE_ARGUMENT = new Signature(1, 0, 0, Rest.NONE);
public static final Signature TWO_ARGUMENTS = new Signature(2, 0, 0, Rest.NONE);
public static final Signature THREE_ARGUMENTS = new Signature(3, 0, 0, Rest.NONE);
public static final Signature OPTIONAL = new Signature(0, 0, 0, Rest.NORM);
public static final Signature ONE_REQUIRED = new Signature(1, 0, 0, Rest.NORM);
public static final Signature TWO_REQUIRED = new Signature(2, 0, 0, Rest.NORM);
public static final Signature THREE_REQUIRED = new Signature(3, 0, 0, Rest.NORM);

private final int pre;
private final int opt;
private final Rest rest;
@@ -50,6 +59,42 @@ public Signature(int pre, int opt, int post, Rest rest) {
public Arity arity() { return arity; }

public static Signature from(int pre, int opt, int post, Rest rest) {
if (opt == 0 && post == 0) {
switch (pre) {
case 0:
switch (rest) {
case NONE:
return Signature.NO_ARGUMENTS;
case NORM:
return Signature.OPTIONAL;
}
break;
case 1:
switch (rest) {
case NONE:
return Signature.ONE_ARGUMENT;
case NORM:
return Signature.ONE_REQUIRED;
}
break;
case 2:
switch (rest) {
case NONE:
return Signature.TWO_ARGUMENTS;
case NORM:
return Signature.TWO_REQUIRED;
}
break;
case 3:
switch (rest) {
case NONE:
return Signature.THREE_ARGUMENTS;
case NORM:
return Signature.THREE_REQUIRED;
}
break;
}
}
return new Signature(pre, opt, post, rest);
}

@@ -68,6 +113,7 @@ public static Signature from(IterNode iter) {
Node restArg = args.getRestArgNode();
rest = restFromArg(restArg);
}

return Signature.from(args.getPreCount(), args.getOptionalArgsCount(), args.getPostCount(), rest);
}

4 changes: 2 additions & 2 deletions core/src/main/ruby/jruby/java/core_ext/object.rb
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ def java_kind_of?(other)
def java_import(*import_classes)
import_classes = import_classes.each_with_object([]) do |classes, flattened|
if classes.is_a?(Array)
flattened.push *classes
flattened.push(*classes)
else
flattened.push classes
flattened.push(classes)
end
end