Permalink
Browse files

[1.9] Fix remaining language/method_spec failures in compiler.

  • Loading branch information...
1 parent 9f44668 commit 80bafe547ee48b90846999a5aeab826fa8983f0e @headius headius committed with yokolet Jan 8, 2011
@@ -281,7 +281,8 @@ public void assignMethodArguments19(
for (int optArgElement = 0; optArgElement < optArgsCount; currentArgElement++, optArgElement++) {
method.aload(argsIndex);
method.pushInt(currentArgElement); // index for the item
- methodCompiler.invokeUtilityMethod("elementOrNull", sig(IRubyObject.class, IRubyObject[].class, int.class));
+ method.pushInt(postArgsCount);
+ methodCompiler.invokeUtilityMethod("optElementOrNull", sig(IRubyObject.class, IRubyObject[].class, int.class, int.class));
method.dup();
method.ifnull(optLabels[optArgElement]);
@@ -1306,20 +1306,21 @@ public void forEachInValueArray(int start, int preCount, Object preSource, int p
for (int postStart = 0; postStart < postCount; postStart++) {
getVariableCompiler().getTempLocal(tempLocal);
+ method.pushInt(preCount);
method.pushInt(postCount);
switch (postStart) {
case 0:
- invokeUtilityMethod("arrayPostOrNilZero", sig(IRubyObject.class, RubyArray.class, int.class));
+ invokeUtilityMethod("arrayPostOrNilZero", sig(IRubyObject.class, RubyArray.class, int.class, int.class));
break;
case 1:
- invokeUtilityMethod("arrayPostOrNilOne", sig(IRubyObject.class, RubyArray.class, int.class));
+ invokeUtilityMethod("arrayPostOrNilOne", sig(IRubyObject.class, RubyArray.class, int.class, int.class));
break;
case 2:
- invokeUtilityMethod("arrayPostOrNilTwo", sig(IRubyObject.class, RubyArray.class, int.class));
+ invokeUtilityMethod("arrayPostOrNilTwo", sig(IRubyObject.class, RubyArray.class, int.class, int.class));
break;
default:
method.pushInt(postStart);
- invokeUtilityMethod("arrayPostOrNil", sig(IRubyObject.class, RubyArray.class, int.class, int.class));
+ invokeUtilityMethod("arrayPostOrNil", sig(IRubyObject.class, RubyArray.class, int.class, int.class, int.class));
break;
}
callback.nextValue(this, postSource, postStart);
@@ -1186,6 +1186,14 @@ public static IRubyObject elementOrNull(IRubyObject[] input, int element) {
}
}
+ public static IRubyObject optElementOrNull(IRubyObject[] input, int element, int postCount) {
+ if (element + postCount >= input.length) {
+ return null;
+ } else {
+ return input[element];
+ }
+ }
+
public static IRubyObject elementOrNil(IRubyObject[] input, int element, IRubyObject nil) {
if (element >= input.length) {
return nil;
@@ -1865,33 +1873,41 @@ public static IRubyObject arrayEntryOrNilTwo(RubyArray array) {
}
}
- public static IRubyObject arrayPostOrNil(RubyArray array, int post, int index) {
- if (index < array.getLength()) {
- return array.eltInternal(array.size() - post + index);
+ public static IRubyObject arrayPostOrNil(RubyArray array, int pre, int post, int index) {
+ if (pre + post < array.getLength()) {
+ return array.eltInternal(array.getLength() - post + index);
+ } else if (pre + index < array.getLength()) {
+ return array.eltInternal(pre + index);
} else {
return array.getRuntime().getNil();
}
}
- public static IRubyObject arrayPostOrNilZero(RubyArray array, int post) {
- if (0 < array.getLength()) {
- return array.eltInternal(array.size() - post + 0);
+ public static IRubyObject arrayPostOrNilZero(RubyArray array, int pre, int post) {
+ if (pre + post < array.getLength()) {
+ return array.eltInternal(array.getLength() - post + 0);
+ } else if (pre + 0 < array.getLength()) {
+ return array.eltInternal(pre + 0);
} else {
return array.getRuntime().getNil();
}
}
- public static IRubyObject arrayPostOrNilOne(RubyArray array, int post) {
- if (1 < array.getLength()) {
- return array.eltInternal(array.size() - post + 1);
+ public static IRubyObject arrayPostOrNilOne(RubyArray array, int pre, int post) {
+ if (pre + post < array.getLength()) {
+ return array.eltInternal(array.getLength() - post + 1);
+ } else if (pre + 1 < array.getLength()) {
+ return array.eltInternal(pre + 1);
} else {
return array.getRuntime().getNil();
}
}
- public static IRubyObject arrayPostOrNilTwo(RubyArray array, int post) {
- if (2 < array.getLength()) {
- return array.eltInternal(array.size() - post + 2);
+ public static IRubyObject arrayPostOrNilTwo(RubyArray array, int pre, int post) {
+ if (pre + post < array.getLength()) {
+ return array.eltInternal(array.getLength() - post + 2);
+ } else if (pre + 2 < array.getLength()) {
+ return array.eltInternal(pre + 2);
} else {
return array.getRuntime().getNil();
}

0 comments on commit 80bafe5

Please sign in to comment.