Permalink
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...
1 parent 2d688c9 commit 9f40038f16dc52d819c2a916703e334ac7868441 @headius headius committed Sep 30, 2006
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
@@ -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() {
@@ -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());
@@ -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++;
@@ -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));
}
}
@@ -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
@@ -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);
@@ -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());
}
@@ -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
Oops, something went wrong.

0 comments on commit 9f40038

Please sign in to comment.