Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bring branch up to date with trunk

git-svn-id: http://svn.codehaus.org/jruby/branches/jruby-joni@5071 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 382fc80e7b019e4544e2250f1356dffb5cc28158 1 parent 9422ebc
@olabini olabini authored
Showing with 2,648 additions and 1,462 deletions.
  1. +40 −142 bin/jrubyc
  2. +1 −6 maven/jruby-complete/pom.xml
  3. +7 −0 maven/jruby/pom.xml
  4. +1 −1  pom.xml
  5. +0 −84 src/org/jruby/JRubyC.java
  6. +5 −3 src/org/jruby/Main.java
  7. +8 −10 src/org/jruby/Ruby.java
  8. +2 −2 src/org/jruby/RubyArgsFile.java
  9. +30 −20 src/org/jruby/RubyArray.java
  10. +3 −2 src/org/jruby/RubyBinding.java
  11. +24 −0 src/org/jruby/RubyClass.java
  12. +2 −1  src/org/jruby/RubyEnumerable.java
  13. +1 −1  src/org/jruby/RubyEnumerator.java
  14. +30 −19 src/org/jruby/RubyFile.java
  15. +3 −3 src/org/jruby/RubyFixnum.java
  16. +11 −2 src/org/jruby/RubyFloat.java
  17. +5 −4 src/org/jruby/RubyGlobal.java
  18. +14 −13 src/org/jruby/RubyIO.java
  19. +8 −5 src/org/jruby/RubyJRuby.java
  20. +52 −33 src/org/jruby/RubyKernel.java
  21. +2 −1  src/org/jruby/RubyMarshal.java
  22. +39 −35 src/org/jruby/RubyModule.java
  23. +2 −1  src/org/jruby/RubyNumeric.java
  24. +43 −118 src/org/jruby/RubyObject.java
  25. +2 −1  src/org/jruby/RubyObjectSpace.java
  26. +26 −9 src/org/jruby/RubyRange.java
  27. +3 −2 src/org/jruby/RubyRegexp.java
  28. +4 −2 src/org/jruby/RubySignal.java
  29. +1 −1  src/org/jruby/RubyString.java
  30. +12 −12 src/org/jruby/RubyStruct.java
  31. +4 −1 src/org/jruby/RubySymbol.java
  32. +3 −3 src/org/jruby/RubyThread.java
  33. +2 −2 src/org/jruby/RubyUnboundMethod.java
  34. +6 −101 src/org/jruby/RubyUndef.java
  35. +1 −1  src/org/jruby/RubyYAML.java
  36. +3 −2 src/org/jruby/ast/executable/RubiniusMachine.java
  37. +1 −1  src/org/jruby/ast/executable/RubiniusRunner.java
  38. +5 −4 src/org/jruby/ast/executable/YARVMachine.java
  39. +2 −1  src/org/jruby/ast/util/ArgsUtil.java
  40. +74 −17 src/org/jruby/compiler/impl/HeapBasedVariableCompiler.java
  41. +18 −15 src/org/jruby/compiler/impl/StandardASMCompiler.java
  42. +1 −1  src/org/jruby/compiler/yarv/StandardYARVCompiler.java
  43. +28 −22 src/org/jruby/evaluator/ASTInterpreter.java
  44. +6 −5 src/org/jruby/evaluator/AssignmentVisitor.java
  45. +11 −11 src/org/jruby/ext/Generator.java
  46. +2 −1  src/org/jruby/internal/runtime/methods/DefaultMethod.java
  47. +1 −1  src/org/jruby/internal/runtime/methods/DynamicMethod.java
  48. +1 −1  src/org/jruby/internal/runtime/methods/YARVMethod.java
  49. +12 −11 src/org/jruby/javasupport/Java.java
  50. +1 −1  src/org/jruby/javasupport/JavaArrayUtilities.java
  51. +14 −12 src/org/jruby/javasupport/JavaClass.java
  52. +2 −2 src/org/jruby/javasupport/JavaObject.java
  53. +1 −1  src/org/jruby/javasupport/JavaUtil.java
  54. +3 −0  src/org/jruby/javasupport/bsf/JRubyEngine.java
  55. +5 −5 src/org/jruby/javasupport/proxy/JavaProxyClass.java
  56. +4 −2 src/org/jruby/javasupport/proxy/JavaProxyConstructor.java
  57. +2 −2 src/org/jruby/javasupport/proxy/JavaProxyReflectionObject.java
  58. +51 −15 src/org/jruby/javasupport/util/RuntimeHelpers.java
  59. +2 −2 src/org/jruby/parser/BlockStaticScope.java
  60. +1 −1  src/org/jruby/parser/LocalStaticScope.java
  61. +4 −1 src/org/jruby/parser/ParserConfiguration.java
  62. +1 −1  src/org/jruby/parser/StaticScope.java
  63. +8 −37 src/org/jruby/runtime/Binding.java
  64. +0 −1  src/org/jruby/runtime/Block.java
  65. +8 −0 src/org/jruby/runtime/BlockBody.java
  66. +7 −2 src/org/jruby/runtime/CallBlock.java
  67. +16 −8 src/org/jruby/runtime/CompiledBlock.java
  68. +15 −7 src/org/jruby/runtime/CompiledBlockLight.java
  69. +3 −3 src/org/jruby/runtime/CompiledSharedScopeBlock.java
  70. +5 −3 src/org/jruby/runtime/Dispatcher.java
  71. +131 −213 src/org/jruby/runtime/DynamicScope.java
  72. +11 −6 src/org/jruby/runtime/InterpretedBlock.java
  73. +7 −2 src/org/jruby/runtime/MethodBlock.java
  74. +1 −1  src/org/jruby/runtime/ObjectSpace.java
  75. +2 −2 src/org/jruby/runtime/SharedScopeBlock.java
  76. +35 −7 src/org/jruby/runtime/ThreadContext.java
  77. +10 −145 src/org/jruby/runtime/builtin/IRubyObject.java
  78. +33 −0 src/org/jruby/runtime/builtin/InstanceVariables.java
  79. +85 −0 src/org/jruby/runtime/builtin/InternalVariables.java
  80. +1 −1  src/org/jruby/runtime/callback/InvocationCallbackFactory.java
  81. +40 −0 src/org/jruby/runtime/marshal/CoreObjectType.java
  82. +105 −97 src/org/jruby/runtime/marshal/MarshalStream.java
  83. +10 −10 src/org/jruby/runtime/marshal/UnmarshalStream.java
  84. +279 −0 src/org/jruby/runtime/scope/ManyVarsDynamicScope.java
  85. +156 −0 src/org/jruby/runtime/scope/NoVarsDynamicScope.java
  86. +191 −0 src/org/jruby/runtime/scope/OneVarDynamicScope.java
  87. +230 −0 src/org/jruby/runtime/scope/TwoVarDynamicScope.java
  88. +0 −65 src/org/jruby/util/CodegenUtils.java
  89. +8 −5 src/org/jruby/util/IOHandlerUnseekable.java
  90. +108 −0 src/org/jruby/util/JavaNameMangler.java
  91. +9 −8 src/org/jruby/util/ShellLauncher.java
  92. +2 −2 src/org/jruby/util/Sprintf.java
  93. +90 −0 src/org/jruby/util/TypeConverter.java
  94. +1 −2  src/org/jruby/util/ZlibInflate.java
  95. +3 −2 src/org/jruby/yaml/JRubyConstructor.java
  96. +187 −0 test/bench/bench_local_vars.rb
  97. +0 −45 test/bench/bench_uncaptured_local_vars.rb
  98. +3 −0  test/jruby_index
  99. +1 −1  test/org/jruby/test/TestKernel.java
  100. +1 −2  test/org/jruby/test/TestRubyObject.java
  101. +1 −1  test/rubicon/test_exception.rb
  102. +3 −3 test/testEval.rb
  103. +1 −1  test/test_array.rb
  104. +25 −0 test/test_eval.rb
  105. +80 −0 test/test_eval_with_binding.rb
  106. +9 −1 test/test_io.rb
  107. +43 −0 test/test_proc_visibility.rb
  108. +31 −0 test/test_zlib.rb
