Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

committing threadcontext work to branch

git-svn-id: http://svn.codehaus.org/jruby/branches/threadcontext@2259 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 9f40038f16dc52d819c2a916703e334ac7868441 1 parent 2d688c9
Charles Oliver Nutter headius authored
Showing with 1,660 additions and 1,613 deletions.
  1. +1 −1  src/org/jruby/MetaClass.java
  2. +5 −3 src/org/jruby/Ruby.java
  3. +6 −3 src/org/jruby/RubyArgsFile.java
  4. +17 −17 src/org/jruby/RubyArray.java
  5. +1 −1  src/org/jruby/RubyClass.java
  6. +5 −5 src/org/jruby/RubyComparable.java
  7. +22 −19 src/org/jruby/RubyEnumerable.java
  8. +1 −1  src/org/jruby/RubyException.java
  9. +2 −2 src/org/jruby/RubyFixnum.java
  10. +7 −7 src/org/jruby/RubyFloat.java
  11. +7 −5 src/org/jruby/RubyGlobal.java
  12. +4 −3 src/org/jruby/RubyHash.java
  13. +13 −10 src/org/jruby/RubyIO.java
  14. +19 −14 src/org/jruby/RubyInteger.java
  15. +15 −14 src/org/jruby/RubyKernel.java
  16. +1 −1  src/org/jruby/RubyMarshal.java
  17. +1 −1  src/org/jruby/RubyMethod.java
  18. +17 −15 src/org/jruby/RubyModule.java
  19. +14 −11 src/org/jruby/RubyNumeric.java
  20. +44 −41 src/org/jruby/RubyObject.java
  21. +3 −3 src/org/jruby/RubyPrecision.java
  22. +30 −24 src/org/jruby/RubyRange.java
  23. +6 −6 src/org/jruby/RubyString.java
  24. +1 −1  src/org/jruby/RubyStruct.java
  25. +4 −3 src/org/jruby/RubySymbol.java
  26. +1 −1  src/org/jruby/RubyThread.java
  27. +1 −1  src/org/jruby/RubyTime.java
  28. +7 −4 src/org/jruby/RubyZlib.java
  29. +1,096 −1,084 src/org/jruby/ast/executable/InstructionCompiler2.java
  30. +1 −1  src/org/jruby/common/RubyWarnings.java
  31. +8 −6 src/org/jruby/evaluator/AssignmentVisitor.java
  32. +3 −3 src/org/jruby/evaluator/DefinedVisitor.java
  33. +120 −112 src/org/jruby/evaluator/EvaluateVisitor.java
  34. +13 −8 src/org/jruby/evaluator/EvaluationState.java
  35. +3 −3 src/org/jruby/exceptions/RaiseException.java
  36. +3 −2 src/org/jruby/internal/runtime/methods/AbstractCallable.java
  37. +5 −4 src/org/jruby/internal/runtime/methods/AbstractMethod.java
  38. +7 −6 src/org/jruby/internal/runtime/methods/AliasMethod.java
  39. +6 −8 src/org/jruby/internal/runtime/methods/CallbackMethod.java
  40. +10 −14 src/org/jruby/internal/runtime/methods/DefaultMethod.java
  41. +3 −8 src/org/jruby/internal/runtime/methods/DirectInvocationMethod.java
  42. +5 −4 src/org/jruby/internal/runtime/methods/EvaluateCallable.java
  43. +4 −4 src/org/jruby/internal/runtime/methods/IterateCallable.java
  44. +3 −7 src/org/jruby/internal/runtime/methods/MethodMethod.java
  45. +13 −18 src/org/jruby/internal/runtime/methods/MultiStubMethod.java
  46. +3 −7 src/org/jruby/internal/runtime/methods/ProcMethod.java
  47. +6 −9 src/org/jruby/internal/runtime/methods/ReflectedMethod.java
  48. +6 −5 src/org/jruby/internal/runtime/methods/UndefinedMethod.java
  49. +5 −4 src/org/jruby/internal/runtime/methods/WrapperCallable.java
  50. +3 −3 src/org/jruby/javasupport/Java.java
  51. +6 −3 src/org/jruby/javasupport/JavaClass.java
  52. +6 −3 src/org/jruby/javasupport/JavaEmbedUtils.java
  53. +11 −9 src/org/jruby/javasupport/JavaUtil.java
  54. +2 −2 src/org/jruby/javasupport/bsf/JRubyEngine.java
  55. +4 −3 src/org/jruby/libraries/RubySocket.java
  56. +2 −1  src/org/jruby/libraries/SocketMetaClass.java
  57. +3 −5 src/org/jruby/runtime/CallBlock.java
  58. +0 −10 src/org/jruby/runtime/Frame.java
  59. +4 −5 src/org/jruby/runtime/ICallable.java
  60. +2 −2 src/org/jruby/runtime/ThreadContext.java
  61. +6 −5 src/org/jruby/runtime/builtin/IRubyObject.java
  62. +1 −1  src/org/jruby/runtime/builtin/meta/FixnumMetaClass.java
  63. +1 −1  src/org/jruby/runtime/builtin/meta/IOMetaClass.java
  64. +13 −12 src/org/jruby/runtime/builtin/meta/StringMetaClass.java
  65. +2 −1  src/org/jruby/runtime/builtin/meta/SymbolMetaClass.java
  66. +2 −2 src/org/jruby/runtime/marshal/MarshalStream.java
  67. +3 −2 src/org/jruby/runtime/marshal/UnmarshalStream.java
  68. +3 −3 src/org/jruby/util/IOInputStream.java
  69. +2 −2 src/org/jruby/util/IOOutputStream.java
  70. +2 −2 src/org/jruby/util/IOReader.java
  71. +3 −1 src/org/jruby/yaml/JRubyConstructor.java
  72. +1 −1  test/org/jruby/test/ScriptTestSuite.java