View
182 bin/jrubyc
@@ -1,148 +1,46 @@
-#!/bin/bash
-# -----------------------------------------------------------------------------
-# jruby.sh - Start Script for the JRuby interpreter
-#
-# Environment Variable Prequisites
-#
-# JRUBY_BASE (Optional) Base directory for resolving dynamic portions
-# of a JRuby installation. If not present, resolves to
-# the same directory that JRUBY_HOME points to.
-#
-# JRUBY_HOME (Optional) May point at your JRuby "build" directory.
-# If not present, the current working directory is assumed.
-#
-# JRUBY_OPTS (Optional) Default JRuby command line args
-# JRUBY_SHELL Where/What is system shell
-#
-# JAVA_HOME Must point at your Java Development Kit installation.
-#
-# -----------------------------------------------------------------------------
+#!/usr/bin/env jruby
-cygwin=false
+require 'jruby'
-# ----- Identify OS we are running under --------------------------------------
-case "`uname`" in
-CYGWIN*) cygwin=true
-esac
+runtime = JRuby.runtime
-# ----- Verify and Set Required Environment Variables -------------------------
+if ARGV.size < 1
+ puts "Usage: jrubyc <filename.rb> [<filename.rb> ...]"
+ exit
+end
-if [ -z "$JRUBY_HOME" ] ; then
- ## resolve links - $0 may be a link to home
- PRG=$0
- progname=`basename "$0"`
+ARGV.each do |filename|
+ unless File.exists? filename
+ puts "Error -- file not found: #{filename}"
+ next
+ end
- while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '.*/.*' > /dev/null; then
- PRG="$link"
- else
- PRG="`dirname $PRG`/$link"
- fi
- done
+ begin
+ file = File.open(filename)
+ destdir = Dir.pwd
- JRUBY_HOME_1=`dirname "$PRG"` # the ./bin dir
- JRUBY_HOME_1=`dirname "$JRUBY_HOME_1"` # the . dir
- if [ -d "${JRUBY_HOME_1}/lib" ] ; then
- JRUBY_HOME="${JRUBY_HOME_1}"
- fi
-else
- if $cygwin; then
- JRUBY_HOME=`cygpath -u "$JRUBY_HOME"`
- fi
-fi
-
-if [ -z "$JRUBY_OPTS" ] ; then
- JRUBY_OPTS=""
-fi
-
-if [ -z "$JAVA_HOME" ] ; then
- JAVA_CMD='java'
-else
- if $cygwin; then
- JAVA_HOME=`cygpath -u "$JAVA_HOME"`
- fi
- JAVA_CMD="$JAVA_HOME/bin/java"
-fi
-
-JRUBY_SHELL=/bin/sh
-
-# ----- Set Up The System Classpath -------------------------------------------
-
-if [ "$JRUBY_PARENT_CLASSPATH" != "" ]; then
- # Use same classpath propagated from parent jruby
- CP=$JRUBY_PARENT_CLASSPATH
-else
- if [ "$CLASSPATH" != "" ]; then
- CP="$CLASSPATH"
- if $cygwin; then
- CP=`cygpath -p -u "$CP"`
- fi
- else
- CP=""
- fi
-
- CP_DELIMETER=":"
-
- # add necessary jars for command-line execution
- for j in "$JRUBY_HOME"/lib/*.jar; do
- if [ "$CP" ]; then
- CP="$CP$CP_DELIMETER$j"
- else
- CP="$j"
- fi
- done
-
- if $cygwin; then
- CP=`cygpath -p -w "$CP"`
- fi
-fi
-
-# ----- Set Up JRUBY_BASE If Necessary -------------------------------------
-
-if [ -z "$JRUBY_BASE" ] ; then
- JRUBY_BASE="$JRUBY_HOME"
-fi
-
-# ----- Execute The Requested Command -----------------------------------------
-
-DEBUG=""
-if [ "$1" = "JAVA_DEBUG" ]; then
- DEBUG="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y"
- shift
-else
- if [ "$1" = "JPROFILER" ]; then
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JPROFILER_PATH/bin/linux-x86
- DEBUG="-Xrunjprofiler:port=8000,noexit -Xbootclasspath/a:/$JPROFILER_PATH/bin/agent.jar"
- shift
- else if [ "$1" = "HPROF" ]; then
- DEBUG="-Xrunhprof:cpu=samples"
- shift
- fi
- fi
-fi
-
-if $cygwin; then
- JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
- JRUBY_BASE=`cygpath --mixed "$JRUBY_BASE"`
- JRUBY_HOME=`cygpath --mixed "$JRUBY_HOME"`
- JRUBY_SHELL=`cygpath --mixed "$JRUBY_SHELL"`
-fi
-
-EN_US=
-if [ "$1" = "EN_US" ]; then
- EN_US="-Duser.language=en -Duser.country=US"
- shift
-fi
-
-if [ "$1" = "SERVER" ]; then
- DEBUG="-server"
- shift
-fi
-
-exec "$JAVA_CMD" $JAVA_OPTS $DEBUG -Xmx256m -Xss1024k -ea -classpath "$CP" \
-"-Djruby.base=$JRUBY_BASE" "-Djruby.home=$JRUBY_HOME" \
-"-Djruby.lib=$JRUBY_BASE/lib" -Djruby.script=jruby \
-"-Djruby.shell=$JRUBY_SHELL" $EN_US \
-org.jruby.JRubyC $JRUBY_OPTS "$@"
+ BAIS = java.io.ByteArrayInputStream
+ Mangler = org.jruby.util.JavaNameMangler
+ BytecodeCompiler = org.jruby.compiler.impl.StandardASMCompiler
+ ASTCompiler = org.jruby.compiler.ASTCompiler
+ JavaFile = java.io.File
+
+ inspector = org.jruby.compiler.ASTInspector.new
+
+ source = file.read
+ node = runtime.parse_file(BAIS.new(source.to_java_bytes), filename, nil)
+
+ classpath = Mangler.mangle_filename_for_classpath(filename)
+
+ inspector.inspect(node)
+
+ compiler = BytecodeCompiler.new(classpath, filename)
+ ASTCompiler.compile_root(node, compiler, inspector)
+
+ compiler.write_class(JavaFile.new(destdir))
+ rescue
+ puts "Failure during compilation of file #{filename}:\n#{$!}"
+ ensure
+ file.close unless file.nil?
+ end
+end
View
7 maven/jruby-complete/pom.xml
@@ -16,12 +16,6 @@
<dependencies>
<dependency>
- <groupId>backport-util-concurrent</groupId>
- <artifactId>backport-util-concurrent</artifactId>
- <version>3.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>0.9.91</version>
@@ -61,6 +55,7 @@
<groupId>org.jruby.extras</groupId>
<artifactId>jna</artifactId>
<version>jruby-pre</version>
+ <scope>provided</scope>
</dependency>
</dependencies>
View
7 maven/jruby/pom.xml
@@ -19,36 +19,43 @@
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>0.9.91</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.0</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>3.0</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-util</artifactId>
<version>3.0</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-analysis</artifactId>
<version>3.0</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-tree</artifactId>
<version>3.0</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jruby.extras</groupId>
<artifactId>jna</artifactId>
<version>jruby-pre</version>
+ <scope>provided</scope>
</dependency>
</dependencies>
View
2  pom.xml
@@ -245,7 +245,7 @@
<id>jruby-release</id>
<activation>
<property>
- <name>performRelease</name>
+ <name>release</name>
<value>true</value>
</property>
</activation>
View
84 src/org/jruby/JRubyC.java
@@ -1,84 +0,0 @@
-/*
- * JRubyC.java
- *
- * Created on January 11, 2007, 11:24 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package org.jruby;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import java.nio.charset.CharsetDecoder;
-import org.jruby.ast.Node;
-import org.jruby.compiler.ASTInspector;
-import org.jruby.compiler.ASTCompiler;
-import org.jruby.compiler.NotCompilableException;
-import org.jruby.compiler.impl.StandardASMCompiler;
-import org.jruby.util.KCode;
-
-/**
- *
- * @author headius
- */
-public class JRubyC {
-
- public static void main(String args[]) {
- Ruby runtime = Ruby.newInstance();
-
- try {
- if (args.length < 1) {
- System.out.println("Usage: jrubyc <filename> [<filename> ...]");
- return;
- }
- for (int i = 0; i < args.length; i++) {
- String filename = args[i];
- if (filename.startsWith("./")) filename = filename.substring(2);
- File srcfile = new File(filename);
- if (!srcfile.exists()) {
- System.out.println("Error -- file not found: " + filename);
- return;
- }
-
- // destination directory
- File destfile = new File(System.getProperty("user.dir"));
-
- int size = (int)srcfile.length();
- byte[] chars = new byte[size];
- new FileInputStream(srcfile).read(chars);
- // FIXME: -K encoding?
- String content = new String(chars);
- Node scriptNode = runtime.parseFile(new ByteArrayInputStream(content.getBytes("ISO-8859-1")), filename, null);
-
- ASTInspector inspector = new ASTInspector();
- inspector.inspect(scriptNode);
-
- // do the compile
- String classPath = filename.substring(0, filename.lastIndexOf(".")).replace('-', '_').replace('.', '_');
- int lastSlashIndex = classPath.lastIndexOf('/');
- if (!Character.isJavaIdentifierStart(classPath.charAt(lastSlashIndex + 1))) {
- if (lastSlashIndex == -1) {
- classPath = "_" + classPath;
- } else {
- classPath = classPath.substring(0, lastSlashIndex + 1) + "_" + classPath.substring(lastSlashIndex + 1);
- }
- }
- StandardASMCompiler compiler = new StandardASMCompiler(classPath, filename);
- ASTCompiler.compileRoot(scriptNode, compiler, inspector);
-
- compiler.writeClass(destfile);
- }
- } catch (IOException ioe) {
- ioe.printStackTrace();
- System.err.println("Error -- IO exception during compile: " + ioe.getMessage());
- } catch (NotCompilableException nce) {
- System.err.println("Error -- Not compilable: " + nce.getMessage());
- }
- }
-
-}
View
8 src/org/jruby/Main.java
@@ -149,9 +149,11 @@ public void printUsage() {
config.getOutput().println(" -- optional -- before rubyfile.rb for compatibility with ruby");
config.getOutput().println(" -d set debugging flags (set $DEBUG to true)");
config.getOutput().println(" -v print version number, then turn on verbose mode");
- config.getOutput().println(" -O run with ObjectSpace disabled (improves performance)");
+ config.getOutput().println(" -O run with ObjectSpace disabled (default; improves performance)");
+ config.getOutput().println(" +O run with ObjectSpace enabled (default; reduces performance)");
config.getOutput().println(" -S cmd run the specified command in JRuby's bin dir");
- config.getOutput().println(" -C pre-compile scripts before running (EXPERIMENTAL)");
+ config.getOutput().println(" -C disable all compilation");
+ config.getOutput().println(" +C force compilation of all scripts before they are run (except eval)");
config.getOutput().println(" -y read a YARV-compiled Ruby script and run that (EXPERIMENTAL)");
config.getOutput().println(" -Y compile a Ruby script into YARV bytecodes and run this (EXPERIMENTAL)");
config.getOutput().println(" -R read a Rubinius-compiled Ruby script and run that (EXPERIMENTAL)");
@@ -184,7 +186,7 @@ private int runInterpreter() {
return 0;
} catch (RaiseException rj) {
RubyException raisedException = rj.getException();
- if (raisedException.isKindOf(runtime.fastGetClass("SystemExit"))) {
+ if (runtime.fastGetClass("SystemExit").isInstance(raisedException)) {
IRubyObject status = raisedException.callMethod(runtime.getCurrentContext(), "status");
if (status != null && !status.isNil()) {
View
18 src/org/jruby/Ruby.java
@@ -83,6 +83,7 @@
import org.jruby.libraries.RbConfigLibrary;
import org.jruby.parser.Parser;
import org.jruby.parser.ParserConfiguration;
+import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.CacheMap;
import org.jruby.runtime.CallbackFactory;
@@ -104,9 +105,9 @@
import org.jruby.util.KCode;
import org.jruby.util.MethodCache;
import org.jruby.util.NormalizedFile;
-import org.jruby.runtime.Binding;
import com.sun.jna.Native;
+import org.jruby.util.JavaNameMangler;
/**
* The jruby runtime.
@@ -516,15 +517,7 @@ private Script tryCompile(Node node) {
Script script = null;
try {
String filename = node.getPosition().getFile();
- String classname;
- if (filename.equals("-e")) {
- classname = "__dash_e__";
- } else {
- classname = filename.replace('\\', '/').replaceAll(".rb", "");
- }
- // remove leading / or ./ from classname, since it will muck up the dotted name
- if (classname.startsWith("/")) classname = classname.substring(1);
- if (classname.startsWith("./")) classname = classname.substring(2);
+ String classname = JavaNameMangler.mangledFilenameForStartupClasspath(filename);
ASTInspector inspector = new ASTInspector();
inspector.inspect(node);
@@ -2152,6 +2145,11 @@ public RaiseException newErrnoENOENTError() {
return newRaiseException(fastGetModule("Errno").fastGetClass("ENOENT"), "File not found");
}
+ public RaiseException newErrnoEACCESError(String message) {
+ return newRaiseException(
+ fastGetModule("Errno").fastGetClass("EACCES"), message);
+ }
+
public RaiseException newErrnoEISDirError() {
return newRaiseException(fastGetModule("Errno").fastGetClass("EISDIR"), "Is a directory");
}
View
4 src/org/jruby/RubyArgsFile.java
@@ -170,8 +170,8 @@ public IRubyObject readline(IRubyObject[] args) {
public RubyArray readlines(IRubyObject[] args) {
IRubyObject[] separatorArgument;
if (args.length > 0) {
- if (!args[0].isKindOf(getRuntime().getNilClass()) &&
- !args[0].isKindOf(getRuntime().getString())) {
+ if (!getRuntime().getNilClass().isInstance(args[0]) &&
+ !getRuntime().getString().isInstance(args[0])) {
throw getRuntime().newTypeError(args[0],
getRuntime().getString());
}
View
50 src/org/jruby/RubyArray.java
@@ -187,8 +187,8 @@ public static RubyArray newArray(Ruby runtime, Collection collection) {
private IRubyObject[] values;
private static final int TMPLOCK_ARR_F = 1 << 9;
- private static final int SHARED_ARR_F = 1 << 10;
+ private volatile boolean isShared = false;
private int begin = 0;
private int realLength = 0;
@@ -209,7 +209,7 @@ private RubyArray(Ruby runtime, IRubyObject[] vals, int begin) {
this.values = vals;
this.begin = begin;
this.realLength = vals.length - begin;
- flags |= SHARED_ARR_F;
+ this.isShared = true;
}
/* rb_ary_new2
@@ -330,11 +330,11 @@ public int getLength() {
}
public IRubyObject[] toJavaArrayUnsafe() {
- return (flags & SHARED_ARR_F) == 0 ? values : toJavaArray();
+ return !isShared ? values : toJavaArray();
}
public IRubyObject[] toJavaArrayMaybeUnsafe() {
- return ((flags & SHARED_ARR_F) == 0 && begin == 0 && values.length == realLength) ? values : toJavaArray();
+ return (!isShared && begin == 0 && values.length == realLength) ? values : toJavaArray();
}
/** rb_ary_make_shared
@@ -349,9 +349,9 @@ private final RubyArray makeShared(int beg, int len, RubyClass klass) {
*/
private final RubyArray makeShared(int beg, int len, RubyClass klass, boolean objectSpace) {
RubyArray sharedArray = new RubyArray(getRuntime(), klass, objectSpace);
- flags |= SHARED_ARR_F;
+ isShared = true;
sharedArray.values = values;
- sharedArray.flags |= SHARED_ARR_F;
+ sharedArray.isShared = true;
sharedArray.begin = beg;
sharedArray.realLength = len;
return sharedArray;
@@ -376,9 +376,9 @@ private final void modifyCheck() {
*/
private final void modify() {
modifyCheck();
- if ((flags & SHARED_ARR_F) != 0) {
+ if (isShared) {
IRubyObject[] vals = reserve(realLength);
- flags &= ~SHARED_ARR_F;
+ isShared = false;
System.arraycopy(values, begin, vals, 0, realLength);
begin = 0;
values = vals;
@@ -442,10 +442,18 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {
return this;
}
+ /** rb_ary_initialize_copy
+ *
+ */
+ @JRubyMethod(name = {"initialize_copy"}, required = 1, visibility=Visibility.PRIVATE)
+ public IRubyObject initialize_copy(IRubyObject orig) {
+ return this.replace(orig);
+ }
+
/** rb_ary_replace
*
*/
- @JRubyMethod(name = {"replace", "initialize_copy"}, required = 1)
+ @JRubyMethod(name = {"replace"}, required = 1)
public IRubyObject replace(IRubyObject orig) {
modifyCheck();
@@ -453,8 +461,8 @@ public IRubyObject replace(IRubyObject orig) {
if (this == orig) return this;
- origArr.flags |= SHARED_ARR_F;
- flags |= SHARED_ARR_F;
+ origArr.isShared = true;
+ isShared = true;
values = origArr.values;
realLength = origArr.realLength;
begin = origArr.begin;
@@ -897,7 +905,7 @@ public IRubyObject pop() {
if (realLength == 0) return getRuntime().getNil();
- if ((flags & SHARED_ARR_F) == 0) {
+ if (!isShared) {
int index = begin + --realLength;
IRubyObject obj = values[index];
values[index] = null;
@@ -918,7 +926,7 @@ public IRubyObject shift() {
IRubyObject obj = values[begin];
- flags |= SHARED_ARR_F;
+ isShared = true;
begin++;
realLength--;
@@ -1164,7 +1172,7 @@ public IRubyObject last(IRubyObject[] args) {
@JRubyMethod(name = "each", frame = true)
public IRubyObject each(Block block) {
ThreadContext context = getRuntime().getCurrentContext();
- if ((flags & SHARED_ARR_F) != 0) {
+ if (isShared) {
for (int i = begin; i < begin + realLength; i++) {
block.yield(context, values[i]);
}
@@ -1284,8 +1292,8 @@ public RubyArray to_a() {
if(getMetaClass() != getRuntime().getArray()) {
RubyArray dup = new RubyArray(getRuntime(), getRuntime().isObjectSpaceEnabled());
- flags |= SHARED_ARR_F;
- dup.flags |= SHARED_ARR_F;
+ isShared = true;
+ dup.isShared = true;
dup.values = values;
dup.realLength = realLength;
dup.begin = begin;
@@ -1319,7 +1327,9 @@ public IRubyObject op_equal(IRubyObject obj) {
if (!obj.respondsTo("to_ary")) {
return getRuntime().getFalse();
} else {
- return equalInternal(getRuntime().getCurrentContext(), obj, this);
+ ThreadContext context = getRuntime().getCurrentContext();
+
+ return equalInternal(context, obj.callMethod(context, "to_ary"), this);
}
}
@@ -1405,9 +1415,9 @@ public IRubyObject empty_p() {
public IRubyObject rb_clear() {
modifyCheck();
- if((flags & SHARED_ARR_F) != 0){
+ if(isShared) {
alloc(ARRAY_DEFAULT_SIZE);
- flags |= SHARED_ARR_F;
+ isShared = true;
} else if (values.length > ARRAY_DEFAULT_SIZE << 1){
alloc(ARRAY_DEFAULT_SIZE << 1);
}
@@ -1613,7 +1623,7 @@ public RubyArray select(Block block) {
RubyArray result = new RubyArray(runtime, realLength);
ThreadContext context = runtime.getCurrentContext();
- if ((flags & SHARED_ARR_F) != 0) {
+ if (isShared) {
for (int i = begin; i < begin + realLength; i++) {
if (block.yield(context, values[i]).isTrue()) result.append(elt(i - begin));
}
View
5 src/org/jruby/RubyBinding.java
@@ -85,7 +85,7 @@ public static RubyBinding newBinding(Ruby runtime) {
// FIXME: We should be cloning, not reusing: frame, scope, dynvars, and potentially iter/block info
Frame frame = context.getCurrentFrame();
- Binding binding = Binding.createBinding(frame, context.getCurrentScope());
+ Binding binding = new Binding(frame, context.getBindingRubyClass(), context.getCurrentScope());
return new RubyBinding(runtime, runtime.getBinding(), binding);
}
@@ -116,7 +116,8 @@ public static RubyBinding newBindingForEval(Ruby runtime) {
// Set jump target to whatever the previousTarget thinks is good.
currentFrame.setJumpTarget(previousFrame.getJumpTarget() != null ? previousFrame.getJumpTarget() : previousFrame);
- Binding binding = Binding.createBinding(previousFrame, context.getCurrentScope());
+ Binding binding = new Binding(previousFrame, context.getBindingRubyClass(), context.getCurrentScope());
+ //Binding.createBinding(previousFrame, context.getCurrentScope());
return new RubyBinding(runtime, runtime.getBinding(), binding);
}
View
24 src/org/jruby/RubyClass.java
@@ -37,11 +37,15 @@
import java.util.Set;
import org.jruby.anno.JRubyMethod;
+import org.jruby.internal.runtime.methods.DynamicMethod;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
+import org.jruby.runtime.CallType;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ObjectMarshal;
+import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.MarshalStream;
@@ -214,6 +218,26 @@ public RubyClass makeMetaClass(RubyClass superClass) {
return super.makeMetaClass(superClass);
}
}
+
+ public IRubyObject invoke(ThreadContext context, IRubyObject self, int methodIndex, String name, IRubyObject[] args, CallType callType, Block block) {
+ if (context.getRuntime().hasEventHooks()) return invoke(context, self, name, args, callType, block);
+
+ return dispatcher.callMethod(context, self, this, methodIndex, name, args, callType, block);
+ }
+
+ public IRubyObject invoke(ThreadContext context, IRubyObject self, String name,
+ IRubyObject[] args, CallType callType, Block block) {
+ assert args != null;
+ DynamicMethod method = null;
+ method = searchMethod(name);
+
+
+ if (method.isUndefined() || (!name.equals("method_missing") && !method.isCallableFrom(context.getFrameSelf(), callType))) {
+ return RuntimeHelpers.callMethodMissing(context, self, method, name, args, context.getFrameSelf(), callType, block);
+ }
+
+ return method.call(context, self, this, name, args, block);
+ }
/** rb_class_new_instance
*
View
3  src/org/jruby/RubyEnumerable.java
@@ -40,6 +40,7 @@
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.util.TypeConverter;
/**
* The implementation of Ruby's Enumerable module.
@@ -471,7 +472,7 @@ public static IRubyObject zip(IRubyObject self, final IRubyObject[] args, final
final ThreadContext context = runtime.getCurrentContext();
for (int i = 0; i < args.length; i++) {
- args[i] = args[i].convertToType(runtime.getArray(), MethodIndex.TO_A, "to_a");
+ args[i] = TypeConverter.convertToType(args[i], runtime.getArray(), MethodIndex.TO_A, "to_a");
}
final int aLen = args.length + 1;
View
2  src/org/jruby/RubyEnumerator.java
@@ -113,7 +113,7 @@ public IRubyObject initialize(IRubyObject[] args) {
*/
@JRubyMethod(name = "each", frame = true)
public IRubyObject each(Block block) {
- return object.callMethod(getRuntime().getCurrentContext(), method.asSymbol(), methodArgs, block);
+ return object.callMethod(getRuntime().getCurrentContext(), method.asInternedString(), methodArgs, block);
}
@JRubyMethod(name = "enum_with_index")
View
49 src/org/jruby/RubyFile.java
@@ -43,8 +43,8 @@
import java.io.Reader;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
-import org.jruby.anno.JRubyMethod;
+import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallbackFactory;
@@ -62,6 +62,7 @@
import org.jruby.util.IOModes;
import org.jruby.util.JRubyFile;
import org.jruby.util.IOHandler.InvalidValueException;
+import org.jruby.util.TypeConverter;
/**
* Ruby File class equivalent in java.
@@ -253,7 +254,14 @@ public void openInternal(String newPath, IOModes newModes) {
} catch (DirectoryAsFileException e) {
throw getRuntime().newErrnoEISDirError();
} catch (FileNotFoundException e) {
- throw getRuntime().newErrnoENOENTError();
+ // FNFException can be thrown in both cases, when the file
+ // is not found, or when permission is denied.
+ if (new File(newPath).exists()) {
+ throw getRuntime().newErrnoEACCESError(
+ "Permission denied - " + newPath);
+ }
+ throw getRuntime().newErrnoENOENTError(
+ "File not found - " + newPath);
} catch (IOException e) {
throw getRuntime().newIOError(e.getMessage());
}
@@ -357,7 +365,7 @@ public IRubyObject initialize(IRubyObject[] args, Block block) {
throw getRuntime().newArgumentError(0, 1);
}
else if (args.length < 3) {
- IRubyObject fd = args[0].convertToTypeWithCheck(getRuntime().getFixnum(), MethodIndex.TO_INT, "to_int");
+ IRubyObject fd = TypeConverter.convertToTypeWithCheck(args[0], getRuntime().getFixnum(), MethodIndex.TO_INT, "to_int");
if (!fd.isNil()) {
args[0] = fd;
return super.initialize(args, block);
@@ -960,21 +968,24 @@ public static IRubyObject open(IRubyObject recv, IRubyObject[] args, boolean try
Arity.checkArgumentCount(runtime, args, 1, -1);
ThreadContext tc = runtime.getCurrentContext();
- RubyString pathString = RubyString.stringValue(args[0]);
- runtime.checkSafeString(pathString);
- String path = pathString.toString();
-
- IOModes modes =
- args.length >= 2 ? getModes(runtime, args[1]) : new IOModes(runtime, IOModes.RDONLY);
- RubyFile file = new RubyFile(runtime, (RubyClass) recv);
-
- RubyInteger fileMode =
- args.length >= 3 ? args[2].convertToInteger() : null;
-
- file.openInternal(path, modes);
-
- if (fileMode != null) {
- chmod(recv, new IRubyObject[] {fileMode, pathString});
+ RubyFile file;
+
+ if (args[0] instanceof RubyInteger) { // open with file descriptor
+ file = new RubyFile(runtime, (RubyClass) recv);
+ file.initialize(args, Block.NULL_BLOCK);
+ } else {
+ RubyString pathString = RubyString.stringValue(args[0]);
+ runtime.checkSafeString(pathString);
+ String path = pathString.toString();
+
+ IOModes modes = args.length >= 2 ? getModes(runtime, args[1]) : new IOModes(runtime, IOModes.RDONLY);
+ file = new RubyFile(runtime, (RubyClass) recv);
+
+ RubyInteger fileMode = args.length >= 3 ? args[2].convertToInteger() : null;
+
+ file.openInternal(path, modes);
+
+ if (fileMode != null) chmod(recv, new IRubyObject[] {fileMode, pathString});
}
if (tryToYield && block.isGiven()) {
@@ -1081,7 +1092,7 @@ public static IRubyObject truncate(IRubyObject recv, IRubyObject arg1, IRubyObje
throw runtime.newErrnoEINVALError("invalid argument: " + filename);
}
- IRubyObject[] args = new IRubyObject[] { filename, runtime.newString("w+") };
+ IRubyObject[] args = new IRubyObject[] { filename, runtime.newString("r+") };
RubyFile file = (RubyFile) open(recv, args, false, null);
file.truncate(newLength);
file.close();
View
6 src/org/jruby/RubyFixnum.java
@@ -200,7 +200,7 @@ public RubyString to_s(IRubyObject[] args) {
public IRubyObject id2name() {
RubySymbol symbol = RubySymbol.getSymbolLong(getRuntime(), value);
- if (symbol != null) return getRuntime().newString(symbol.asSymbol());
+ if (symbol != null) return getRuntime().newString(symbol.asInternedString());
return getRuntime().getNil();
}
@@ -683,7 +683,7 @@ public IRubyObject freeze() {
}
// Piece of mri rb_to_id
- public String asSymbol() {
+ public String asInternedString() {
getRuntime().getWarnings().warn("do not use Fixnums as Symbols");
// FIXME: I think this chunk is equivalent to MRI id2name (and not our public method
@@ -694,7 +694,7 @@ public String asSymbol() {
throw getRuntime().newArgumentError("" + value + " is not a symbol");
}
- return symbol.asSymbol();
+ return symbol.asInternedString();
}
public static RubyFixnum unmarshalFrom(UnmarshalStream input) throws java.io.IOException {
View
13 src/org/jruby/RubyFloat.java
@@ -81,7 +81,7 @@ public boolean isKindOf(IRubyObject obj, RubyModule type) {
// Double.MAX_EXPONENT since Java 1.6
floatc.defineConstant("MAX_EXP", RubyFixnum.newFixnum(runtime, 1024));
floatc.defineConstant("MIN_10_EXP", RubyFixnum.newFixnum(runtime, -307));
- floatc.defineConstant("MAX_10_EXP", RubyFixnum.newFixnum(runtime, -308));
+ floatc.defineConstant("MAX_10_EXP", RubyFixnum.newFixnum(runtime, 308));
floatc.defineConstant("MIN", RubyFloat.newFloat(runtime, Double.MIN_VALUE));
floatc.defineConstant("MAX", RubyFloat.newFloat(runtime, Double.MAX_VALUE));
floatc.defineConstant("EPSILON", RubyFloat.newFloat(runtime, 2.2204460492503131e-16));
@@ -197,7 +197,16 @@ public IRubyObject to_s() {
*/
@JRubyMethod(name = "coerce", required = 1)
public IRubyObject coerce(IRubyObject other) {
- if (other instanceof RubyNumeric) {
+ if (other instanceof RubyString) {
+ double otherDouble = 0.0;
+ try {
+ otherDouble = Double.parseDouble(other.toString());
+ } catch (Exception e) {
+ throw getRuntime().newArgumentError("invalid value for Float(): \"" + other.toString() + "\"");
+ }
+ return getRuntime().newArray(
+ newFloat(getRuntime(), otherDouble), this);
+ } else if (other instanceof RubyNumeric) {
return getRuntime().newArray(
newFloat(getRuntime(), ((RubyNumeric) other).getDoubleValue()), this);
}
View
9 src/org/jruby/RubyGlobal.java
@@ -41,6 +41,7 @@
import org.jruby.environment.OSEnvironmentReaderExcepton;
import org.jruby.environment.OSEnvironment;
import org.jruby.internal.runtime.ValueAccessor;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.Constants;
import org.jruby.runtime.GlobalVariable;
import org.jruby.runtime.MethodIndex;
@@ -70,7 +71,7 @@ public IRubyObject op_aref(IRubyObject key) {
throw getRuntime().newTypeError("can't convert " + key.getMetaClass() + " into String");
}
- return super.op_aref(key.callMethod(getRuntime().getCurrentContext(), MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY));
+ return super.op_aref(RuntimeHelpers.invoke(getRuntime().getCurrentContext(), key, MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY));
}
public IRubyObject op_aset(IRubyObject key, IRubyObject value) {
@@ -87,8 +88,8 @@ public IRubyObject op_aset(IRubyObject key, IRubyObject value) {
ThreadContext context = getRuntime().getCurrentContext();
//return super.aset(getRuntime().newString("sadfasdF"), getRuntime().newString("sadfasdF"));
- return super.op_aset(key.callMethod(context, MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY),
- value.isNil() ? getRuntime().getNil() : value.callMethod(context, MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY));
+ return super.op_aset(RuntimeHelpers.invoke(context, key, MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY),
+ value.isNil() ? getRuntime().getNil() : RuntimeHelpers.invoke(context, value, MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY));
}
public IRubyObject to_s(){
@@ -304,7 +305,7 @@ public ErrorInfoGlobalVariable(Ruby runtime, String name, IRubyObject value) {
}
public IRubyObject set(IRubyObject value) {
- if (!value.isNil() && ! value.isKindOf(runtime.getException())) {
+ if (!value.isNil() && ! runtime.getException().isInstance(value)) {
throw runtime.newTypeError("assigning non-exception to $!");
}
View
27 src/org/jruby/RubyIO.java
@@ -72,6 +72,7 @@
import org.jruby.util.IOHandlerUnseekable;
import org.jruby.util.IOModes;
import org.jruby.util.ShellLauncher;
+import org.jruby.util.IOHandler.BadDescriptorException;
/**
*
@@ -263,12 +264,12 @@ public RubyIO(Ruby runtime, int descriptor) {
try {
handler = new IOHandlerUnseekable(runtime, descriptor);
- } catch (IOException e) {
- throw runtime.newIOError(e.getMessage());
+ } catch (BadDescriptorException e) {
+ throw runtime.newErrnoEBADFError();
}
modes = handler.getModes();
- registerIOHandler(handler);
+ registerIOHandler(handler);
}
private static ObjectAllocator IO_ALLOCATOR = new ObjectAllocator() {
@@ -372,7 +373,7 @@ public IRubyObject reopen(IRubyObject[] args) {
throw getRuntime().newArgumentError("wrong number of arguments");
}
- if (args[0].isKindOf(getRuntime().getIO())) {
+ if (getRuntime().getIO().isInstance(args[0])) {
RubyIO ios = (RubyIO) args[0];
int keepFileno = handler.getFileno();
@@ -413,12 +414,12 @@ public IRubyObject reopen(IRubyObject[] args) {
// Update fileno list with our new handler
registerIOHandler(handler);
- } else if (args[0].isKindOf(getRuntime().getString())) {
+ } else if (getRuntime().getString().isInstance(args[0])) {
String path = ((RubyString) args[0]).toString();
IOModes newModes = null;
if (args.length > 1) {
- if (!args[1].isKindOf(getRuntime().getString())) {
+ if (!getRuntime().getString().isInstance(args[1])) {
throw getRuntime().newTypeError(args[1], getRuntime().getString());
}
@@ -527,8 +528,8 @@ public IRubyObject initialize(IRubyObject[] args, Block unusedBlock) {
try {
handler = new IOHandlerUnseekable(getRuntime(), newFileno, mode);
- } catch (IOException e) {
- throw getRuntime().newIOError(e.getMessage());
+ } catch (BadDescriptorException e) {
+ throw getRuntime().newErrnoEBADFError();
}
modes = new IOModes(getRuntime(), mode);
@@ -774,7 +775,7 @@ public IRubyObject printf(IRubyObject[] args) {
public IRubyObject putc(IRubyObject object) {
int c;
- if (object.isKindOf(getRuntime().getString())) {
+ if (getRuntime().getString().isInstance(object)) {
String value = ((RubyString) object).toString();
if (value.length() > 0) {
@@ -782,7 +783,7 @@ public IRubyObject putc(IRubyObject object) {
} else {
throw getRuntime().newTypeError("Cannot convert String to Integer");
}
- } else if (object.isKindOf(getRuntime().getFixnum())){
+ } else if (getRuntime().getFixnum().isInstance(object)){
c = RubyNumeric.fix2int(object);
} else { // What case will this work for?
c = RubyNumeric.fix2int(object.callMethod(getRuntime().getCurrentContext(), MethodIndex.TO_I, "to_i"));
@@ -1186,7 +1187,7 @@ public IRubyObject read(IRubyObject[] args) {
if (atEOF && handler.isEOF()) throw new EOFException();
if (argCount == 2) {
- callerBuffer = args[1].convertToString();
+ callerBuffer = !args[1].isNil() ? args[1].convertToString() : getRuntime().newString();
}
ByteList buf;
@@ -1308,8 +1309,8 @@ public RubyIO each_line(IRubyObject[] args, Block block) {
public RubyArray readlines(IRubyObject[] args) {
ByteList separator;
if (args.length > 0) {
- if (!args[0].isKindOf(getRuntime().getNilClass()) &&
- !args[0].isKindOf(getRuntime().getString())) {
+ if (!getRuntime().getNilClass().isInstance(args[0]) &&
+ !getRuntime().getString().isInstance(args[0])) {
throw getRuntime().newTypeError(args[0],
getRuntime().getString());
}
View
13 src/org/jruby/RubyJRuby.java
@@ -29,6 +29,8 @@
package org.jruby;
import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import org.jruby.anno.JRubyMethod;
import org.jruby.javasupport.Java;
@@ -46,6 +48,7 @@
import org.jruby.compiler.impl.StandardASMCompiler;
import org.jruby.runtime.InterpretedBlock;
import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.util.TraceClassVisitor;
/**
* Module which defines JRuby-specific methods for use.
@@ -174,19 +177,19 @@ public static IRubyObject reference(IRubyObject recv, IRubyObject obj) {
public static class JRubyCompiledScript {
@JRubyMethod(name = "to_s")
public static IRubyObject compiled_script_to_s(IRubyObject recv) {
- return recv.fastGetInstanceVariable("@original_script");
+ return recv.getInstanceVariables().fastGetInstanceVariable("@original_script");
}
@JRubyMethod(name = "inspect")
public static IRubyObject compiled_script_inspect(IRubyObject recv) {
- return recv.getRuntime().newString("#<JRuby::CompiledScript " + recv.fastGetInstanceVariable("@name") + ">");
+ return recv.getRuntime().newString("#<JRuby::CompiledScript " + recv.getInstanceVariables().fastGetInstanceVariable("@name") + ">");
}
@JRubyMethod(name = "inspect_bytecode")
public static IRubyObject compiled_script_inspect_bytecode(IRubyObject recv) {
- java.io.StringWriter sw = new java.io.StringWriter();
- org.objectweb.asm.ClassReader cr = new org.objectweb.asm.ClassReader((byte[])org.jruby.javasupport.JavaUtil.convertRubyToJava(recv.fastGetInstanceVariable("@code"),byte[].class));
- org.objectweb.asm.util.TraceClassVisitor cv = new org.objectweb.asm.util.TraceClassVisitor(new java.io.PrintWriter(sw));
+ StringWriter sw = new StringWriter();
+ ClassReader cr = new ClassReader((byte[])org.jruby.javasupport.JavaUtil.convertRubyToJava(recv.getInstanceVariables().fastGetInstanceVariable("@code"),byte[].class));
+ TraceClassVisitor cv = new TraceClassVisitor(new PrintWriter(sw));
cr.accept(cv, ClassReader.SKIP_DEBUG);
return recv.getRuntime().newString(sw.toString());
}
View
85 src/org/jruby/RubyKernel.java
@@ -55,10 +55,14 @@
import org.jruby.exceptions.MainExitException;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.JumpTarget;
+import org.jruby.javasupport.util.RuntimeHelpers;
+import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.Arity;
+import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallType;
import org.jruby.runtime.CallbackFactory;
+import org.jruby.runtime.Frame;
import org.jruby.runtime.MethodIndex;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
@@ -68,6 +72,7 @@
import org.jruby.util.IdUtil;
import org.jruby.util.ShellLauncher;
import org.jruby.util.Sprintf;
+import org.jruby.util.TypeConverter;
/**
* Note: For CVS history, see KernelModule.java.
@@ -102,7 +107,7 @@ public static IRubyObject at_exit(IRubyObject recv, Block block) {
@JRubyMethod(name = "autoload?", required = 1, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject autoload_p(final IRubyObject recv, IRubyObject symbol) {
RubyModule module = recv instanceof RubyModule ? (RubyModule) recv : recv.getRuntime().getObject();
- String name = module.getName() + "::" + symbol.asSymbol();
+ String name = module.getName() + "::" + symbol.asInternedString();
IAutoloadMethod autoloadMethod = recv.getRuntime().getLoadService().autoloadFor(name);
if (autoloadMethod == null) return recv.getRuntime().getNil();
@@ -114,7 +119,7 @@ public static IRubyObject autoload_p(final IRubyObject recv, IRubyObject symbol)
public static IRubyObject autoload(final IRubyObject recv, IRubyObject symbol, final IRubyObject file) {
Ruby runtime = recv.getRuntime();
final LoadService loadService = runtime.getLoadService();
- final String baseName = symbol.asSymbol(); // interned, OK for "fast" methods
+ final String baseName = symbol.asInternedString(); // interned, OK for "fast" methods
final RubyModule module = recv instanceof RubyModule ? (RubyModule) recv : runtime.getObject();
String nm = module.getName() + "::" + baseName;
@@ -149,7 +154,7 @@ public static IRubyObject method_missing(IRubyObject recv, IRubyObject[] args, B
if (args.length == 0 || !(args[0] instanceof RubySymbol)) throw runtime.newArgumentError("no id given");
- String name = args[0].asSymbol();
+ String name = args[0].asInternedString();
ThreadContext context = runtime.getCurrentContext();
Visibility lastVis = context.getLastVisibility();
CallType lastCallType = context.getLastCallType();
@@ -298,7 +303,7 @@ public static IRubyObject new_float(IRubyObject recv, IRubyObject object) {
}else if(object.isNil()){
throw recv.getRuntime().newTypeError("can't convert nil into Float");
} else {
- RubyFloat rFloat = (RubyFloat)object.convertToType(recv.getRuntime().getFloat(), MethodIndex.TO_F, "to_f");
+ RubyFloat rFloat = (RubyFloat)TypeConverter.convertToType(object, recv.getRuntime().getFloat(), MethodIndex.TO_F, "to_f");
if (Double.isNaN(rFloat.getDoubleValue())) throw recv.getRuntime().newArgumentError("invalid value for Float()");
return rFloat;
}
@@ -317,14 +322,14 @@ public static IRubyObject new_integer(IRubyObject recv, IRubyObject object) {
return RubyNumeric.str2inum(recv.getRuntime(),(RubyString)object,0,true);
}
- IRubyObject tmp = object.convertToType(recv.getRuntime().getInteger(), MethodIndex.TO_INT, "to_int", false);
+ IRubyObject tmp = TypeConverter.convertToType(object, recv.getRuntime().getInteger(), MethodIndex.TO_INT, "to_int", false);
if (tmp.isNil()) return object.convertToInteger(MethodIndex.TO_I, "to_i");
return tmp;
}
@JRubyMethod(name = "String", required = 1, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject new_string(IRubyObject recv, IRubyObject object) {
- return object.convertToType(recv.getRuntime().getString(), MethodIndex.TO_S, "to_s");
+ return TypeConverter.convertToType(object, recv.getRuntime().getString(), MethodIndex.TO_S, "to_s");
}
@JRubyMethod(name = "p", rest = true, module = true, visibility = Visibility.PRIVATE)
@@ -650,7 +655,7 @@ public static IRubyObject raise(IRubyObject recv, IRubyObject[] args, Block bloc
exception = args[0].callMethod(context, "exception", args[1]);
}
- if (!exception.isKindOf(runtime.fastGetClass("Exception"))) {
+ if (!runtime.fastGetClass("Exception").isInstance(exception)) {
throw runtime.newTypeError("exception object expected");
}
@@ -685,40 +690,54 @@ public static IRubyObject load(IRubyObject recv, IRubyObject arg1, Block block)
@JRubyMethod(name = "eval", required = 1, optional = 3, frame = true, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject eval(IRubyObject recv, IRubyObject[] args, Block block) {
- if (args == null || args.length == 0) {
- throw recv.getRuntime().newArgumentError(args.length, 1);
- }
+ Ruby runtime = recv.getRuntime();
+ // string to eval
RubyString src = args[0].convertToString();
+ runtime.checkSafeString(src);
+
IRubyObject scope = null;
String file = "(eval)";
int line = 1;
+
+ // determine scope and position
+ if (args.length > 1 && !args[1].isNil()) {
+ scope = args[1];
+
+ Binding binding;
+ if (scope instanceof RubyBinding) {
+ binding = ((RubyBinding)scope).getBinding();
+ } else if (scope instanceof RubyProc) {
+ RubyProc proc = (RubyProc)scope;
+ binding = proc.getBlock().getBinding();
+ } else {
+ throw runtime.newTypeError("Wrong argument type " + scope.getMetaClass() + "(expected Proc/Binding)");
+ }
- if (args.length > 1) {
- if (!args[1].isNil()) {
- scope = args[1];
+ Frame frame = binding.getFrame();
+ ISourcePosition pos = frame.getPosition();
- org.jruby.lexer.yacc.ISourcePosition pos = ((scope instanceof RubyBinding) ? (RubyBinding)scope : (RubyBinding)((RubyProc)scope).binding()).getBinding().getFrame().getPosition();
- file = pos.getFile();
- line = pos.getEndLine();
- }
+ file = pos.getFile();
+ line = pos.getEndLine();
+ } else {
+ scope = RubyBinding.newBindingForEval(runtime);
+ }
- if (args.length > 2) {
- file = args[2].toString();
- }
-
- if(args.length > 3) {
- line = RubyNumeric.fix2int(args[3]) - 1;
- }
+ // if we have additional args, use them for file and line number
+ if (args.length > 2) {
+ file = args[2].convertToString().toString();
+ } else {
+ file = "(eval)";
}
- recv.getRuntime().checkSafeString(src);
- ThreadContext context = recv.getRuntime().getCurrentContext();
-
- if (scope == null) {
- scope = RubyBinding.newBindingForEval(recv.getRuntime());
+ if (args.length > 3) {
+ line = (int)args[3].convertToInteger().getLongValue();
+ } else {
+ line = 1;
}
+ ThreadContext context = runtime.getCurrentContext();
+
return ASTInterpreter.evalWithBinding(context, src, scope, file, line);
}
@@ -745,7 +764,7 @@ public static IRubyObject caller(IRubyObject recv, IRubyObject[] args, Block blo
@JRubyMethod(name = "catch", required = 1, frame = true, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject rbCatch(IRubyObject recv, IRubyObject tag, Block block) {
ThreadContext context = recv.getRuntime().getCurrentContext();
- CatchTarget target = new CatchTarget(tag.asSymbol());
+ CatchTarget target = new CatchTarget(tag.asInternedString());
try {
context.pushCatch(target);
return block.yield(context, tag);
@@ -768,7 +787,7 @@ public static IRubyObject rbCatch(IRubyObject recv, IRubyObject tag, Block block
public static IRubyObject rbThrow(IRubyObject recv, IRubyObject[] args, Block block) {
Ruby runtime = recv.getRuntime();
- String tag = args[0].asSymbol();
+ String tag = args[0].asInternedString();
ThreadContext context = runtime.getCurrentContext();
CatchTarget[] catches = context.getActiveCatches();
@@ -789,7 +808,7 @@ public static IRubyObject rbThrow(IRubyObject recv, IRubyObject[] args, Block bl
@JRubyMethod(name = "trap", required = 1, frame = true, optional = 1, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject trap(IRubyObject recv, IRubyObject[] args, Block block) {
recv.getRuntime().getLoadService().require("jsignal");
- return recv.callMethod(recv.getRuntime().getCurrentContext(), "__jtrap", args, CallType.FUNCTIONAL, block);
+ return RuntimeHelpers.invoke(recv.getRuntime().getCurrentContext(), recv, "__jtrap", args, CallType.FUNCTIONAL, block);
}
@JRubyMethod(name = "warn", required = 1, module = true, visibility = Visibility.PRIVATE)
@@ -833,7 +852,7 @@ public static IRubyObject trace_var(IRubyObject recv, IRubyObject[] args, Block
proc = RubyProc.newProc(recv.getRuntime(), block, Block.Type.PROC);
}
if (args.length == 2) {
- proc = (RubyProc)args[1].convertToType(recv.getRuntime().getProc(), 0, "to_proc", true);
+ proc = (RubyProc)TypeConverter.convertToType(args[1], recv.getRuntime().getProc(), 0, "to_proc", true);
}
recv.getRuntime().getGlobalVariables().setTraceVar(var, proc);
View
3  src/org/jruby/RubyMarshal.java
@@ -40,6 +40,7 @@
import java.io.OutputStream;
import org.jruby.anno.JRubyMethod;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallbackFactory;
import org.jruby.runtime.Constants;
@@ -149,7 +150,7 @@ public static IRubyObject load(IRubyObject recv, IRubyObject[] args, Block unuse
if (in != null && in.respondsTo("read")) {
rawInput = inputStream(in);
} else if (in != null && in.respondsTo("to_str")) {
- RubyString inString = (RubyString) in.callMethod(recv.getRuntime().getCurrentContext(), MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY);
+ RubyString inString = (RubyString) RuntimeHelpers.invoke(recv.getRuntime().getCurrentContext(), in, MethodIndex.TO_STR, "to_str", IRubyObject.NULL_ARRAY);
ByteList bytes = inString.getByteList();
rawInput = new ByteArrayInputStream(bytes.unsafeBytes(), bytes.begin(), bytes.length());
} else {
View
74 src/org/jruby/RubyModule.java
@@ -142,6 +142,10 @@ public boolean isKindOf(IRubyObject obj, RubyModule type) {
return obj.getMetaClass().hasModuleInHierarchy(type);
}
}
+
+ public boolean isInstance(IRubyObject object) {
+ return kindOf.isKindOf(object, this);
+ }
public KindOf kindOf = KindOf.DEFAULT_KIND_OF;
@@ -942,7 +946,7 @@ private void addAccessor(String internedName, boolean readable, boolean writeabl
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
if (args.length != 0) Arity.raiseArgumentError(runtime, args.length, 0, 0);
- IRubyObject variable = self.fastGetInstanceVariable(variableName);
+ IRubyObject variable = self.getInstanceVariables().fastGetInstanceVariable(variableName);
return variable == null ? runtime.getNil() : variable;
}
@@ -961,7 +965,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
// ENEBO: Can anyone get args to be anything but length 1?
if (args.length != 1) Arity.raiseArgumentError(runtime, args.length, 1, 1);
- return self.fastSetInstanceVariable(variableName, args[0]);
+ return self.getInstanceVariables().fastSetInstanceVariable(variableName, args[0]);
}
public Arity getArity() {
@@ -981,7 +985,7 @@ public void setMethodVisibility(IRubyObject[] methods, Visibility visibility) {
}
for (int i = 0; i < methods.length; i++) {
- exportMethod(methods[i].asSymbol(), visibility);
+ exportMethod(methods[i].asInternedString(), visibility);
}
}
@@ -1048,7 +1052,7 @@ public IRubyObject define_method(IRubyObject[] args, Block block) {
}
IRubyObject body;
- String name = args[0].asSymbol();
+ String name = args[0].asInternedString();
DynamicMethod newMethod = null;
ThreadContext tc = getRuntime().getCurrentContext();
Visibility visibility = tc.getCurrentVisibility();
@@ -1066,13 +1070,13 @@ public IRubyObject define_method(IRubyObject[] args, Block block) {
proc.getBlock().getBinding().getFrame().setName(name);
// for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope
- proc.getBlock().getBinding().getDynamicScope().getStaticScope().setArgumentScope(true);
+ proc.getBlock().getBody().getStaticScope().setArgumentScope(true);
// just using required is broken...but no more broken than before zsuper refactoring
- proc.getBlock().getBinding().getDynamicScope().getStaticScope().setRequiredArgs(proc.getBlock().arity().required());
+ proc.getBlock().getBody().getStaticScope().setRequiredArgs(proc.getBlock().arity().required());
newMethod = new ProcMethod(this, proc, visibility);
} else if (args.length == 2) {
- if (args[1].isKindOf(getRuntime().getProc())) {
+ if (getRuntime().getProc().isInstance(args[1])) {
// double-testing args.length here, but it avoids duplicating the proc-setup code in two places
RubyProc proc = (RubyProc)args[1];
body = proc;
@@ -1081,12 +1085,12 @@ public IRubyObject define_method(IRubyObject[] args, Block block) {
proc.getBlock().getBinding().getFrame().setName(name);
// for zsupers in define_method (blech!) we tell the proc scope to act as the "argument" scope
- proc.getBlock().getBinding().getDynamicScope().getStaticScope().setArgumentScope(true);
+ proc.getBlock().getBody().getStaticScope().setArgumentScope(true);
// just using required is broken...but no more broken than before zsuper refactoring
- proc.getBlock().getBinding().getDynamicScope().getStaticScope().setRequiredArgs(proc.getBlock().arity().required());
+ proc.getBlock().getBody().getStaticScope().setRequiredArgs(proc.getBlock().arity().required());
newMethod = new ProcMethod(this, proc, visibility);
- } else if (args[1].isKindOf(getRuntime().getMethod())) {
+ } else if (getRuntime().getMethod().isInstance(args[1])) {
RubyMethod method = (RubyMethod)args[1];
body = method;
@@ -1258,7 +1262,7 @@ public IRubyObject to_s() {
*/
@JRubyMethod(name = "===", required = 1)
public RubyBoolean op_eqq(IRubyObject obj) {
- return getRuntime().newBoolean(obj.isKindOf(this));
+ return getRuntime().newBoolean(isInstance(obj));
}
@JRubyMethod(name = "==", required = 1)
@@ -1381,7 +1385,7 @@ public IRubyObject attr(IRubyObject[] args) {
Arity.checkArgumentCount(getRuntime(), args, 1, 2);
boolean writeable = args.length > 1 ? args[1].isTrue() : false;
- addAccessor(args[0].asSymbol(), true, writeable);
+ addAccessor(args[0].asInternedString(), true, writeable);
return getRuntime().getNil();
}
@@ -1392,7 +1396,7 @@ public IRubyObject attr(IRubyObject[] args) {
@JRubyMethod(name = "attr_reader", required = 1, rest = true, visibility = Visibility.PRIVATE)
public IRubyObject attr_reader(IRubyObject[] args) {
for (int i = 0; i < args.length; i++) {
- addAccessor(args[i].asSymbol(), true, false);
+ addAccessor(args[i].asInternedString(), true, false);
}
return getRuntime().getNil();
@@ -1404,7 +1408,7 @@ public IRubyObject attr_reader(IRubyObject[] args) {
@JRubyMethod(name = "attr_writer", required = 1, rest = true, visibility = Visibility.PRIVATE)
public IRubyObject attr_writer(IRubyObject[] args) {
for (int i = 0; i < args.length; i++) {
- addAccessor(args[i].asSymbol(), false, true);
+ addAccessor(args[i].asInternedString(), false, true);
}
return getRuntime().getNil();
@@ -1416,7 +1420,7 @@ public IRubyObject attr_writer(IRubyObject[] args) {
@JRubyMethod(name = "attr_accessor", required = 1, rest = true, visibility = Visibility.PRIVATE)
public IRubyObject attr_accessor(IRubyObject[] args) {
for (int i = 0; i < args.length; i++) {
- addAccessor(args[i].asSymbol(), true, true);
+ addAccessor(args[i].asInternedString(), true, true);
}
return getRuntime().getNil();
@@ -1475,7 +1479,7 @@ public RubyArray public_instance_methods(IRubyObject[] args) {
@JRubyMethod(name = "instance_method", required = 1)
public IRubyObject instance_method(IRubyObject symbol) {
- return newMethod(null, symbol.asSymbol(), false);
+ return newMethod(null, symbol.asInternedString(), false);
}
/** rb_class_protected_instance_methods
@@ -1603,7 +1607,7 @@ public RubyModule module_function(IRubyObject[] args) {
setMethodVisibility(args, Visibility.PRIVATE);
for (int i = 0; i < args.length; i++) {
- String name = args[i].asSymbol();
+ String name = args[i].asInternedString();
DynamicMethod method = searchMethod(name);
assert !method.isUndefined() : "undefined method '" + name + "'";
getSingletonClass().addMethod(name, new WrapperMethod(getSingletonClass(), method, Visibility.PUBLIC));
@@ -1630,26 +1634,26 @@ public IRubyObject method_undefined(IRubyObject nothing) {
@JRubyMethod(name = "method_defined?", required = 1)
public RubyBoolean method_defined_p(IRubyObject symbol) {
- return isMethodBound(symbol.asSymbol(), true) ? getRuntime().getTrue() : getRuntime().getFalse();
+ return isMethodBound(symbol.asInternedString(), true) ? getRuntime().getTrue() : getRuntime().getFalse();
}
@JRubyMethod(name = "public_method_defined?", required = 1)
public IRubyObject public_method_defined(IRubyObject symbol) {
- DynamicMethod method = searchMethod(symbol.asSymbol());
+ DynamicMethod method = searchMethod(symbol.asInternedString());
return getRuntime().newBoolean(!method.isUndefined() && method.getVisibility() == Visibility.PUBLIC);
}
@JRubyMethod(name = "protected_method_defined?", required = 1)
public IRubyObject protected_method_defined(IRubyObject symbol) {
- DynamicMethod method = searchMethod(symbol.asSymbol());
+ DynamicMethod method = searchMethod(symbol.asInternedString());
return getRuntime().newBoolean(!method.isUndefined() && method.getVisibility() == Visibility.PROTECTED);
}
@JRubyMethod(name = "private_method_defined?", required = 1)
public IRubyObject private_method_defined(IRubyObject symbol) {
- DynamicMethod method = searchMethod(symbol.asSymbol());
+ DynamicMethod method = searchMethod(symbol.asInternedString());
return getRuntime().newBoolean(!method.isUndefined() && method.getVisibility() == Visibility.PRIVATE);
}
@@ -1668,7 +1672,7 @@ public RubyModule private_class_method(IRubyObject[] args) {
@JRubyMethod(name = "alias_method", required = 2, visibility = Visibility.PRIVATE)
public RubyModule alias_method(IRubyObject newId, IRubyObject oldId) {
- defineAlias(newId.asSymbol(), oldId.asSymbol());
+ defineAlias(newId.asInternedString(), oldId.asInternedString());
callMethod(getRuntime().getCurrentContext(), "method_added", newId);
return this;
}
@@ -1676,7 +1680,7 @@ public RubyModule alias_method(IRubyObject newId, IRubyObject oldId) {
@JRubyMethod(name = "undef_method", required = 1, rest = true, visibility = Visibility.PRIVATE)
public RubyModule undef_method(IRubyObject[] args) {
for (int i=0; i<args.length; i++) {
- undef(args[i].asSymbol());
+ undef(args[i].asInternedString());
}
return this;
}
@@ -1689,7 +1693,7 @@ public IRubyObject module_eval(IRubyObject[] args, Block block) {
@JRubyMethod(name = "remove_method", required = 1, rest = true, visibility = Visibility.PRIVATE)
public RubyModule remove_method(IRubyObject[] args) {
for(int i=0;i<args.length;i++) {
- removeMethod(args[i].asSymbol());
+ removeMethod(args[i].asInternedString());
}
return this;
}
@@ -1782,7 +1786,7 @@ private void doIncludeModule(RubyModule includedModule) {
@JRubyMethod(name = "class_variable_defined?", required = 1)
public IRubyObject class_variable_defined_p(IRubyObject var) {
- String internedName = validateClassVariable(var.asSymbol());
+ String internedName = validateClassVariable(var.asInternedString());
RubyModule module = this;
do {
if (module.fastHasClassVariable(internedName)) {
@@ -1798,7 +1802,7 @@ public IRubyObject class_variable_defined_p(IRubyObject var) {
*/
@JRubyMethod(name = "class_variable_get", required = 1, visibility = Visibility.PRIVATE)
public IRubyObject class_variable_get(IRubyObject var) {
- return fastGetClassVar(validateClassVariable(var.asSymbol()));
+ return fastGetClassVar(validateClassVariable(var.asInternedString()));
}
/** rb_mod_cvar_set
@@ -1806,7 +1810,7 @@ public IRubyObject class_variable_get(IRubyObject var) {
*/
@JRubyMethod(name = "class_variable_set", required = 2, visibility = Visibility.PRIVATE)
public IRubyObject class_variable_set(IRubyObject var, IRubyObject value) {
- return fastSetClassVar(validateClassVariable(var.asSymbol()), value);
+ return fastSetClassVar(validateClassVariable(var.asInternedString()), value);
}
/** rb_mod_remove_cvar
@@ -1814,7 +1818,7 @@ public IRubyObject class_variable_set(IRubyObject var, IRubyObject value) {
*/
@JRubyMethod(name = "remove_class_variable", required = 1, visibility = Visibility.PRIVATE)
public IRubyObject remove_class_variable(IRubyObject name) {
- String internedName = validateClassVariable(name.asSymbol());
+ String internedName = validateClassVariable(name.asInternedString());
IRubyObject value;
if ((value = deleteClassVariable(internedName)) != null) {
@@ -1862,7 +1866,7 @@ public RubyArray class_variables() {
@JRubyMethod(name = "const_defined?", required = 1)
public RubyBoolean const_defined_p(IRubyObject symbol) {
// Note: includes part of fix for JRUBY-1339
- return getRuntime().newBoolean(fastIsConstantDefined(validateConstant(symbol.asSymbol())));
+ return getRuntime().newBoolean(fastIsConstantDefined(validateConstant(symbol.asInternedString())));
}
/** rb_mod_const_get
@@ -1870,7 +1874,7 @@ public RubyBoolean const_defined_p(IRubyObject symbol) {
*/
@JRubyMethod(name = "const_get", required = 1)
public IRubyObject const_get(IRubyObject symbol) {
- return fastGetConstant(validateConstant(symbol.asSymbol()));
+ return fastGetConstant(validateConstant(symbol.asInternedString()));
}
/** rb_mod_const_set
@@ -1878,12 +1882,12 @@ public IRubyObject const_get(IRubyObject symbol) {
*/
@JRubyMethod(name = "const_set", required = 2)
public IRubyObject const_set(IRubyObject symbol, IRubyObject value) {
- return fastSetConstant(validateConstant(symbol.asSymbol()), value);
+ return fastSetConstant(validateConstant(symbol.asInternedString()), value);
}
@JRubyMethod(name = "remove_const", required = 1, visibility = Visibility.PRIVATE)
public IRubyObject remove_const(IRubyObject name) {
- String id = validateConstant(name.asSymbol());
+ String id = validateConstant(name.asInternedString());
IRubyObject value;
if ((value = deleteConstant(id)) != null) {
if (value != getRuntime().getUndef()) {
@@ -1921,10 +1925,10 @@ private boolean hasConstantInHierarchy(final String name) {
public IRubyObject const_missing(IRubyObject name, Block block) {
/* Uninitialized constant */
if (this != getRuntime().getObject()) {
- throw getRuntime().newNameError("uninitialized constant " + getName() + "::" + name.asSymbol(), "" + getName() + "::" + name.asSymbol());
+ throw getRuntime().newNameError("uninitialized constant " + getName() + "::" + name.asInternedString(), "" + getName() + "::" + name.asInternedString());
}
- throw getRuntime().newNameError("uninitialized constant " + name.asSymbol(), name.asSymbol());
+ throw getRuntime().newNameError("uninitialized constant " + name.asInternedString(), name.asInternedString());
}
/** rb_mod_constants
@@ -2064,7 +2068,7 @@ public boolean fastIsClassVarDefined(String internedName) {
* FIXME: any good reason to have two identical methods? (same as remove_class_variable)
*/
public IRubyObject removeCvar(IRubyObject name) { // Wrong Parameter ?
- String internedName = validateClassVariable(name.asSymbol());
+ String internedName = validateClassVariable(name.asInternedString());
IRubyObject value;
if ((value = deleteClassVariable(internedName)) != null) {
View
3  src/org/jruby/RubyNumeric.java
@@ -37,6 +37,7 @@
import java.math.BigInteger;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallbackFactory;
import org.jruby.runtime.MethodIndex;
@@ -602,7 +603,7 @@ public IRubyObject abs() {
*/
@JRubyMethod(name = "to_int")
public IRubyObject to_int() {
- return callMethod(getRuntime().getCurrentContext(), MethodIndex.TO_I, "to_i", IRubyObject.NULL_ARRAY);
+ return RuntimeHelpers.invoke(getRuntime().getCurrentContext(), this, MethodIndex.TO_I, "to_i", IRubyObject.NULL_ARRAY);
}
/** num_int_p
View
161 src/org/jruby/RubyObject.java
@@ -40,16 +40,13 @@
package org.jruby;
import java.io.IOException;
-import java.io.ObjectInput;
import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jruby.evaluator.ASTInterpreter;
import org.jruby.exceptions.JumpException;
import org.jruby.internal.runtime.methods.DynamicMethod;
-import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallType;
@@ -68,17 +65,19 @@
import java.util.List;
import java.util.Map;
import org.jruby.anno.JRubyMethod;
-import org.jruby.ast.Node;
import org.jruby.javasupport.util.RuntimeHelpers;
-import org.jruby.runtime.Binding;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.MethodIndex;
+import org.jruby.runtime.builtin.InstanceVariables;
+import org.jruby.runtime.builtin.InternalVariables;
+import org.jruby.runtime.marshal.CoreObjectType;
+import org.jruby.util.TypeConverter;
/**
*
* @author jpetersen
*/
-public class RubyObject implements Cloneable, IRubyObject, Serializable {
+public class RubyObject implements Cloneable, IRubyObject, Serializable, CoreObjectType, InstanceVariables, InternalVariables {
private RubyObject(){};
// An instance that never equals any other instance
@@ -272,7 +271,7 @@ public boolean equals(Object other) {
}
public String toString() {
- return callMethod(getRuntime().getCurrentContext(), MethodIndex.TO_S, "to_s", IRubyObject.NULL_ARRAY).toString();
+ return RuntimeHelpers.invoke(getRuntime().getCurrentContext(), this, MethodIndex.TO_S, "to_s", IRubyObject.NULL_ARRAY).toString();
}
/** Getter for property ruby.
@@ -374,10 +373,6 @@ public boolean respondsTo(String name) {
}
}
- public boolean isKindOf(RubyModule type) {
- return type.kindOf.isKindOf(this, type);
- }
-
/** rb_singleton_class
* Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean
*/
@@ -457,58 +452,26 @@ public IRubyObject callSuper(ThreadContext context, IRubyObject[] args, Block bl
assert superClass != null : "Superclass should always be something for " + klazz.getBaseName();
- return callMethod(context, superClass, context.getFrameName(), args, CallType.SUPER, block);
+ return RuntimeHelpers.invokeAs(context, superClass, this, context.getFrameName(), args, CallType.SUPER, block);
}
public IRubyObject callMethod(ThreadContext context, String name) {
- return callMethod(context, getMetaClass(), name, IRubyObject.NULL_ARRAY, null, Block.NULL_BLOCK);
+ return RuntimeHelpers.invoke(context, this, name, IRubyObject.NULL_ARRAY, null, Block.NULL_BLOCK);
}
public IRubyObject callMethod(ThreadContext context, String name, IRubyObject arg) {
- return callMethod(context, getMetaClass(), name, new IRubyObject[] { arg }, CallType.FUNCTIONAL, Block.NULL_BLOCK);
+ return RuntimeHelpers.invoke(context, this, name, new IRubyObject[] { arg }, CallType.FUNCTIONAL, Block.NULL_BLOCK);
}
public IRubyObject callMethod(ThreadContext context, String name, IRubyObject[] args) {
- return callMethod(context, getMetaClass(), name, args, CallType.FUNCTIONAL, Block.NULL_BLOCK);
+ return RuntimeHelpers.invoke(context, this, name, args, CallType.FUNCTIONAL, Block.NULL_BLOCK);
}
public IRubyObject callMethod(ThreadContext context, String name, IRubyObject[] args, Block block) {
- return callMethod(context, getMetaClass(), name, args, CallType.FUNCTIONAL, block);
- }
- public IRubyObject callMethod(ThreadContext context, String name, IRubyObject[] args, CallType callType, Block block) {
- return callMethod(context, getMetaClass(), name, args, callType, block);
+ return RuntimeHelpers.invoke(context, this, name, args, CallType.FUNCTIONAL, block);
}
public IRubyObject callMethod(ThreadContext context, int methodIndex, String name) {
- return callMethod(context, getMetaClass(), methodIndex, name, IRubyObject.NULL_ARRAY, null, Block.NULL_BLOCK);
+ return RuntimeHelpers.invoke(context, this, methodIndex, name, IRubyObject.NULL_ARRAY, null, Block.NULL_BLOCK);
}
public IRubyObject callMethod(ThreadContext context, int methodIndex, String name, IRubyObject arg) {
- return callMethod(context,getMetaClass(),methodIndex,name,new IRubyObject[]{arg},CallType.FUNCTIONAL, Block.NULL_BLOCK);
- }
- public IRubyObject callMethod(ThreadContext context, int methodIndex, String name, IRubyObject[] args) {
- return callMethod(context,getMetaClass(),methodIndex,name,args,CallType.FUNCTIONAL, Block.NULL_BLOCK);
- }
- public IRubyObject callMethod(ThreadContext context, RubyModule rubyclass, int methodIndex, String name, IRubyObject[] args, CallType callType) {
- return callMethod(context, rubyclass, methodIndex, name, args, callType, Block.NULL_BLOCK);
- }
-
- public IRubyObject callMethod(ThreadContext context, RubyModule rubyclass, int methodIndex, String name, IRubyObject[] args, CallType callType, Block block) {
- if (context.getRuntime().hasEventHooks()) return callMethod(context, rubyclass, name, args, callType, block);
-
- return rubyclass.dispatcher.callMethod(context, this, rubyclass, methodIndex, name, args, callType, block);
- }
-
- /**
- *
- */
- public IRubyObject callMethod(ThreadContext context, RubyModule rubyclass, String name,
- IRubyObject[] args, CallType callType, Block block) {
- assert args != null;
- DynamicMethod method = null;
- method = rubyclass.searchMethod(name);
-
-
- if (method.isUndefined() || (!name.equals("method_missing") && !method.isCallableFrom(context.getFrameSelf(), callType))) {
- return RuntimeHelpers.callMethodMissing(context, this, method, name, args, context.getFrameSelf(), callType, block);
- }
-
- return method.call(context, this, rubyclass, name, args, block);
+ return RuntimeHelpers.invoke(context, this, methodIndex,name,new IRubyObject[]{arg},CallType.FUNCTIONAL, Block.NULL_BLOCK);
}
public void callInit(IRubyObject[] args, Block block) {
@@ -518,22 +481,22 @@ public void callInit(IRubyObject[] args, Block block) {
/** rb_to_id
*
*/
- public String asSymbol() {
+ public String asInternedString() {
IRubyObject asString = checkStringType();
- if(!asString.isNil()) return ((RubyString)asString).asSymbol();
+ if(!asString.isNil()) return ((RubyString)asString).asInternedString();
throw getRuntime().newTypeError(inspect().toString() + " is not a symbol");
}
public RubyArray convertToArray() {
- return (RubyArray) convertToType(getRuntime().getArray(), MethodIndex.TO_ARY, "to_ary");
+ return (RubyArray) TypeConverter.convertToType(this, getRuntime().getArray(), MethodIndex.TO_ARY, "to_ary");
}
public RubyHash convertToHash() {
- return (RubyHash)convertToType(getRuntime().getHash(), MethodIndex.TO_HASH, "to_hash");
+ return (RubyHash)TypeConverter.convertToType(this, getRuntime().getHash(), MethodIndex.TO_HASH, "to_hash");
}
public RubyFloat convertToFloat() {
- return (RubyFloat) convertToType(getRuntime().getFloat(), MethodIndex.TO_F, "to_f");
+ return (RubyFloat) TypeConverter.convertToType(this, getRuntime().getFloat(), MethodIndex.TO_F, "to_f");
}
public RubyInteger convertToInteger() {
@@ -541,69 +504,23 @@ public RubyInteger convertToInteger() {
}
public RubyInteger convertToInteger(int convertMethodIndex, String convertMethod) {
- IRubyObject val = convertToType(getRuntime().getInteger(), convertMethodIndex, convertMethod, true);
+ IRubyObject val = TypeConverter.convertToType(this, getRuntime().getInteger(), convertMethodIndex, convertMethod, true);
if (!(val instanceof RubyInteger)) throw getRuntime().newTypeError(getMetaClass().getName() + "#" + convertMethod + " should return Integer");
return (RubyInteger)val;
}
public RubyString convertToString() {
- return (RubyString) convertToType(getRuntime().getString(), MethodIndex.TO_STR, "to_str");
- }
-
- /** convert_type
- *
- */
- public final IRubyObject convertToType(RubyClass target, int convertMethodIndex, String convertMethod, boolean raise) {
- if (!respondsTo(convertMethod)) {
- if (raise) {
- String type;
- if (isNil()) {
- type = "nil";
- } else if (this instanceof RubyBoolean) {
- type = isTrue() ? "true" : "false";
- } else {
- type = target.getName();
- }
- throw getRuntime().newTypeError("can't convert " + getMetaClass().getName() + " into " + type);
- } else {
- return getRuntime().getNil();
- }
- }
- return callMethod(getRuntime().getCurrentContext(), convertMethodIndex, convertMethod);
+ return (RubyString) TypeConverter.convertToType(this, getRuntime().getString(), MethodIndex.TO_STR, "to_str");
}
public final IRubyObject convertToType(RubyClass target, int convertMethodIndex) {
-