2  src/org/jruby/MetaClass.java
View
@@ -63,7 +63,7 @@ public RubyClass getRealClass() {
}
public void methodAdded(RubySymbol symbol) {
- getAttachedObject().callMethod("singleton_method_added", symbol);
+ getAttachedObject().callMethod(getRuntime().getCurrentContext(), "singleton_method_added", symbol);
}
public IRubyObject getAttachedObject() {
8 src/org/jruby/Ruby.java
View
@@ -203,7 +203,8 @@ public IRubyObject evalScript(String script) {
public IRubyObject eval(Node node) {
try {
- return getCurrentContext().getFrameEvalState().begin(node);
+ ThreadContext context = getCurrentContext();
+ return context.getFrameEvalState().begin(context, node);
} catch (JumpException je) {
if (je.getJumpType() == JumpException.JumpType.ReturnJump) {
return (IRubyObject)je.getSecondaryData();
@@ -713,12 +714,13 @@ public void printError(RubyException excp) {
if (excp == null || excp.isNil()) {
return;
}
+
+ ThreadContext tc = getCurrentContext();
- RubyArray backtrace = (RubyArray) excp.callMethod("backtrace");
+ RubyArray backtrace = (RubyArray) excp.callMethod(tc, "backtrace");
PrintStream errorStream = getErrorStream();
if (backtrace.isNil()) {
- ThreadContext tc = getCurrentContext();
if (tc.getSourceFile() != null) {
errorStream.print(tc.getPosition());
9 src/org/jruby/RubyArgsFile.java
View
@@ -31,6 +31,7 @@
package org.jruby;
import org.jruby.runtime.CallbackFactory;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
public class RubyArgsFile extends RubyObject {
@@ -106,15 +107,17 @@ public IRubyObject internalGets(IRubyObject[] args) {
return getRuntime().getNil();
}
- IRubyObject line = currentFile.callMethod("gets", args);
+ ThreadContext context = getRuntime().getCurrentContext();
+
+ IRubyObject line = currentFile.callMethod(context, "gets", args);
while (line instanceof RubyNil) {
- currentFile.callMethod("close");
+ currentFile.callMethod(context, "close");
if (! nextArgsFile()) {
currentFile = null;
return line;
}
- line = currentFile.callMethod("gets", args);
+ line = currentFile.callMethod(context, "gets", args);
}
currentLineNumber++;
34 src/org/jruby/RubyArray.java
View
@@ -107,7 +107,7 @@ public int getLength() {
public boolean includes(IRubyObject item) {
for (int i = 0, n = getLength(); i < n; i++) {
- if (item.callMethod("==", entry(i)).isTrue()) {
+ if (item.callMethod(getRuntime().getCurrentContext(), "==", entry(i)).isTrue()) {
return true;
}
}
@@ -631,7 +631,7 @@ public IRubyObject inspect() {
if (i > 0) {
result.append(separator);
}
- result.append(entry(i).callMethod("inspect"));
+ result.append(entry(i).callMethod(getRuntime().getCurrentContext(), "inspect"));
}
result.cat("]");
return result;
@@ -819,7 +819,7 @@ public IRubyObject array_op_equal(IRubyObject obj) {
}
for (long i = 0; i < length; i++) {
- if (!entry(i).callMethod("==", ary.entry(i)).isTrue()) {
+ if (!entry(i).callMethod(getRuntime().getCurrentContext(), "==", ary.entry(i)).isTrue()) {
return getRuntime().getFalse();
}
}
@@ -842,7 +842,7 @@ public RubyBoolean eql(IRubyObject obj) {
}
for (long i = 0; i < length; i++) {
- if (!entry(i).callMethod("eql?", ary.entry(i)).isTrue()) {
+ if (!entry(i).callMethod(getRuntime().getCurrentContext(), "eql?", ary.entry(i)).isTrue()) {
return getRuntime().getFalse();
}
}
@@ -952,7 +952,7 @@ public IRubyObject fill(IRubyObject[] args) {
*/
public IRubyObject index(IRubyObject obj) {
for (int i = 0, len = getLength(); i < len; i++) {
- if (obj.callMethod("==", entry(i)).isTrue()) {
+ if (obj.callMethod(getRuntime().getCurrentContext(), "==", entry(i)).isTrue()) {
return getRuntime().newFixnum(i);
}
}
@@ -964,7 +964,7 @@ public IRubyObject index(IRubyObject obj) {
*/
public IRubyObject rindex(IRubyObject obj) {
for (int i = getLength() - 1; i >= 0; i--) {
- if (obj.callMethod("==", entry(i)).isTrue()) {
+ if (obj.callMethod(getRuntime().getCurrentContext(), "==", entry(i)).isTrue()) {
return getRuntime().newFixnum(i);
}
}
@@ -1043,15 +1043,15 @@ public RubyArray collect_bang() {
*/
public IRubyObject delete(IRubyObject obj) {
modify();
- ThreadContext tc = getRuntime().getCurrentContext();
+ ThreadContext context = getRuntime().getCurrentContext();
IRubyObject result = getRuntime().getNil();
for (int i = getLength() - 1; i >= 0; i--) {
- if (obj.callMethod("==", entry(i)).isTrue()) {
+ if (obj.callMethod(context, "==", entry(i)).isTrue()) {
result = (IRubyObject) list.remove(i);
}
}
- if (result.isNil() && tc.isBlockGiven()) {
- result = tc.yield(entry(0));
+ if (result.isNil() && context.isBlockGiven()) {
+ result = context.yield(entry(0));
}
return result;
}
@@ -1114,7 +1114,7 @@ public IRubyObject op_cmp(IRubyObject other) {
}
for (int i = 0; i < len; i++) {
- IRubyObject result = entry(i).callMethod("<=>", ary.entry(i));
+ IRubyObject result = entry(i).callMethod(getRuntime().getCurrentContext(), "<=>", ary.entry(i));
if (result.isNil() || ((RubyFixnum)result).getLongValue() != 0) {
return result;
@@ -1152,7 +1152,7 @@ public IRubyObject assoc(IRubyObject arg) {
continue;
}
RubyArray ary = (RubyArray) entry(i);
- if (arg.callMethod("==", ary.entry(0)).isTrue()) {
+ if (arg.callMethod(getRuntime().getCurrentContext(), "==", ary.entry(0)).isTrue()) {
return ary;
}
}
@@ -1168,7 +1168,7 @@ public IRubyObject rassoc(IRubyObject arg) {
continue;
}
RubyArray ary = (RubyArray) entry(i);
- if (arg.callMethod("==", ary.entry(1)).isTrue()) {
+ if (arg.callMethod(getRuntime().getCurrentContext(), "==", ary.entry(1)).isTrue()) {
return ary;
}
}
@@ -1278,7 +1278,7 @@ public IRubyObject op_diff(IRubyObject other) {
for (int i = ary1.size() - 1; i >= 0; i--) {
IRubyObject obj = (IRubyObject) ary1.get(i);
for (int j = 0; j < len2; j++) {
- if (obj.callMethod("==", (IRubyObject) ary2.get(j)).isTrue()) {
+ if (obj.callMethod(getRuntime().getCurrentContext(), "==", (IRubyObject) ary2.get(j)).isTrue()) {
ary1.remove(i);
break;
}
@@ -1305,7 +1305,7 @@ public IRubyObject op_and(IRubyObject other) {
for (int i = 0; i < len1; i++) {
IRubyObject obj = (IRubyObject) ary1.get(i);
for (int j = 0; j < len2; j++) {
- if (obj.callMethod("eql?", (IRubyObject) ary2.get(j)).isTrue()) {
+ if (obj.callMethod(getRuntime().getCurrentContext(), "eql?", (IRubyObject) ary2.get(j)).isTrue()) {
ary3.add(obj);
break;
}
@@ -1400,10 +1400,10 @@ public int compare(Object o1, Object o2) {
if (o1 instanceof RubyString && o2 instanceof RubyString) {
StringMetaClass stringMC = (StringMetaClass)((RubyObject)o1).getMetaClass();
return RubyNumeric.fix2int(
- stringMC.op_cmp.call(stringMC.getRuntime(), (RubyString)o1, stringMC, "<=>", new IRubyObject[] {(RubyString)o2}, false));
+ stringMC.op_cmp.call(stringMC.getRuntime().getCurrentContext(), (RubyString)o1, stringMC, "<=>", new IRubyObject[] {(RubyString)o2}, false));
}
- return RubyNumeric.fix2int(obj1.callMethod("<=>", obj2));
+ return RubyNumeric.fix2int(obj1.callMethod(obj1.getRuntime().getCurrentContext(), "<=>", obj2));
}
}
2  src/org/jruby/RubyClass.java
View
@@ -112,7 +112,7 @@ public void inheritedBy(RubyClass superType) {
if (superType == null) {
superType = getRuntime().getObject();
}
- superType.callMethod("inherited", this);
+ superType.callMethod(getRuntime().getCurrentContext(), "inherited", this);
}
/** rb_singleton_class_clone
10 src/org/jruby/RubyComparable.java
View
@@ -59,7 +59,7 @@ public static IRubyObject equal(IRubyObject recv, IRubyObject other) {
if (recv == other) {
return recv.getRuntime().getTrue();
}
- IRubyObject result = recv.callMethod("<=>", other);
+ IRubyObject result = recv.callMethod(recv.getRuntime().getCurrentContext(), "<=>", other);
if (result.isNil()) {
return result;
@@ -86,7 +86,7 @@ private static void cmperr(IRubyObject recv, IRubyObject other) {
public static RubyBoolean op_gt(IRubyObject recv, IRubyObject other) {
// <=> may return nil in many circumstances, e.g. 3 <=> NaN
- IRubyObject tmp = recv.callMethod("<=>", other);
+ IRubyObject tmp = recv.callMethod(recv.getRuntime().getCurrentContext(), "<=>", other);
if (tmp.isNil()) {
cmperr(recv, other);
@@ -96,7 +96,7 @@ public static RubyBoolean op_gt(IRubyObject recv, IRubyObject other) {
}
public static RubyBoolean op_ge(IRubyObject recv, IRubyObject other) {
- IRubyObject tmp = recv.callMethod("<=>", other);
+ IRubyObject tmp = recv.callMethod(recv.getRuntime().getCurrentContext(), "<=>", other);
if (tmp.isNil()) {
cmperr(recv, other);
@@ -106,7 +106,7 @@ public static RubyBoolean op_ge(IRubyObject recv, IRubyObject other) {
}
public static RubyBoolean op_lt(IRubyObject recv, IRubyObject other) {
- IRubyObject tmp = recv.callMethod("<=>", other);
+ IRubyObject tmp = recv.callMethod(recv.getRuntime().getCurrentContext(), "<=>", other);
if (tmp.isNil()) {
cmperr(recv, other);
@@ -116,7 +116,7 @@ public static RubyBoolean op_lt(IRubyObject recv, IRubyObject other) {
}
public static RubyBoolean op_le(IRubyObject recv, IRubyObject other) {
- IRubyObject tmp = recv.callMethod("<=>", other);
+ IRubyObject tmp = recv.callMethod(recv.getRuntime().getCurrentContext(), "<=>", other);
if (tmp.isNil()) {
cmperr(recv, other);
41 src/org/jruby/RubyEnumerable.java
View
@@ -73,7 +73,10 @@ public List getList() {
private static class RubyFirstArrayComparator implements Comparator {
public int compare(Object o1, Object o2) {
- return RubyFixnum.fix2int((((IRubyObject[])o1)[0].callMethod("<=>",((IRubyObject[])o2)[0])));
+ IRubyObject[] o1arr = (IRubyObject[])o1;
+ IRubyObject[] o2arr = (IRubyObject[])o2;
+
+ return RubyFixnum.fix2int(o1arr[0].callMethod(o1arr[0].getRuntime().getCurrentContext(), "<=>", o2arr[0]));
}
}
private static class RubyYieldComparator implements Comparator {
@@ -88,12 +91,12 @@ public int compare(Object o1, Object o2) {
}
}
- public static IRubyObject callEach(ThreadContext tc, IRubyObject self, RubyModule module, BlockCallback bc) {
- Iter bef = tc.getFrameIter();
- tc.preBlockPassEval(new CallBlock(self,module,Arity.noArguments(),bc,tc));
- IRubyObject ret = self.callMethod("each");
- tc.postBlockPassEval();
- tc.setFrameIter(bef);
+ public static IRubyObject callEach(ThreadContext context, IRubyObject self, RubyModule module, BlockCallback bc) {
+ Iter bef = context.getFrameIter();
+ context.preBlockPassEval(new CallBlock(self,module,Arity.noArguments(),bc,context));
+ IRubyObject ret = self.callMethod(context, "each");
+ context.postBlockPassEval();
+ context.setFrameIter(bef);
return ret;
}
@@ -143,8 +146,8 @@ public IRubyObject method0(ThreadContext tc, IRubyObject self, IRubyObject[] arg
public IRubyObject method1(final ThreadContext tc, IRubyObject self, IRubyObject[] args) {
//SORT
if(!tc.isBlockGiven()) {
- IRubyObject res = self.callMethod("to_a");
- return res.callMethod("sort");
+ IRubyObject res = self.callMethod(tc, "to_a");
+ return res.callMethod(tc, "sort");
} else {
final List arr = eachToList(tc,self,module);
Collections.sort(arr, new RubyYieldComparator(tc));
@@ -176,14 +179,14 @@ public IRubyObject method3(ThreadContext tc, IRubyObject self, IRubyObject[] arg
if(!tc.isBlockGiven()) {
for(Iterator iter = arr.iterator();iter.hasNext();) {
IRubyObject item = (IRubyObject)iter.next();
- if(pattern.callMethod("===",item).isTrue()) {
+ if(pattern.callMethod(tc, "===",item).isTrue()) {
result.add(item);
}
}
} else {
for(Iterator iter = arr.iterator();iter.hasNext();) {
IRubyObject item = (IRubyObject)iter.next();
- if(pattern.callMethod("===",item).isTrue()) {
+ if(pattern.callMethod(tc, "===",item).isTrue()) {
result.add(tc.yield(item));
}
}
@@ -323,7 +326,7 @@ public IRubyObject method1(ThreadContext tc, IRubyObject self, IRubyObject[] arg
//INCLUDE?
List arr = eachToList(tc,self,module);
for(Iterator iter = arr.iterator();iter.hasNext();) {
- if(args[0].callMethod("==",(IRubyObject)iter.next()).isTrue()) {
+ if(args[0].callMethod(tc, "==",(IRubyObject)iter.next()).isTrue()) {
return tc.getRuntime().getTrue();
}
}
@@ -337,14 +340,14 @@ public IRubyObject method2(final ThreadContext tc, IRubyObject self, IRubyObject
if(tc.isBlockGiven()) {
for(Iterator iter = arr.iterator();iter.hasNext();) {
IRubyObject item = (IRubyObject)iter.next();
- if(result == null || (tc.yield(tc.getRuntime().newArray(item,result)).callMethod(">", RubyFixnum.zero(tc.getRuntime()))).isTrue()) {
+ if(result == null || (tc.yield(tc.getRuntime().newArray(item,result)).callMethod(tc, ">", RubyFixnum.zero(tc.getRuntime()))).isTrue()) {
result = item;
}
}
} else {
for(Iterator iter = arr.iterator();iter.hasNext();) {
IRubyObject item = (IRubyObject)iter.next();
- if(result == null || item.callMethod("<=>",result).callMethod(">", RubyFixnum.zero(tc.getRuntime())).isTrue()) {
+ if(result == null || item.callMethod(tc, "<=>",result).callMethod(tc, ">", RubyFixnum.zero(tc.getRuntime())).isTrue()) {
result = item;
}
}
@@ -362,14 +365,14 @@ public IRubyObject method3(ThreadContext tc, IRubyObject self, IRubyObject[] arg
if(tc.isBlockGiven()) {
for(Iterator iter = arr.iterator();iter.hasNext();) {
IRubyObject item = (IRubyObject)iter.next();
- if(result == null || (tc.yield(tc.getRuntime().newArray(item,result)).callMethod("<", RubyFixnum.zero(tc.getRuntime()))).isTrue()) {
+ if(result == null || (tc.yield(tc.getRuntime().newArray(item,result)).callMethod(tc, "<", RubyFixnum.zero(tc.getRuntime()))).isTrue()) {
result = item;
}
}
} else {
for(Iterator iter = arr.iterator();iter.hasNext();) {
IRubyObject item = (IRubyObject)iter.next();
- if(result == null || item.callMethod("<=>",result).callMethod("<", RubyFixnum.zero(tc.getRuntime())).isTrue()) {
+ if(result == null || item.callMethod(tc, "<=>",result).callMethod(tc, "<", RubyFixnum.zero(tc.getRuntime())).isTrue()) {
result = item;
}
}
@@ -435,7 +438,7 @@ public IRubyObject method6(ThreadContext tc, IRubyObject self, IRubyObject[] arg
List array = new ArrayList(aLen);
array.add(elem);
for(int i=0,j=args.length;i<j;i++) {
- array.add(args[i].callMethod("[]",tc.getRuntime().newFixnum(ix)));
+ array.add(args[i].callMethod(tc, "[]",tc.getRuntime().newFixnum(ix)));
}
tc.yield(tc.getRuntime().newArray(array));
ix++;
@@ -447,7 +450,7 @@ public IRubyObject method6(ThreadContext tc, IRubyObject self, IRubyObject[] arg
List array = new ArrayList(aLen);
array.add(elem);
for(int i=0,j=args.length;i<j;i++) {
- array.add(args[i].callMethod("[]",tc.getRuntime().newFixnum(ix)));
+ array.add(args[i].callMethod(tc, "[]",tc.getRuntime().newFixnum(ix)));
}
zip.add(tc.getRuntime().newArray(array));
ix++;
@@ -467,7 +470,7 @@ public IRubyObject method7(ThreadContext tc, IRubyObject self, IRubyObject[] arg
curr = tc.getRuntime().newArray();
results.put(key,curr);
}
- curr.callMethod("<<",item);
+ curr.callMethod(tc, "<<",item);
}
return new RubyHash(tc.getRuntime(),results,tc.getRuntime().getNil());
}
2  src/org/jruby/RubyException.java
View
@@ -148,7 +148,7 @@ public IRubyObject to_s() {
return getRuntime().newString(getMetaClass().getName());
}
message.setTaint(isTaint());
- return (RubyString) message.callMethod("to_s");
+ return (RubyString) message.callMethod(getRuntime().getCurrentContext(), "to_s");
}
/** inspects an object and return a kind of debug information
4 src/org/jruby/RubyFixnum.java
View
@@ -259,7 +259,7 @@ public IRubyObject op_mul(IRubyObject other) {
public IRubyObject op_or(IRubyObject other) {
if (other instanceof RubyBignum) {
- return (RubyInteger) other.callMethod("|", this);
+ return (RubyInteger) other.callMethod(getRuntime().getCurrentContext(), "|", this);
} else if (other instanceof RubyNumeric) {
return newFixnum(value | ((RubyNumeric) other).getLongValue());
}
@@ -317,7 +317,7 @@ public IRubyObject op_rshift(IRubyObject other) {
public IRubyObject op_xor(IRubyObject other) {
if (other instanceof RubyBignum) {
- return (RubyInteger) other.callMethod("^", this);
+ return (RubyInteger) other.callMethod(getRuntime().getCurrentContext(), "^", this);
} else if (other instanceof RubyNumeric) {
return newFixnum(value ^ ((RubyNumeric) other).getLongValue());
}
14 src/org/jruby/RubyFloat.java
View
@@ -138,7 +138,7 @@ public static RubyFloat induced_from(IRubyObject recv, IRubyObject number) {
if (number instanceof RubyFloat) {
return (RubyFloat) number;
} else if (number instanceof RubyInteger) {
- return (RubyFloat) number.callMethod("to_f");
+ return (RubyFloat) number.callMethod(recv.getRuntime().getCurrentContext(), "to_f");
} else {
throw recv.getRuntime().newTypeError("failed to convert " + number.getMetaClass() + " into Float");
}
@@ -337,7 +337,7 @@ public static RubyFloat unmarshalFrom(UnmarshalStream input) throws java.io.IOEx
/* flo_eq */
public IRubyObject equal(IRubyObject other) {
if (!(other instanceof RubyNumeric)) {
- return other.callMethod("==", this);
+ return other.callMethod(getRuntime().getCurrentContext(), "==", this);
}
double otherValue = ((RubyNumeric) other).getDoubleValue();
@@ -357,7 +357,7 @@ public IRubyObject cmp(IRubyObject other) {
if (tmp == null) {
return getRuntime().getNil();
}
- return tmp[1].callMethod("<=>", tmp[0]);
+ return tmp[1].callMethod(getRuntime().getCurrentContext(), "<=>", tmp[0]);
}
return doubleCompare(((RubyNumeric) other).getDoubleValue());
@@ -382,7 +382,7 @@ public IRubyObject op_gt(IRubyObject other) {
cmperr(other);
}
- return tmp[1].callMethod("<=>", tmp[0]);
+ return tmp[1].callMethod(getRuntime().getCurrentContext(), "<=>", tmp[0]);
}
double oth = ((RubyNumeric) other).getDoubleValue();
@@ -406,7 +406,7 @@ public IRubyObject op_ge(IRubyObject other) {
cmperr(other);
}
- return tmp[1].callMethod("<=>", tmp[0]);
+ return tmp[1].callMethod(getRuntime().getCurrentContext(), "<=>", tmp[0]);
}
double oth = ((RubyNumeric) other).getDoubleValue();
@@ -430,7 +430,7 @@ public IRubyObject op_lt(IRubyObject other) {
cmperr(other);
}
- return tmp[1].callMethod("<=>", tmp[0]);
+ return tmp[1].callMethod(getRuntime().getCurrentContext(), "<=>", tmp[0]);
}
double oth = ((RubyNumeric) other).getDoubleValue();
@@ -455,7 +455,7 @@ public IRubyObject op_le(IRubyObject other) {
cmperr(other);
}
- return tmp[1].callMethod("<=>", tmp[0]);
+ return tmp[1].callMethod(getRuntime().getCurrentContext(), "<=>", tmp[0]);
}
double oth = ((RubyNumeric) other).getDoubleValue();
12 src/org/jruby/RubyGlobal.java
View
@@ -44,6 +44,7 @@
import org.jruby.runtime.Constants;
import org.jruby.runtime.GlobalVariable;
import org.jruby.runtime.ReadonlyGlobalVariable;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
/** This class initializes global variables and constants.
@@ -67,7 +68,7 @@ public IRubyObject aref(IRubyObject key) {
throw getRuntime().newTypeError("can't convert " + key.getMetaClass() + " into String");
}
- return super.aref(key.callMethod("to_str"));
+ return super.aref(key.callMethod(getRuntime().getCurrentContext(), "to_str"));
}
public IRubyObject aset(IRubyObject key, IRubyObject value) {
@@ -78,8 +79,9 @@ public IRubyObject aset(IRubyObject key, IRubyObject value) {
throw getRuntime().newTypeError("can't convert " + value.getMetaClass() + " into String");
}
- return super.aset(key.callMethod("to_str"),
- value.isNil() ? getRuntime().getNil() : value.callMethod("to_str"));
+ ThreadContext context = getRuntime().getCurrentContext();
+ return super.aset(key.callMethod(context, "to_str"),
+ value.isNil() ? getRuntime().getNil() : value.callMethod(context, "to_str"));
}
}
@@ -242,14 +244,14 @@ public BacktraceGlobalVariable(IRuby runtime, String name) {
public IRubyObject get() {
IRubyObject errorInfo = runtime.getGlobalVariables().get("$!");
- return errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod("backtrace");
+ return errorInfo.isNil() ? runtime.getNil() : errorInfo.callMethod(runtime.getCurrentContext(), "backtrace");
}
public IRubyObject set(IRubyObject value) {
if (runtime.getGlobalVariables().get("$!").isNil()) {
throw runtime.newArgumentError("$! not set.");
}
- runtime.getGlobalVariables().get("$!").callMethod("set_backtrace", value);
+ runtime.getGlobalVariables().get("$!").callMethod(runtime.getCurrentContext(), "set_backtrace", value);
return value;
}
}
7 src/org/jruby/RubyHash.java
View
@@ -221,6 +221,7 @@ public IRubyObject inspect() {
final StringBuffer sb = new StringBuffer("{");
boolean firstEntry = true;
+ ThreadContext context = getRuntime().getCurrentContext();
for (Iterator iter = valueMap.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
IRubyObject key = (IRubyObject) entry.getKey();
@@ -228,8 +229,8 @@ public IRubyObject inspect() {
if (!firstEntry) {
sb.append(sep);
}
- sb.append(key.callMethod("inspect")).append(arrow);
- sb.append(value.callMethod("inspect"));
+ sb.append(key.callMethod(context, "inspect")).append(arrow);
+ sb.append(value.callMethod(context, "inspect"));
firstEntry = false;
}
sb.append("}");
@@ -299,7 +300,7 @@ public IRubyObject aset(IRubyObject key, IRubyObject value) {
public IRubyObject aref(IRubyObject key) {
IRubyObject value = (IRubyObject) valueMap.get(key);
- return value != null ? value : callMethod("default", new IRubyObject[] {key});
+ return value != null ? value : callMethod(getRuntime().getCurrentContext(), "default", new IRubyObject[] {key});
}
public IRubyObject fetch(IRubyObject[] args) {
23 src/org/jruby/RubyIO.java
View
@@ -41,6 +41,7 @@
import java.lang.ref.WeakReference;
import java.nio.channels.Channel;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.IOHandler;
import org.jruby.util.IOHandlerJavaIO;
@@ -499,7 +500,7 @@ public IRubyObject write(IRubyObject obj) {
*/
public IRubyObject addString(IRubyObject anObject) {
// Claims conversion is done via 'to_s' in docs.
- IRubyObject strObject = anObject.callMethod("to_s");
+ IRubyObject strObject = anObject.callMethod(getRuntime().getCurrentContext(), "to_s");
write(strObject);
@@ -588,8 +589,9 @@ public RubyFixnum pos_set(IRubyObject newPosition) {
*
*/
public IRubyObject print(IRubyObject[] args) {
+ ThreadContext context = getRuntime().getCurrentContext();
if (args.length == 0) {
- args = new IRubyObject[] { getRuntime().getCurrentContext().getLastline() };
+ args = new IRubyObject[] { context.getLastline() };
}
IRubyObject fs = getRuntime().getGlobalVariables().get("$,");
@@ -597,16 +599,16 @@ public IRubyObject print(IRubyObject[] args) {
for (int i = 0; i < args.length; i++) {
if (i > 0 && !fs.isNil()) {
- callMethod("write", fs);
+ callMethod(context, "write", fs);
}
if (args[i].isNil()) {
- callMethod("write", getRuntime().newString("nil"));
+ callMethod(context, "write", getRuntime().newString("nil"));
} else {
- callMethod("write", args[i]);
+ callMethod(context, "write", args[i]);
}
}
if (!rs.isNil()) {
- callMethod("write", rs);
+ callMethod(context, "write", rs);
}
return getRuntime().getNil();
@@ -614,7 +616,7 @@ public IRubyObject print(IRubyObject[] args) {
public IRubyObject printf(IRubyObject[] args) {
checkArgumentCount(args, 1, -1);
- callMethod("write", RubyKernel.sprintf(this, args));
+ callMethod(getRuntime().getCurrentContext(), "write", RubyKernel.sprintf(this, args));
return getRuntime().getNil();
}
@@ -633,7 +635,7 @@ public IRubyObject putc(IRubyObject object) {
} else if (object.isKindOf(getRuntime().getClass("Fixnum"))){
c = RubyNumeric.fix2int(object);
} else { // What case will this work for?
- c = RubyNumeric.fix2int(object.callMethod("to_i"));
+ c = RubyNumeric.fix2int(object.callMethod(getRuntime().getCurrentContext(), "to_i"));
}
try {
@@ -862,8 +864,9 @@ public IRubyObject fcntl(IRubyObject cmd, IRubyObject arg) throws IOException {
public IRubyObject puts(IRubyObject[] args) {
checkArgumentCount(args, 0, -1);
+ ThreadContext context = getRuntime().getCurrentContext();
if (args.length == 0) {
- callMethod("write", getRuntime().newString("\n"));
+ callMethod(context, "write", getRuntime().newString("\n"));
return getRuntime().getNil();
}
@@ -877,7 +880,7 @@ public IRubyObject puts(IRubyObject[] args) {
} else {
line = args[i].toString();
}
- callMethod("write", getRuntime().newString(line+
+ callMethod(context, "write", getRuntime().newString(line+
(line.endsWith("\n") ? "" : "\n")));
}
return getRuntime().getNil();
33 src/org/jruby/RubyInteger.java
View
@@ -33,6 +33,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
/** Implementation of the Integer class.
@@ -64,13 +65,14 @@ public RubyString chr() {
// TODO: Make callCoerced work in block context...then fix downto, step, and upto.
public IRubyObject downto(IRubyObject to) {
+ ThreadContext context = getRuntime().getCurrentContext();
RubyNumeric i = this;
while (true) {
- if (i.callMethod("<", to).isTrue()) {
+ if (i.callMethod(context, "<", to).isTrue()) {
break;
}
- getRuntime().getCurrentContext().yield(i);
- i = (RubyNumeric) i.callMethod("-", RubyFixnum.one(getRuntime()));
+ context.yield(i);
+ i = (RubyNumeric) i.callMethod(context, "-", RubyFixnum.one(getRuntime()));
}
return this;
}
@@ -86,46 +88,49 @@ public IRubyObject step(IRubyObject to, IRubyObject step) {
throw getRuntime().newArgumentError("step cannot be 0");
}
+ ThreadContext context = getRuntime().getCurrentContext();
String cmp = "<";
- if (((RubyBoolean) step.callMethod("<", getRuntime().newFixnum(0))).isFalse()) {
+ if (((RubyBoolean) step.callMethod(context, "<", getRuntime().newFixnum(0))).isFalse()) {
cmp = ">";
}
while (true) {
- if (i.callMethod(cmp, test).isTrue()) {
+ if (i.callMethod(context, cmp, test).isTrue()) {
break;
}
- getRuntime().getCurrentContext().yield(i);
- i = (RubyNumeric) i.callMethod("+", step);
+ context.yield(i);
+ i = (RubyNumeric) i.callMethod(context, "+", step);
}
return this;
}
public IRubyObject times() {
+ ThreadContext context = getRuntime().getCurrentContext();
RubyNumeric i = RubyFixnum.zero(getRuntime());
while (true) {
- if (!i.callMethod("<", this).isTrue()) {
+ if (!i.callMethod(context, "<", this).isTrue()) {
break;
}
- getRuntime().getCurrentContext().yield(i);
- i = (RubyNumeric) i.callMethod("+", RubyFixnum.one(getRuntime()));
+ context.yield(i);
+ i = (RubyNumeric) i.callMethod(context, "+", RubyFixnum.one(getRuntime()));
}
return this;
}
public IRubyObject next() {
- return callMethod("+", RubyFixnum.one(getRuntime()));
+ return callMethod(getRuntime().getCurrentContext(), "+", RubyFixnum.one(getRuntime()));
}
public IRubyObject upto(IRubyObject to) {
+ ThreadContext context = getRuntime().getCurrentContext();
RubyNumeric test = (RubyNumeric) to;
RubyNumeric i = this;
while (true) {
- if (i.callMethod(">", test).isTrue()) {
+ if (i.callMethod(context, ">", test).isTrue()) {
break;
}
- getRuntime().getCurrentContext().yield(i);
- i = (RubyNumeric) i.callMethod("+", RubyFixnum.one(getRuntime()));
+ context.yield(i);
+ i = (RubyNumeric) i.callMethod(context, "+", RubyFixnum.one(getRuntime()));
}
return this;
}
29 src/org/jruby/RubyKernel.java
View
@@ -218,9 +218,9 @@ public static IRubyObject method_missing(IRubyObject recv, IRubyObject[] args) {
}
String name = args[0].asSymbol();
- String description = recv.callMethod("inspect").toString();
- boolean noClass = description.length() > 0 && description.charAt(0) == '#';
ThreadContext tc = runtime.getCurrentContext();
+ String description = recv.callMethod(tc, "inspect").toString();
+ boolean noClass = description.length() > 0 && description.charAt(0) == '#';
Visibility lastVis = tc.getLastVisibility();
CallType lastCallType = tc.getLastCallType();
String format = lastVis.errorMessageFormat(lastCallType, name);
@@ -283,7 +283,7 @@ public static IRubyObject new_array(IRubyObject recv, IRubyObject object) {
}
// Strange that Ruby has custom code here and not convertToTypeWithCheck equivalent.
- value = object.callMethod("to_a");
+ value = object.callMethod(recv.getRuntime().getCurrentContext(), "to_a");
if (value.getMetaClass() != recv.getRuntime().getClass("Array")) {
throw recv.getRuntime().newTypeError("`to_a' did not return Array");
@@ -294,15 +294,15 @@ public static IRubyObject new_array(IRubyObject recv, IRubyObject object) {
}
public static IRubyObject new_float(IRubyObject recv, IRubyObject object) {
- return object.callMethod("to_f");
+ return object.callMethod(recv.getRuntime().getCurrentContext(), "to_f");
}
public static IRubyObject new_integer(IRubyObject recv, IRubyObject object) {
- return object.callMethod("to_i");
+ return object.callMethod(recv.getRuntime().getCurrentContext(), "to_i");
}
public static IRubyObject new_string(IRubyObject recv, IRubyObject object) {
- return object.callMethod("to_s");
+ return object.callMethod(recv.getRuntime().getCurrentContext(), "to_s");
}
@@ -311,8 +311,9 @@ public static IRubyObject p(IRubyObject recv, IRubyObject[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i] != null) {
- defout.callMethod("write", args[i].callMethod("inspect"));
- defout.callMethod("write", recv.getRuntime().newString("\n"));
+ ThreadContext context = recv.getRuntime().getCurrentContext();
+ defout.callMethod(context, "write", args[i].callMethod(context, "inspect"));
+ defout.callMethod(context, "write", recv.getRuntime().newString("\n"));
}
}
return recv.getRuntime().getNil();
@@ -321,7 +322,7 @@ public static IRubyObject p(IRubyObject recv, IRubyObject[] args) {
public static IRubyObject puts(IRubyObject recv, IRubyObject[] args) {
IRubyObject defout = recv.getRuntime().getGlobalVariables().get("$>");
- defout.callMethod("puts", args);
+ defout.callMethod(recv.getRuntime().getCurrentContext(), "puts", args);
return recv.getRuntime().getNil();
}
@@ -329,7 +330,7 @@ public static IRubyObject puts(IRubyObject recv, IRubyObject[] args) {
public static IRubyObject print(IRubyObject recv, IRubyObject[] args) {
IRubyObject defout = recv.getRuntime().getGlobalVariables().get("$>");
- defout.callMethod("print", args);
+ defout.callMethod(recv.getRuntime().getCurrentContext(), "print", args);
return recv.getRuntime().getNil();
}
@@ -343,7 +344,7 @@ public static IRubyObject printf(IRubyObject recv, IRubyObject[] args) {
args = ArgsUtil.popArray(args);
}
- defout.callMethod("write", RubyKernel.sprintf(recv, args));
+ defout.callMethod(recv.getRuntime().getCurrentContext(), "write", RubyKernel.sprintf(recv, args));
}
return recv.getRuntime().getNil();
@@ -559,7 +560,7 @@ public static IRubyObject sprintf(IRubyObject recv, IRubyObject[] args) {
RubyArray newArgs = recv.getRuntime().newArray(args);
newArgs.shift();
- return ((StringMetaClass)str.getMetaClass()).format.call(recv.getRuntime(), str, str.getMetaClass(), "%", new IRubyObject[] {newArgs}, false);
+ return ((StringMetaClass)str.getMetaClass()).format.call(recv.getRuntime().getCurrentContext(), str, str.getMetaClass(), "%", new IRubyObject[] {newArgs}, false);
}
public static IRubyObject raise(IRubyObject recv, IRubyObject[] args) {
@@ -583,13 +584,13 @@ public static IRubyObject raise(IRubyObject recv, IRubyObject[] args) {
if (!args[0].respondsTo("exception")) {
throw runtime.newTypeError("exception class/object expected");
}
- exception = args[0].callMethod("exception");
+ exception = args[0].callMethod(recv.getRuntime().getCurrentContext(), "exception");
} else {
if (!args[0].respondsTo("exception")) {
throw runtime.newTypeError("exception class/object expected");
}
- exception = args[0].callMethod("exception", args[1]);
+ exception = args[0].callMethod(recv.getRuntime().getCurrentContext(), "exception", args[1]);
}
if (!exception.isKindOf(runtime.getClass("Exception"))) {
2  src/org/jruby/RubyMarshal.java
View
@@ -121,7 +121,7 @@ public static IRubyObject load(IRubyObject recv, IRubyObject[] args) {
if (in instanceof RubyIO) {
rawInput = ((RubyIO) in).getInStream();
} else if (in.respondsTo("to_str")) {
- RubyString inString = (RubyString) in.callMethod("to_str");
+ RubyString inString = (RubyString) in.callMethod(recv.getRuntime().getCurrentContext(), "to_str");
rawInput = new ByteArrayInputStream(inString.toByteArray());
} else {
throw recv.getRuntime().newTypeError("instance of IO needed");
2  src/org/jruby/RubyMethod.java
View
@@ -115,7 +115,7 @@ public IRubyObject call(IRubyObject[] args) {
tc.setIfBlockAvailable();
try {
// FIXME: should lastClass be implementation module for a Method?
- return method.call(getRuntime(), receiver, implementationModule, methodName, args, false);
+ return method.call(tc, receiver, implementationModule, methodName, args, false);
} finally {
tc.clearIfBlockAvailable();
}
32 src/org/jruby/RubyModule.java
View
@@ -350,7 +350,7 @@ public synchronized void includeModule(IRubyObject arg) {
// cnutter: removed iterative inclusion of module's superclasses, because it included them in reverse order
// see RubyModule.newIncludeClass for replacement
- module.callMethod("included", this);
+ module.callMethod(getRuntime().getCurrentContext(), "included", this);
}
public void defineMethod(String name, Callback method) {
@@ -569,7 +569,7 @@ private IRubyObject getConstantInner(String name, boolean exclude) {
break;
}
- return callMethod("const_missing", RubySymbol.newSymbol(getRuntime(), name));
+ return callMethod(getRuntime().getCurrentContext(), "const_missing", RubySymbol.newSymbol(getRuntime(), name));
}
/**
@@ -710,10 +710,10 @@ public IRubyObject removeCvar(IRubyObject name) { // Wrong Parameter ?
}
private void addAccessor(String name, boolean readable, boolean writeable) {
- ThreadContext tc = getRuntime().getCurrentContext();
+ ThreadContext context = getRuntime().getCurrentContext();
// Check the visibility of the previous frame, which will be the frame in which the class is being eval'ed
- Visibility attributeScope = tc.getCurrentVisibility();
+ Visibility attributeScope = context.getCurrentVisibility();
if (attributeScope.isPrivate()) {
//FIXME warning
} else if (attributeScope.isModuleFunction()) {
@@ -736,13 +736,13 @@ public Arity getArity() {
return Arity.noArguments();
}
});
- callMethod("method_added", RubySymbol.newSymbol(getRuntime(), name));
+ callMethod(context, "method_added", RubySymbol.newSymbol(getRuntime(), name));
}
if (writeable) {
name = name + "=";
defineMethod(name, new Callback() {
public IRubyObject execute(IRubyObject self, IRubyObject[] args) {
- IRubyObject[] fargs = runtime.getCurrentContext().getFrameArgs();
+ IRubyObject[] fargs = self.getRuntime().getCurrentContext().getFrameArgs();
if (fargs.length != 1) {
throw runtime.newArgumentError("wrong # of arguments(" + fargs.length + "for 1)");
@@ -755,7 +755,7 @@ public Arity getArity() {
return Arity.singleArgument();
}
});
- callMethod("method_added", RubySymbol.newSymbol(getRuntime(), name));
+ callMethod(context, "method_added", RubySymbol.newSymbol(getRuntime(), name));
}
}
@@ -844,8 +844,8 @@ public IRubyObject define_method(IRubyObject[] args) {
IRubyObject body;
String name = args[0].asSymbol();
ICallable newMethod = null;
- ThreadContext tc = getRuntime().getCurrentContext();
- Visibility visibility = tc.getCurrentVisibility();
+ ThreadContext context = getRuntime().getCurrentContext();
+ Visibility visibility = context.getCurrentVisibility();
if (visibility.isModuleFunction()) {
visibility = Visibility.PRIVATE;
@@ -874,12 +874,12 @@ public IRubyObject define_method(IRubyObject[] args) {
addMethod(name, newMethod);
RubySymbol symbol = RubySymbol.newSymbol(getRuntime(), name);
- if (tc.getPreviousVisibility().isModuleFunction()) {
+ if (context.getPreviousVisibility().isModuleFunction()) {
getSingletonClass().addMethod(name, new WrapperCallable(getSingletonClass(), newMethod, Visibility.PUBLIC));
- callMethod("singleton_method_added", symbol);
+ callMethod(context, "singleton_method_added", symbol);
}
- callMethod("method_added", symbol);
+ callMethod(context, "method_added", symbol);
return body;
}
@@ -1369,7 +1369,7 @@ public IRubyObject extend_object(IRubyObject obj) {
*/
public RubyModule include(IRubyObject[] modules) {
for (int i = modules.length - 1; i >= 0; i--) {
- modules[i].callMethod("append_features", this);
+ modules[i].callMethod(getRuntime().getCurrentContext(), "append_features", this);
}
return this;
@@ -1426,9 +1426,11 @@ public RubyModule module_function(IRubyObject[] args) {
if (getRuntime().getSafeLevel() >= 4 && !isTaint()) {
throw getRuntime().newSecurityError("Insecure: can't change method visibility");
}
+
+ ThreadContext context = getRuntime().getCurrentContext();
if (args.length == 0) {
- getRuntime().getCurrentContext().setCurrentVisibility(Visibility.MODULE_FUNCTION);
+ context.setCurrentVisibility(Visibility.MODULE_FUNCTION);
} else {
setMethodVisibility(args, Visibility.PRIVATE);
@@ -1437,7 +1439,7 @@ public RubyModule module_function(IRubyObject[] args) {
ICallable method = searchMethod(name);
assert !method.isUndefined() : "undefined method '" + name + "'";
getSingletonClass().addMethod(name, new WrapperCallable(getSingletonClass(), method, Visibility.PUBLIC));
- callMethod("singleton_method_added", RubySymbol.newSymbol(getRuntime(), name));
+ callMethod(context, "singleton_method_added", RubySymbol.newSymbol(getRuntime(), name));
}
}
return this;
25 src/org/jruby/RubyNumeric.java
View
@@ -36,6 +36,7 @@
import java.math.BigInteger;
import org.jruby.exceptions.RaiseException;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
/**
@@ -211,7 +212,7 @@ public static RubyFloat str2fnum(IRuby runtime, RubyString arg) {
IRubyObject result;
try {
- result = other.callMethod("coerce", this);
+ result = other.callMethod(getRuntime().getCurrentContext(), "coerce", this);
} catch (RaiseException e) {
if (error) {
throw getRuntime().newTypeError(other.getMetaClass().getName() +
@@ -231,7 +232,7 @@ public static RubyFloat str2fnum(IRuby runtime, RubyString arg) {
protected IRubyObject callCoerced(String method, IRubyObject other) {
IRubyObject[] args = getCoerced(other, true);
- return args[0].callMethod(method, args[1]);
+ return args[0].callMethod(getRuntime().getCurrentContext(), method, args[1]);
}
public RubyNumeric asNumeric() {
@@ -269,7 +270,7 @@ public IRubyObject op_uplus() {
public IRubyObject op_uminus() {
RubyArray coerce = (RubyArray) coerce(RubyFixnum.zero(getRuntime()));
- return (RubyNumeric) coerce.entry(0).callMethod("-", coerce.entry(1));
+ return (RubyNumeric) coerce.entry(0).callMethod(getRuntime().getCurrentContext(), "-", coerce.entry(1));
}
public IRubyObject cmp(IRubyObject other) {
@@ -283,7 +284,7 @@ public IRubyObject cmp(IRubyObject other) {
public IRubyObject divmod(IRubyObject other) {
if (other instanceof RubyNumeric) {
RubyNumeric denominator = (RubyNumeric) other;
- RubyNumeric div = (RubyNumeric) callMethod("/", denominator);
+ RubyNumeric div = (RubyNumeric) callMethod(getRuntime().getCurrentContext(), "/", denominator);
if (div instanceof RubyFloat) {
double d = Math.floor(((RubyFloat) div).getValue());
if (((RubyFloat) div).getValue() > d) {
@@ -302,7 +303,7 @@ public IRubyObject divmod(IRubyObject other) {
*/
public IRubyObject modulo(IRubyObject other) {
if (other instanceof RubyNumeric) {
- return (RubyNumeric) callMethod("%", other);
+ return (RubyNumeric) callMethod(getRuntime().getCurrentContext(), "%", other);
}
return callCoerced("modulo", other);
@@ -316,10 +317,11 @@ public IRubyObject remainder(IRubyObject other) {
IRubyObject mod = modulo(other);
final RubyNumeric zero = RubyFixnum.zero(getRuntime());
- if (callMethod("<", zero).isTrue() && other.callMethod(">", zero).isTrue() ||
- callMethod(">", zero).isTrue() && other.callMethod("<", zero).isTrue()) {
+ ThreadContext context = getRuntime().getCurrentContext();
+ if (callMethod(context, "<", zero).isTrue() && other.callMethod(context, ">", zero).isTrue() ||
+ callMethod(context, ">", zero).isTrue() && other.callMethod(context, "<", zero).isTrue()) {
- return (RubyNumeric) mod.callMethod("-", other);
+ return (RubyNumeric) mod.callMethod(context, "-", other);
}
return mod;
@@ -372,8 +374,9 @@ public RubyBoolean eql(IRubyObject other) {
*
*/
public RubyNumeric abs() {
- if (callMethod("<", RubyFixnum.zero(getRuntime())).isTrue()) {
- return (RubyNumeric) callMethod("-@");
+ ThreadContext context = getRuntime().getCurrentContext();
+ if (callMethod(context, "<", RubyFixnum.zero(getRuntime())).isTrue()) {
+ return (RubyNumeric) callMethod(context, "-@");
}
return this;
}
@@ -397,7 +400,7 @@ public RubyBoolean zero_p() {
*
*/
public IRubyObject nonzero_p() {
- if (callMethod("zero?").isTrue()) {
+ if (callMethod(getRuntime().getCurrentContext(), "zero?").isTrue()) {
return getRuntime().getNil();
}
return this;
85 src/org/jruby/RubyObject.java
View
@@ -132,11 +132,11 @@ public static void puts(Object obj) {
* HashMap object underlying RubyHash.
*/
public boolean equals(Object other) {
- return other == this || other instanceof IRubyObject && callMethod("==", (IRubyObject) other).isTrue();
+ return other == this || other instanceof IRubyObject && callMethod(getRuntime().getCurrentContext(), "==", (IRubyObject) other).isTrue();
}
public String toString() {
- return ((RubyString) callMethod("to_s")).toString();
+ return ((RubyString) callMethod(getRuntime().getCurrentContext(), "to_s")).toString();
}
/** Getter for property ruby.
@@ -296,7 +296,7 @@ public void initCopy(IRubyObject original) {
setInstanceVariables(new HashMap(original.getInstanceVariables()));
- callMethod("initialize_copy", original);
+ callMethod(getRuntime().getCurrentContext(), "initialize_copy", original);
}
/** OBJ_INFECT
@@ -311,37 +311,37 @@ public IRubyObject infectBy(IRubyObject obj) {
/**
*
*/
- public IRubyObject callMethod(String name, IRubyObject[] args) {
- return callMethod(getMetaClass(), name, args, CallType.FUNCTIONAL);
+ public IRubyObject callMethod(ThreadContext context, String name, IRubyObject[] args) {
+ return callMethod(context, getMetaClass(), name, args, CallType.FUNCTIONAL);
}
/**
*
*/
- public IRubyObject callMethod(String name, IRubyObject[] args,
+ public IRubyObject callMethod(ThreadContext context, String name, IRubyObject[] args,
CallType callType) {
- return callMethod(getMetaClass(), name, args, callType);
+ return callMethod(context, getMetaClass(), name, args, callType);
}
/**
*
*/
- public IRubyObject callMethod(RubyModule context, String name, IRubyObject[] args,
+ public IRubyObject callMethod(ThreadContext context, RubyModule type, String name, IRubyObject[] args,
CallType callType) {
assert args != null;
ICallable method = null;
- method = context.searchMethod(name);
+ method = type.searchMethod(name);
if (method.isUndefined() ||
!(name.equals("method_missing") ||
- method.isCallableFrom(getRuntime().getCurrentContext().getFrameSelf(), callType))) {
+ method.isCallableFrom(context.getFrameSelf(), callType))) {
if (callType == CallType.SUPER) {
throw getRuntime().newNameError("super: no superclass method '" + name + "'");
}
// store call information so method_missing impl can use it
- getRuntime().getCurrentContext().setLastCallStatus(method.getVisibility(), callType);
+ context.setLastCallStatus(method.getVisibility(), callType);
if (name.equals("method_missing")) {
return RubyKernel.method_missing(this, args);
@@ -351,13 +351,13 @@ public IRubyObject callMethod(RubyModule context, String name, IRubyObject[] arg
System.arraycopy(args, 0, newArgs, 1, args.length);
newArgs[0] = RubySymbol.newSymbol(getRuntime(), name);
- return callMethod("method_missing", newArgs);
+ return callMethod(context, "method_missing", newArgs);
}
RubyModule implementer = null;
if (method.needsImplementer()) {
// modules are included with a shim class; we must find that shim to handle super() appropriately
- implementer = context.findImplementer(method.getImplementationClass());
+ implementer = type.findImplementer(method.getImplementationClass());
} else {
// classes are directly in the hierarchy, so no special logic is necessary for implementer
implementer = method.getImplementationClass();
@@ -368,21 +368,21 @@ public IRubyObject callMethod(RubyModule context, String name, IRubyObject[] arg
name = originalName;
}
- IRubyObject result = method.call(getRuntime(), this, implementer, name, args, false);
+ IRubyObject result = method.call(context, this, implementer, name, args, false);
return result;
}
- public IRubyObject callMethod(String name) {
- return callMethod(name, IRubyObject.NULL_ARRAY);
+ public IRubyObject callMethod(ThreadContext context, String name) {
+ return callMethod(context, name, IRubyObject.NULL_ARRAY);
}
/**
* rb_funcall
*
*/
- public IRubyObject callMethod(String name, IRubyObject arg) {
- return callMethod(name, new IRubyObject[] { arg });
+ public IRubyObject callMethod(ThreadContext context, String name, IRubyObject arg) {
+ return callMethod(context, name, new IRubyObject[] { arg });
}
public IRubyObject instance_variable_get(IRubyObject var) {
@@ -442,24 +442,25 @@ public Iterator instanceVariableNames() {
public IRubyObject eval(Node n) {
//return new EvaluationState(getRuntime(), this).begin(n);
// need to continue evaluation with a new self, so save the old one (should be a stack?)
- EvaluationState state = getRuntime().getCurrentContext().getFrameEvalState();
+ ThreadContext context = getRuntime().getCurrentContext();
+ EvaluationState state = context.getFrameEvalState();
IRubyObject oldSelf = state.getSelf();
state.setSelf(this);
try {
- return state.begin(n);
+ return state.begin(context, n);
} finally {
state.setSelf(oldSelf);
}
}
public void callInit(IRubyObject[] args) {
- ThreadContext tc = getRuntime().getCurrentContext();
+ ThreadContext context = getRuntime().getCurrentContext();
- tc.setIfBlockAvailable();
+ context.setIfBlockAvailable();
try {
- callMethod("initialize", args);
+ callMethod(context, "initialize", args);
} finally {
- tc.clearIfBlockAvailable();
+ context.clearIfBlockAvailable();
}
}
@@ -514,7 +515,7 @@ public IRubyObject convertToType(String targetType, String convertMethod, boolea
return getRuntime().getNil();
}
- return callMethod(convertMethod);
+ return callMethod(getRuntime().getCurrentContext(), convertMethod);
}
public RubyArray convertToArray() {
@@ -697,7 +698,7 @@ public IRubyObject evalWithBinding(IRubyObject src, IRubyObject scope, String fi
oldSelf = state.getSelf();
state.setSelf(newSelf);
- result = state.begin(getRuntime().parse(src.toString(), file));
+ result = state.begin(threadContext, getRuntime().parse(src.toString(), file));
} finally {
// return the eval state to its original self
state.setSelf(oldSelf);
@@ -733,7 +734,7 @@ public IRubyObject evalSimple(IRubyObject src, String file) {
state.setSelf(this);
- result = state.begin(getRuntime().parse(src.toString(), file));
+ result = state.begin(threadContext, getRuntime().parse(src.toString(), file));
} finally {
// return the eval state to its original self
state.setSelf(oldSelf);
@@ -809,7 +810,7 @@ public RubyFixnum hash() {
}
public final int hashCode() {
- return (int) RubyNumeric.fix2int(callMethod("hash"));
+ return (int) RubyNumeric.fix2int(callMethod(getRuntime().getCurrentContext(), "hash"));
}
/** rb_obj_type
@@ -846,7 +847,7 @@ public IRubyObject display(IRubyObject[] args) {
IRubyObject port = args.length == 0
? getRuntime().getGlobalVariables().get("$>") : args[0];
- port.callMethod("write", this);
+ port.callMethod(getRuntime().getCurrentContext(), "write", this);
return getRuntime().getNil();
}
@@ -855,7 +856,7 @@ public IRubyObject display(IRubyObject[] args) {
*
*/
public IRubyObject dup() {
- IRubyObject dup = callMethod("clone");
+ IRubyObject dup = callMethod(getRuntime().getCurrentContext(), "clone");
if (!dup.getClass().equals(getClass())) {
throw getRuntime().newTypeError("duplicated object must be same type");
}
@@ -941,7 +942,7 @@ public IRubyObject inspect() {
// }
// return rb_funcall(obj, rb_intern("to_s"), 0, 0);
// }
- return callMethod("to_s");
+ return callMethod(getRuntime().getCurrentContext(), "to_s");
}
/** rb_obj_is_instance_of
@@ -1064,9 +1065,11 @@ public IRubyObject extend(IRubyObject[] args) {
}
}
+ ThreadContext context = getRuntime().getCurrentContext();
+
for (int i = 0; i < args.length; i++) {
- args[i].callMethod("extend_object", this);
- args[i].callMethod("extended", this);
+ args[i].callMethod(context, "extend_object", this);
+ args[i].callMethod(context, "extended", this);
}
return this;
}
@@ -1084,11 +1087,11 @@ public IRubyObject method_missing(IRubyObject[] args) {
}
String name = args[0].asSymbol();
- String description = callMethod("inspect").toString();
+ ThreadContext context = getRuntime().getCurrentContext();
+ String description = callMethod(context, "inspect").toString();
boolean noClass = description.length() > 0 && description.charAt(0) == '#';
- ThreadContext tc = getRuntime().getCurrentContext();
- Visibility lastVis = tc.getLastVisibility();
- CallType lastCallType = tc.getLastCallType();
+ Visibility lastVis = context.getLastVisibility();
+ CallType lastCallType = context.getLastCallType();
String format = lastVis.errorMessageFormat(lastCallType, name);
String msg = new PrintfFormat(format).sprintf(new Object[] { name, description,
noClass ? "" : ":", noClass ? "" : getType().getName()});
@@ -1128,13 +1131,13 @@ public IRubyObject send(IRubyObject[] args) {
IRubyObject[] newArgs = new IRubyObject[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);
- ThreadContext tc = getRuntime().getCurrentContext();
+ ThreadContext context = getRuntime().getCurrentContext();
- tc.setIfBlockAvailable();
+ context.setIfBlockAvailable();
try {
- return callMethod(name, newArgs, CallType.FUNCTIONAL);
+ return callMethod(context, name, newArgs, CallType.FUNCTIONAL);
} finally {
- tc.clearIfBlockAvailable();
+ context.clearIfBlockAvailable();
}
}
6 src/org/jruby/RubyPrecision.java
View
@@ -63,14 +63,14 @@ public static IRubyObject append_features(IRubyObject receiver, IRubyObject incl
}
public static IRubyObject prec(IRubyObject receiver, IRubyObject type) {
- return type.callMethod("induced_from", receiver);
+ return type.callMethod(receiver.getRuntime().getCurrentContext(), "induced_from", receiver);
}
public static IRubyObject prec_i(IRubyObject receiver) {
- return receiver.getRuntime().getClass("Integer").callMethod("induced_from", receiver);
+ return receiver.getRuntime().getClass("Integer").callMethod(receiver.getRuntime().getCurrentContext(), "induced_from", receiver);
}
public static IRubyObject prec_f(IRubyObject receiver) {
- return receiver.getRuntime().getClass("Float").callMethod("induced_from", receiver);
+ return receiver.getRuntime().getClass("Float").callMethod(receiver.getRuntime().getCurrentContext(), "induced_from", receiver);
}
}
54 src/org/jruby/RubyRange.java
View
@@ -57,7 +57,7 @@ public RubyRange(IRuby runtime) {
public void init(IRubyObject aBegin, IRubyObject aEnd, RubyBoolean aIsExclusive) {
if (!(aBegin instanceof RubyFixnum && aEnd instanceof RubyFixnum)) {
try {
- aBegin.callMethod("<=>", aEnd);
+ aBegin.callMethod(getRuntime().getCurrentContext(), "<=>", aEnd);
} catch (RaiseException rExcptn) {
throw getRuntime().newArgumentError("bad value for range");
}
@@ -200,9 +200,10 @@ public IRubyObject last() {
public RubyFixnum hash() {
+ ThreadContext context = getRuntime().getCurrentContext();
long baseHash = (isExclusive ? 1 : 0);
- long beginHash = ((RubyFixnum) begin.callMethod("hash")).getLongValue();
- long endHash = ((RubyFixnum) end.callMethod("hash")).getLongValue();
+ long beginHash = ((RubyFixnum) begin.callMethod(context, "hash")).getLongValue();
+ long endHash = ((RubyFixnum) end.callMethod(context, "hash")).getLongValue();
long hash = baseHash;
hash = hash ^ (beginHash << 1);
@@ -213,8 +214,9 @@ public RubyFixnum hash() {
}
private IRubyObject asString(String stringMethod) {
- RubyString begStr = (RubyString) begin.callMethod(stringMethod);
- RubyString endStr = (RubyString) end.callMethod(stringMethod);
+ ThreadContext context = getRuntime().getCurrentContext();
+ RubyString begStr = (RubyString) begin.callMethod(context, stringMethod);
+ RubyString endStr = (RubyString) end.callMethod(context, stringMethod);
return begStr.cat(isExclusive ? "..." : "..").concat(endStr);
}
@@ -234,7 +236,8 @@ public RubyBoolean exclude_end_p() {
public RubyFixnum length() {
long size = 0;
- if (begin.callMethod(">", end).isTrue()) {
+ ThreadContext context = getRuntime().getCurrentContext();
+ if (begin.callMethod(context, ">", end).isTrue()) {
return getRuntime().newFixnum(0);
}
@@ -247,12 +250,12 @@ public RubyFixnum length() {
IRubyObject currentObject = begin;
String compareMethod = isExclusive ? "<" : "<=";
- while (currentObject.callMethod(compareMethod, end).isTrue()) {
+ while (currentObject.callMethod(context, compareMethod, end).isTrue()) {
size++;
if (currentObject.equals(end)) {
break;
}
- currentObject = currentObject.callMethod("succ");
+ currentObject = currentObject.callMethod(context, "succ");
}
}
return getRuntime().newFixnum(size);
@@ -288,30 +291,30 @@ public IRubyObject each() {
((RubyString) begin).upto(end, isExclusive);
} else if (begin.isKindOf(getRuntime().getClass("Numeric"))) {
if (!isExclusive) {
- end = end.callMethod("+", RubyFixnum.one(getRuntime()));
+ end = end.callMethod(tc, "+", RubyFixnum.one(getRuntime()));
}
- while (begin.callMethod("<", end).isTrue()) {
+ while (begin.callMethod(tc, "<", end).isTrue()) {
tc.yield(begin);
- begin = begin.callMethod("+", RubyFixnum.one(getRuntime()));
+ begin = begin.callMethod(tc, "+", RubyFixnum.one(getRuntime()));
}
} else {
IRubyObject v = begin;
if (isExclusive) {
- while (v.callMethod("<", end).isTrue()) {
+ while (v.callMethod(tc, "<", end).isTrue()) {
if (v.equals(end)) {
break;
}
tc.yield(v);
- v = v.callMethod("succ");
+ v = v.callMethod(tc, "succ");
}
} else {
- while (v.callMethod("<=", end).isTrue()) {
+ while (v.callMethod(tc, "<=", end).isTrue()) {
tc.yield(v);
if (v.equals(end)) {
break;
}
- v = v.callMethod("succ");
+ v = v.callMethod(tc, "succ");
}
}
}
@@ -330,18 +333,19 @@ public IRubyObject step(IRubyObject[] args) {
throw getRuntime().newArgumentError("step can't be negative");
}
+ ThreadContext context = getRuntime().getCurrentContext();
if (begin instanceof RubyNumeric && end instanceof RubyNumeric) {
RubyFixnum stepNum = getRuntime().newFixnum(stepSize);
- while (currentObject.callMethod(compareMethod, end).isTrue()) {
- getRuntime().getCurrentContext().yield(currentObject);
- currentObject = currentObject.callMethod("+", stepNum);
+ while (currentObject.callMethod(context, compareMethod, end).isTrue()) {
+ context.yield(currentObject);
+ currentObject = currentObject.callMethod(context, "+", stepNum);
}
} else {
- while (currentObject.callMethod(compareMethod, end).isTrue()) {
- getRuntime().getCurrentContext().yield(currentObject);
+ while (currentObject.callMethod(context, compareMethod, end).isTrue()) {
+ context.yield(currentObject);
for (int i = 0; i < stepSize; i++) {
- currentObject = currentObject.callMethod("succ");
+ currentObject = currentObject.callMethod(context, "succ");
}
}
}
@@ -354,14 +358,15 @@ public RubyArray to_a() {
String compareMethod = isExclusive ? "<" : "<=";
RubyArray array = getRuntime().newArray();
- while (currentObject.callMethod(compareMethod, end).isTrue()) {
+ ThreadContext context = getRuntime().getCurrentContext();
+ while (currentObject.callMethod(context, compareMethod, end).isTrue()) {
array.append(currentObject);
if (currentObject.equals(end)) {
break;
}
- currentObject = currentObject.callMethod("succ");
+ currentObject = currentObject.callMethod(context, "succ");
}
return array;
@@ -372,7 +377,8 @@ public RubyBoolean include_p(IRubyObject obj) {
String compareMethod = isExclusive ? ">" : ">=";
IRubyObject[] arg = new IRubyObject[]{ obj };
IRubyObject f = obj.getRuntime().getFalse();
+ ThreadContext context = getRuntime().getCurrentContext();
return f.getRuntime().newBoolean(
- f != first().callMethod("<=", arg) && f != last().callMethod(compareMethod, arg));
+ f != first().callMethod(context, "<=", arg) && f != last().callMethod(context, compareMethod, arg));
}
}
12 src/org/jruby/RubyString.java
View
@@ -65,13 +65,13 @@ public StringMethod(RubyModule implementationClass, Arity arity, Visibility visi
super(implementationClass, arity, visibility);
}
- public IRubyObject internalCall(IRuby runtime, IRubyObject receiver, RubyModule lastClass, String name, IRubyObject[] args, boolean noSuper) {
+ public IRubyObject internalCall(ThreadContext context, IRubyObject receiver, RubyModule lastClass, String name, IRubyObject[] args, boolean noSuper) {
RubyString s = (RubyString)receiver;
- return invoke(s, args);
+ return invoke(context, s, args);
}
- public abstract IRubyObject invoke(RubyString target, IRubyObject[] args);
+ public abstract IRubyObject invoke(ThreadContext context, RubyString target, IRubyObject[] args);
};
@@ -157,7 +157,7 @@ private boolean sameAs(Object other) {
*/
public static RubyString objAsString(IRubyObject obj) {
return (RubyString) (obj instanceof RubyString ? obj :
- obj.callMethod("to_s"));
+ obj.callMethod(obj.getRuntime().getCurrentContext(), "to_s"));
}
/** rb_str_cmp
@@ -269,7 +269,7 @@ public IRubyObject casecmp(IRubyObject other) {
RubyString thisLCString = getRuntime().newString(toString().toLowerCase());
RubyString lcString = getRuntime().newString(stringValue(other).toString().toLowerCase());
- return ((StringMetaClass)thisLCString.getMetaClass()).op_cmp.call(getRuntime(), thisLCString, thisLCString.getMetaClass(), "<=>", new IRubyObject[] {lcString}, false);
+ return ((StringMetaClass)thisLCString.getMetaClass()).op_cmp.call(getRuntime().getCurrentContext(), thisLCString, thisLCString.getMetaClass(), "<=>", new IRubyObject[] {lcString}, false);
}
/** rb_str_match
@@ -281,7 +281,7 @@ public IRubyObject match(IRubyObject other) {
} else if (other instanceof RubyString) {
return RubyRegexp.newRegexp((RubyString) other, 0, null).match(this);
}
- return other.callMethod("=~", this);
+ return other.callMethod(getRuntime().getCurrentContext(), "=~", this);
}
/** rb_str_match2
2  src/org/jruby/RubyStruct.java
View
@@ -328,7 +328,7 @@ public IRubyObject inspect() {
}
sb.append(member.entry(i).asSymbol()).append("=");
- sb.append(values[i].callMethod("inspect"));
+ sb.append(values[i].callMethod(getRuntime().getCurrentContext(), "inspect"));
}
sb.append('>');
7 src/org/jruby/RubySymbol.java
View
@@ -42,6 +42,7 @@
import org.jruby.internal.runtime.methods.DirectInvocationMethod;
import org.jruby.runtime.Arity;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.MarshalStream;
@@ -63,13 +64,13 @@ public SymbolMethod(RubyModule implementationClass, Arity arity, Visibility visi
super(implementationClass, arity, visibility);
}
- public IRubyObject internalCall(IRuby runtime, IRubyObject receiver, RubyModule lastClass, String name, IRubyObject[] args, boolean noSuper) {
+ public IRubyObject internalCall(ThreadContext context, IRubyObject receiver, RubyModule lastClass, String name, IRubyObject[] args, boolean noSuper) {
RubySymbol s = (RubySymbol)receiver;
- return invoke(s, args);
+ return invoke(context, s, args);
}
- public abstract IRubyObject invoke(RubySymbol target, IRubyObject[] args);
+ public abstract IRubyObject invoke(ThreadContext context, RubySymbol target, IRubyObject[] args);
};
2  src/org/jruby/RubyThread.java
View
@@ -260,7 +260,7 @@ private void pollReceivedExceptions() {
IRubyObject raiseException = receivedException;
receivedException = null;
RubyModule kernelModule = getRuntime().getModule("Kernel");
- kernelModule.callMethod("raise", raiseException);
+ kernelModule.callMethod(getRuntime().getCurrentContext(), "raise", raiseException);
}
}
2  src/org/jruby/RubyTime.java
View
@@ -174,7 +174,7 @@ public IRubyObject op_minus(IRubyObject other) {
}
public IRubyObject same2(IRubyObject other) {
- return (RubyNumeric.fix2int(callMethod("<=>", other)) == 0) ? getRuntime().getTrue() : getRuntime().getFalse();
+ return (RubyNumeric.fix2int(callMethod(getRuntime().getCurrentContext(), "<=>", other)) == 0) ? getRuntime().getTrue() : getRuntime().getFalse();
}
public IRubyObject op_cmp(IRubyObject other) {
11 src/org/jruby/RubyZlib.java
View
@@ -37,6 +37,7 @@
import java.util.zip.GZIPOutputStream;
import org.jruby.runtime.CallbackFactory;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.IOInputStream;
@@ -217,8 +218,9 @@ public static RubyGzipReader newCreate(IRubyObject recv, IRubyObject[] args) {
}
public static IRubyObject open(IRubyObject recv, RubyString filename) throws IOException {
- RubyObject proc = (recv.getRuntime().getCurrentContext().isBlockGiven()) ? (RubyObject)recv.getRuntime().newProc() : (RubyObject)recv.getRuntime().getNil();
- RubyGzipReader io = newInstance(recv,new IRubyObject[]{recv.getRuntime().getClass("File").callMethod("open",new IRubyObject[]{filename,recv.getRuntime().newString("rb")})});
+ ThreadContext context = recv.getRuntime().getCurrentContext();
+ RubyObject proc = (context.isBlockGiven()) ? (RubyObject)recv.getRuntime().newProc() : (RubyObject)recv.getRuntime().getNil();
+ RubyGzipReader io = newInstance(recv,new IRubyObject[]{recv.getRuntime().getClass("File").callMethod(context, "open",new IRubyObject[]{filename,recv.getRuntime().newString("rb")})});
return RubyGzipFile.wrap(recv, io, proc);
}
@@ -435,8 +437,9 @@ public static IRubyObject open(IRubyObject recv, IRubyObject[] args) throws IOEx
}
}
- RubyObject proc = (recv.getRuntime().getCurrentContext().isBlockGiven()) ? (RubyObject)recv.getRuntime().newProc() : (RubyObject)recv.getRuntime().getNil();
- RubyGzipWriter io = newInstance(recv,new IRubyObject[]{recv.getRuntime().getClass("File").callMethod("open",new IRubyObject[]{args[0],recv.getRuntime().newString("wb")}),level,strategy});
+ ThreadContext context = recv.getRuntime().getCurrentContext();
+ RubyObject proc = (context.isBlockGiven()) ? (RubyObject)recv.getRuntime().newProc() : (RubyObject)recv.getRuntime().getNil();
+ RubyGzipWriter io = newInstance(recv,new IRubyObject[]{recv.getRuntime().getClass("File").callMethod(context, "open",new IRubyObject[]{args[0],recv.getRuntime().newString("wb")}),level,strategy});
return RubyGzipFile.wrap(recv, io, proc);
}
2,180 src/org/jruby/ast/executable/InstructionCompiler2.java
View
@@ -1,1084 +1,1096 @@
-/***** BEGIN LICENSE BLOCK *****
- * Version: CPL 1.0/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Common Public
- * License Version 1.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.eclipse.org/legal/cpl-v10.html
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * Copyright (C) 2004-2006 Charles O Nutter <headius@headius.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the CPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the CPL, the GPL or the LGPL.
- ***** END LICENSE BLOCK *****/
-package org.jruby.ast.executable;
-
-import java.util.Iterator;
-
-import org.jruby.IRuby;
-import org.jruby.ast.AliasNode;
-import org.jruby.ast.AndNode;
-import org.jruby.ast.ArgsCatNode;
-import org.jruby.ast.ArgsNode;
-import org.jruby.ast.ArrayNode;
-import org.jruby.ast.BackRefNode;
-import org.jruby.ast.BeginNode;
-import org.jruby.ast.BignumNode;
-import org.jruby.ast.BlockArgNode;
-import org.jruby.ast.BlockNode;
-import org.jruby.ast.BlockPassNode;
-import org.jruby.ast.BreakNode;
-import org.jruby.ast.CallNode;
-import org.jruby.ast.CaseNode;
-import org.jruby.ast.ClassNode;
-import org.jruby.ast.ClassVarAsgnNode;
-import org.jruby.ast.ClassVarDeclNode;
-import org.jruby.ast.ClassVarNode;
-import org.jruby.ast.Colon2Node;
-import org.jruby.ast.Colon3Node;
-import org.jruby.ast.ConstDeclNode;
-import org.jruby.ast.ConstNode;
-import org.jruby.ast.DAsgnNode;
-import org.jruby.ast.DRegexpNode;
-import org.jruby.ast.DStrNode;
-import org.jruby.ast.DSymbolNode;
-import org.jruby.ast.DVarNode;
-import org.jruby.ast.DXStrNode;
-import org.jruby.ast.DefinedNode;
-import org.jruby.ast.DefnNode;
-import org.jruby.ast.DefsNode;
-import org.jruby.ast.DotNode;
-import org.jruby.ast.EnsureNode;
-import org.jruby.ast.EvStrNode;
-import org.jruby.ast.FCallNode;
-import org.jruby.ast.FalseNode;
-import org.jruby.ast.FixnumNode;
-import org.jruby.ast.FlipNode;
-import org.jruby.ast.FloatNode;
-import org.jruby.ast.ForNode;
-import org.jruby.ast.GlobalAsgnNode;
-import org.jruby.ast.GlobalVarNode;
-import org.jruby.ast.HashNode;
-import org.jruby.ast.IfNode;
-import org.jruby.ast.InstAsgnNode;
-import org.jruby.ast.InstVarNode;
-import org.jruby.ast.IterNode;
-import org.jruby.ast.LocalAsgnNode;
-import org.jruby.ast.LocalVarNode;
-import org.jruby.ast.Match2Node;
-import org.jruby.ast.Match3Node;
-import org.jruby.ast.MatchNode;
-import org.jruby.ast.ModuleNode;
-import org.jruby.ast.MultipleAsgnNode;
-import org.jruby.ast.NewlineNode;
-import org.jruby.ast.NextNode;
-import org.jruby.ast.NilNode;
-import org.jruby.ast.Node;
-import org.jruby.ast.NotNode;
-import org.jruby.ast.NthRefNode;
-import org.jruby.ast.OpAsgnAndNode;
-import org.jruby.ast.OpAsgnNode;
-import org.jruby.ast.OpAsgnOrNode;
-import org.jruby.ast.OpElementAsgnNode;
-import org.jruby.ast.OptNNode;
-import org.jruby.ast.OrNode;
-import org.jruby.ast.PostExeNode;
-import org.jruby.ast.RedoNode;
-import org.jruby.ast.RegexpNode;
-import org.jruby.ast.RescueBodyNode;
-import org.jruby.ast.RescueNode;
-import org.jruby.ast.RetryNode;
-import org.jruby.ast.ReturnNode;
-import org.jruby.ast.SClassNode;
-import org.jruby.ast.SValueNode;
-import org.jruby.ast.ScopeNode;
-import org.jruby.ast.SelfNode;
-import org.jruby.ast.SplatNode;
-import org.jruby.ast.StrNode;
-import org.jruby.ast.SuperNode;
-import org.jruby.ast.SymbolNode;
-import org.jruby.ast.ToAryNode;
-import org.jruby.ast.TrueNode;
-import org.jruby.ast.UndefNode;
-import org.jruby.ast.UntilNode;
-import org.jruby.ast.VAliasNode;
-import org.jruby.ast.VCallNode;
-import org.jruby.ast.WhenNode;
-import org.jruby.ast.WhileNode;
-import org.jruby.ast.XStrNode;
-import org.jruby.ast.YieldNode;
-import org.jruby.ast.ZArrayNode;
-import org.jruby.ast.ZSuperNode;
-import org.jruby.ast.visitor.NodeVisitor;
-import org.jruby.evaluator.Instruction;
-import org.jruby.runtime.callback.Callback;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
-
-public class InstructionCompiler2 implements NodeVisitor {
- private static final String IRUBY = "org/jruby/IRuby";
-
- private static final String IRUBYOBJECT = "org/jruby/runtime/builtin/IRubyObject";
-
- private static final String FRAME = "org/jruby/runtime/Frame";
-
- private static final String THREADCONTEXT = "org/jruby/runtime/ThreadContext";
-
- private static final boolean EXPERIMENTAL_SOURCING = true;
-
- private ArgsNode args;
- private ClassWriter cv;
- private MethodVisitor mv;
-
- private int lastLine = 0;
-
- private boolean tcLoaded;
-
- private boolean runtimeLoaded;
-
- public class NotCompilableException extends RuntimeException {
- private static final long serialVersionUID = 8481162670192366492L;
-
- public NotCompilableException(String message) {
- super(message);
- }
- }
-
- public InstructionCompiler2(String classname, String sourceName) {
- cv = new ClassWriter(true);
-
- cv.visit(Opcodes.V1_2, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER,
- classname, null, "java/lang/Object", null);
- cv.visitSource(sourceName, null);
-
- mv = cv.visitMethod(Opcodes.ACC_PRIVATE, "<init>", "()V", null, null);
- mv.visitCode();
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>",
- "()V");
- mv.visitInsn(Opcodes.RETURN);
- mv.visitMaxs(1, 1);
- mv.visitEnd();
- }
-
- public void newMethod(String methodName, String signature, Node node) {
- mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
- methodName, signature, null, null);
- mv.visitCode();
-
- node.accept(this);
-
- mv.visitMaxs(1, 1); // bogus values, ASM will auto-calculate
- mv.visitInsn(Opc