Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove all code and references to the outdated and nonfunctional YARV…

… and RBX bytecode support. Both have evolved since, both will need a fresh look, and current interpreter is now much faster than either engine.
  • Loading branch information...
commit 2257c8f811fab8d675a942c86ab712922dc46c6f 1 parent da23e51
@headius headius authored
Showing with 21 additions and 3,645 deletions.
  1. +19 −68 src/org/jruby/Ruby.java
  2. +1 −25 src/org/jruby/RubyInstanceConfig.java
  3. +0 −60 src/org/jruby/ast/executable/RubiniusCMethod.java
  4. +0 −277 src/org/jruby/ast/executable/RubiniusInstructions.java
  5. +0 −341 src/org/jruby/ast/executable/RubiniusMachine.java
  6. +0 −176 src/org/jruby/ast/executable/RubiniusRunner.java
  7. +0 −215 src/org/jruby/ast/executable/YARVCompiledRunner.java
  8. +0 −422 src/org/jruby/ast/executable/YARVInstructions.java
  9. +0 −62 src/org/jruby/ast/executable/YARVInstructions.java.template
  10. +0 −720 src/org/jruby/ast/executable/YARVMachine.java
  11. +0 −4 src/org/jruby/compiler/ASTCompiler.java
  12. +0 −40 src/org/jruby/compiler/YARVNodesCompiler.java
  13. +0 −800 src/org/jruby/compiler/yarv/StandardYARVCompiler.java
  14. +0 −114 src/org/jruby/internal/runtime/methods/RubiniusMethod.java
  15. +0 −185 src/org/jruby/internal/runtime/methods/YARVMethod.java
  16. +0 −12 src/org/jruby/management/Config.java
  17. +0 −3  src/org/jruby/management/ConfigMBean.java
  18. +0 −117 test/org/jruby/ast/executable/YARVMachineTest.java
  19. +0 −2  test/org/jruby/test/MainTestSuite.java
  20. +1 −2  test/org/jruby/test/TestRubyBase.java
View
87 src/org/jruby/Ruby.java
@@ -71,17 +71,14 @@
import org.jcodings.Encoding;
import org.joda.time.DateTimeZone;
import org.jruby.ast.Node;
-import org.jruby.ast.executable.RubiniusRunner;
import org.jruby.ast.executable.Script;
-import org.jruby.ast.executable.YARVCompiledRunner;
import org.jruby.common.RubyWarnings;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.compiler.ASTCompiler;
import org.jruby.compiler.ASTInspector;
import org.jruby.compiler.JITCompiler;
-import org.jruby.compiler.NotCompilableException;
import org.jruby.compiler.impl.StandardASMCompiler;
-import org.jruby.compiler.yarv.StandardYARVCompiler;
+import org.jruby.compiler.NotCompilableException;
import org.jruby.exceptions.JumpException;
import org.jruby.exceptions.MainExitException;
import org.jruby.exceptions.RaiseException;
@@ -295,7 +292,7 @@ public IRubyObject executeScript(String script, String filename) {
int oldLine = context.getLine();
try {
context.setFileAndLine(node.getPosition());
- return runNormally(node, false);
+ return runNormally(node);
} finally {
context.setFileAndLine(oldFile, oldLine);
}
@@ -348,30 +345,22 @@ public void runFromMain(InputStream inputStream, String filename) {
return;
}
- if(config.isYARVEnabled()) {
- if (config.isShowBytecode()) System.err.print("error: bytecode printing only works with JVM bytecode");
- new YARVCompiledRunner(this, inputStream, filename).run();
- } else if(config.isRubiniusEnabled()) {
- if (config.isShowBytecode()) System.err.print("error: bytecode printing only works with JVM bytecode");
- new RubiniusRunner(this, inputStream, filename).run();
- } else {
- Node scriptNode = parseFromMain(inputStream, filename);
- ThreadContext context = getCurrentContext();
+ Node scriptNode = parseFromMain(inputStream, filename);
+ ThreadContext context = getCurrentContext();
- String oldFile = context.getFile();
- int oldLine = context.getLine();
- try {
- context.setFileAndLine(scriptNode.getPosition());
+ String oldFile = context.getFile();
+ int oldLine = context.getLine();
+ try {
+ context.setFileAndLine(scriptNode.getPosition());
- if (config.isAssumePrinting() || config.isAssumeLoop()) {
- runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
- config.isSplit(), config.isYARVCompileEnabled());
- } else {
- runNormally(scriptNode, config.isYARVCompileEnabled());
- }
- } finally {
- context.setFileAndLine(oldFile, oldLine);
+ if (config.isAssumePrinting() || config.isAssumeLoop()) {
+ runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
+ config.isSplit());
+ } else {
+ runNormally(scriptNode);
}
+ } finally {
+ context.setFileAndLine(oldFile, oldLine);
}
}
@@ -405,24 +394,20 @@ public Node parseFromMain(InputStream inputStream, String filename) {
* @param processLineEnds Whether line endings should be processed by
* setting $\ to $/ and <code>chop!</code>ing every line read
* @param split Whether to split each line read using <code>String#split</code>
- * @param yarvCompile Whether to compile the target script to YARV (Ruby 1.9)
* bytecode before executing.
* @return The result of executing the specified script
*/
- public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split, boolean yarvCompile) {
+ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split) {
ThreadContext context = getCurrentContext();
Script script = null;
- YARVCompiledRunner runner = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
- if (compile || !yarvCompile) {
+ if (compile) {
script = tryCompile(scriptNode);
if (compile && script == null) {
// terminate; tryCompile will have printed out an error and we're done
return getNil();
}
- } else if (yarvCompile) {
- runner = tryCompileYarv(scriptNode);
}
if (processLineEnds) {
@@ -447,8 +432,6 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
if (script != null) {
runScriptBody(script);
- } else if (runner != null) {
- runYarv(runner);
} else {
runInterpreterBody(scriptNode);
}
@@ -478,19 +461,14 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
* code.
*
* @param scriptNode The root node of the script to be executed
- * @param yarvCompile Whether to compile the script to YARV (Ruby 1.9)
* bytecode before execution
* @return The result of executing the script
*/
- public IRubyObject runNormally(Node scriptNode, boolean yarvCompile) {
+ public IRubyObject runNormally(Node scriptNode) {
Script script = null;
- YARVCompiledRunner runner = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
boolean forceCompile = getInstanceConfig().getCompileMode().shouldPrecompileAll();
- if (yarvCompile) {
- runner = tryCompileYarv(scriptNode);
- // FIXME: Once 1.9 compilation is supported this should be removed
- } else if (compile) {
+ if (compile) {
script = tryCompile(scriptNode);
if (forceCompile && script == null) {
return getNil();
@@ -503,8 +481,6 @@ public IRubyObject runNormally(Node scriptNode, boolean yarvCompile) {
} else {
return runScript(script);
}
- } else if (runner != null) {
- return runYarv(runner);
} else {
if (config.isShowBytecode()) System.err.print("error: bytecode printing only works with JVM bytecode");
return runInterpreter(scriptNode);
@@ -577,23 +553,6 @@ private Script tryCompile(Node node, JRubyClassLoader classLoader) {
return script;
}
- private YARVCompiledRunner tryCompileYarv(Node node) {
- try {
- StandardYARVCompiler compiler = new StandardYARVCompiler(this);
- ASTCompiler.getYARVCompiler().compile(node, compiler);
- org.jruby.lexer.yacc.ISourcePosition p = node.getPosition();
- if(p == null && node instanceof org.jruby.ast.RootNode) {
- p = ((org.jruby.ast.RootNode)node).getBodyNode().getPosition();
- }
- return new YARVCompiledRunner(this,compiler.getInstructionSequence("<main>",p.getFile(),"toplevel"));
- } catch (NotCompilableException nce) {
- System.err.println("Error -- Not compileable: " + nce.getMessage());
- return null;
- } catch (JumpException.ReturnJump rj) {
- return null;
- }
- }
-
private IRubyObject runScript(Script script) {
ThreadContext context = getCurrentContext();
@@ -618,14 +577,6 @@ private IRubyObject runScriptBody(Script script) {
}
}
- private IRubyObject runYarv(YARVCompiledRunner runner) {
- try {
- return runner.run();
- } catch (JumpException.ReturnJump rj) {
- return (IRubyObject) rj.getValue();
- }
- }
-
public IRubyObject runInterpreter(Node scriptNode) {
ThreadContext context = getCurrentContext();
View
26 src/org/jruby/RubyInstanceConfig.java
@@ -161,9 +161,6 @@ public boolean shouldPrecompileAll() {
private boolean shouldRunInterpreter = true;
private boolean shouldPrintUsage = false;
private boolean shouldPrintProperties=false;
- private boolean yarv = false;
- private boolean rubinius = false;
- private boolean yarvCompile = false;
private KCode kcode = KCode.NONE;
private String recordSeparator = "\n";
private boolean shouldCheckSyntax = false;
@@ -406,10 +403,7 @@ public String getExtendedHelp() {
.append(" -O run with ObjectSpace disabled (default; improves performance)\n")
.append(" +O run with ObjectSpace enabled (reduces performance)\n")
.append(" -C disable all compilation\n")
- .append(" +C force compilation of all scripts before they are run (except eval)\n")
- .append(" -y read a YARV-compiled Ruby script and run that (EXPERIMENTAL)\n")
- .append(" -Y compile a Ruby script into YARV bytecodes and run this (EXPERIMENTAL)\n")
- .append(" -R read a Rubinius-compiled Ruby script and run that (EXPERIMENTAL)\n");
+ .append(" +C force compilation of all scripts before they are run (except eval)\n");
return sb.toString();
}
@@ -936,12 +930,6 @@ private void processArgument() {
compileMode = CompileMode.OFF;
} else if (extendedOption.equals("+C")) {
compileMode = CompileMode.FORCE;
- } else if (extendedOption.equals("-y")) {
- yarv = true;
- } else if (extendedOption.equals("-Y")) {
- yarvCompile = true;
- } else if (extendedOption.equals("-R")) {
- rubinius = true;
} else {
MainExitException mee =
new MainExitException(1, "jruby: invalid extended option " + extendedOption + " (-X will list valid options)\n");
@@ -1234,22 +1222,10 @@ public boolean isShouldCheckSyntax() {
return shouldCheckSyntax;
}
- public boolean isYARVEnabled() {
- return yarv;
- }
-
public String getInputFieldSeparator() {
return inputFieldSeparator;
}
- public boolean isRubiniusEnabled() {
- return rubinius;
- }
-
- public boolean isYARVCompileEnabled() {
- return yarvCompile;
- }
-
public KCode getKCode() {
return kcode;
}
View
60 src/org/jruby/ast/executable/RubiniusCMethod.java
@@ -1,60 +0,0 @@
-/***** 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) 2007 Ola Bini <ola.bini@gmail.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 org.jruby.RubyArray;
-import org.jruby.RubyNumeric;
-import org.jruby.runtime.builtin.IRubyObject;
-
-/**
- * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
- */
-public class RubiniusCMethod {
- public String name;
- public String file;
- public int locals;
- public IRubyObject[] literals;
- public char[] code;
- public int required;
-
- public RubiniusCMethod(RubyArray obj) {
- code = obj.eltInternal(4).toString().toCharArray();
- name = obj.eltInternal(5).toString();
- file = obj.eltInternal(6).toString();
- locals = RubyNumeric.fix2int(obj.eltInternal(7));
- required = RubyNumeric.fix2int(obj.eltInternal(2));
- literals = toArray(obj.eltInternal(8));
- }
-
- private final IRubyObject[] toArray(IRubyObject oo) {
- if(oo.isNil()) {
- return new IRubyObject[0];
- }
- return (IRubyObject[])((RubyArray)oo).toArray(new IRubyObject[0]);
- }
-}// RubiniusCMethod
View
277 src/org/jruby/ast/executable/RubiniusInstructions.java
@@ -1,277 +0,0 @@
-/***** 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) 2007 Ola Bini <ola.bini@gmail.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;
-
-/**
- * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
- */
-public abstract class RubiniusInstructions {
- public final static int NOOP=0;
- public final static int PUSH_NIL=1;
- public final static int PUSH_TRUE=2;
- public final static int PUSH_FALSE=3;
- public final static int ALLOCATE=4;
- public final static int SET_CLASS=5;
- public final static int STORE_FIELD=6;
- public final static int PUSH_INT=7;
- public final static int FETCH_FIELD=8;
- public final static int SEND_PRIMITIVE=9;
- public final static int PUSH_CONTEXT=10;
- public final static int PUSH_LITERAL=11;
- public final static int PUSH_SELF=12;
- public final static int GOTO=13;
- public final static int GOTO_IF_FALSE=14;
- public final static int GOTO_IF_TRUE=15;
- public final static int SWAP_STACK=16;
- public final static int SET_LOCAL=17;
- public final static int PUSH_LOCAL=18;
- public final static int PUSH_EXCEPTION=19;
- public final static int MAKE_ARRAY=20;
- public final static int SET_IVAR=21;
- public final static int PUSH_IVAR=22;
- public final static int GOTO_IF_DEFINED=23;
- public final static int PUSH_CONST=24;
- public final static int SET_CONST=25;
- public final static int SET_CONST_AT=26;
- public final static int FIND_CONST=27;
- public final static int ATTACH_METHOD=28;
- public final static int ADD_METHOD=29;
- public final static int OPEN_CLASS=30;
- public final static int OPEN_CLASS_UNDER=31;
- public final static int OPEN_MODULE=32;
- public final static int OPEN_MODULE_UNDER=33;
- public final static int UNSHIFT_TUPLE=34;
- public final static int CAST_TUPLE=35;
- public final static int MAKE_REST=36;
- public final static int DUP_TOP=37;
- public final static int POP=38;
- public final static int RET=39;
- public final static int SEND_METHOD=40;
- public final static int SEND_STACK=41;
- public final static int SEND_STACK_WITH_BLOCK=42;
- public final static int PUSH_BLOCK=43;
- public final static int CLEAR_EXCEPTION=44;
- public final static int SOFT_RETURN=45;
- public final static int CALLER_RETURN=46;
- public final static int PUSH_ARRAY=47;
- public final static int CAST_ARRAY=48;
- public final static int MAKE_HASH=49;
- public final static int RAISE_EXC=50;
- public final static int SET_ENCLOSER=51;
- public final static int PUSH_ENCLOSER=52;
- public final static int ACTIVATE_METHOD=53;
- public final static int PUSH_CPATH_TOP=54;
- public final static int CHECK_ARGCOUNT=55;
- public final static int PASSED_ARG=56;
- public final static int STRING_APPEND=57;
- public final static int STRING_DUP=58;
- public final static int SET_ARGS=59;
- public final static int GET_ARGS=60;
- public final static int SEND_WITH_ARG_REGISTER=61;
- public final static int CAST_ARRAY_FOR_ARGS=62;
- public final static int SEND_SUPER_STACK_WITH_BLOCK=63;
- public final static int PUSH_MY_FIELD=64;
- public final static int STORE_MY_FIELD=65;
- public final static int OPEN_METACLASS=66;
- public final static int SET_CACHE_INDEX=67;
- public final static int BLOCK_BREAK=68;
- public final static int SEND_SUPER_WITH_ARG_REGISTER=69;
- public final static int META_PUSH_NEG_1=70;
- public final static int META_PUSH_0=71;
- public final static int META_PUSH_1=72;
- public final static int META_PUSH_2=73;
- public final static int META_SEND_STACK_1=74;
- public final static int META_SEND_STACK_2=75;
- public final static int META_SEND_STACK_3=76;
- public final static int META_SEND_STACK_4=77;
- public final static int META_SEND_OP_PLUS=78;
- public final static int META_SEND_OP_MINUS=79;
- public final static int META_SEND_OP_EQUAL=80;
- public final static int META_SEND_OP_LT=81;
- public final static int META_SEND_OP_GT=82;
- public final static int META_SEND_OP_TEQUAL=83;
- public final static int META_SEND_OP_NEQUAL=84;
- public final static int PUSH_LOCAL_DEPTH=85;
- public final static int SET_LOCAL_DEPTH=86;
- public final static int CREATE_BLOCK=87;
- public final static int SEND_OFF_STACK=88;
- public final static int LOCATE_METHOD=89;
- public final static int KIND_OF=90;
- public final static int INSTANCE_OF=91;
- public final static int SET_CALL_FLAGS=92;
- public final static int YIELD_DEBUGGER=93;
-
- public final static boolean[] ONE_INT = new boolean[94];
- public final static boolean[] TWO_INT = new boolean[94];
-
- static {
- ONE_INT[PUSH_INT] = true;
- ONE_INT[PUSH_LITERAL] = true;
- ONE_INT[GOTO] = true;
- ONE_INT[GOTO_IF_FALSE] = true;
- ONE_INT[GOTO_IF_TRUE] = true;
- ONE_INT[GOTO_IF_DEFINED] = true;
- ONE_INT[SET_LOCAL] = true;
- ONE_INT[PUSH_LOCAL] = true;
- ONE_INT[MAKE_ARRAY] = true;
- ONE_INT[SET_IVAR] = true;
- ONE_INT[PUSH_IVAR] = true;
- ONE_INT[PUSH_CONST] = true;
- ONE_INT[SET_CONST] = true;
- ONE_INT[SET_CONST_AT] = true;
- ONE_INT[FIND_CONST] = true;
- ONE_INT[ATTACH_METHOD] = true;
- ONE_INT[ADD_METHOD] = true;
- ONE_INT[OPEN_CLASS] = true;
- ONE_INT[OPEN_CLASS_UNDER] = true;
- ONE_INT[OPEN_MODULE] = true;
- ONE_INT[OPEN_MODULE_UNDER] = true;
- ONE_INT[SEND_METHOD] = true;
- ONE_INT[MAKE_HASH] = true;
- ONE_INT[MAKE_REST] = true;
- ONE_INT[ACTIVATE_METHOD] = true;
- ONE_INT[PASSED_ARG] = true;
- ONE_INT[SEND_WITH_ARG_REGISTER] = true;
- ONE_INT[CAST_ARRAY_FOR_ARGS] = true;
- ONE_INT[PUSH_MY_FIELD] = true;
- ONE_INT[STORE_MY_FIELD] = true;
- ONE_INT[SET_CACHE_INDEX] = true;
- ONE_INT[SEND_SUPER_WITH_ARG_REGISTER] = true;
- ONE_INT[META_SEND_STACK_1] = true;
- ONE_INT[META_SEND_STACK_2] = true;
- ONE_INT[META_SEND_STACK_3] = true;
- ONE_INT[META_SEND_STACK_4] = true;
- ONE_INT[CREATE_BLOCK] = true;
- ONE_INT[SET_CALL_FLAGS] = true;
-
- TWO_INT[SEND_STACK] = true;
- TWO_INT[SEND_STACK_WITH_BLOCK] = true;
- TWO_INT[CHECK_ARGCOUNT] = true;
- TWO_INT[SEND_SUPER_STACK_WITH_BLOCK] = true;
- TWO_INT[SEND_PRIMITIVE] = true;
- TWO_INT[PUSH_LOCAL_DEPTH] = true;
- TWO_INT[SET_LOCAL_DEPTH] = true;
- }
-
- public static final String[] NAMES = new String[] {
- "noop",
- "push_nil",
- "push_true",
- "push_false",
- "allocate",
- "set_class",
- "store_field",
- "push_int",
- "fetch_field",
- "send_primitive",
- "push_context",
- "push_literal",
- "push_self",
- "goto",
- "goto_if_false",
- "goto_if_true",
- "swap_stack",
- "set_local",
- "push_local",
- "push_exception",
- "make_array",
- "set_ivar",
- "push_ivar",
- "goto_if_defined",
- "push_const",
- "set_const",
- "set_const_at",
- "find_const",
- "attach_method",
- "add_method",
- "open_class",
- "open_class_under",
- "open_module",
- "open_module_under",
- "unshift_tuple",
- "cast_tuple",
- "make_rest",
- "dup_top",
- "pop",
- "ret",
- "send_method",
- "send_stack",
- "send_stack_with_block",
- "push_block",
- "clear_exception",
- "soft_return",
- "caller_return",
- "push_array",
- "cast_array",
- "make_hash",
- "raise_exc",
- "set_encloser",
- "push_encloser",
- "activate_method",
- "push_cpath_top",
- "check_argcount",
- "passed_arg",
- "string_append",
- "string_dup",
- "set_args",
- "get_args",
- "send_with_arg_register",
- "cast_array_for_args",
- "send_super_stack_with_block",
- "push_my_field",
- "store_my_field",
- "open_metaclass",
- "set_cache_index",
- "block_break",
- "send_super_with_arg_register",
- "meta_push_neg_1",
- "meta_push_0",
- "meta_push_1",
- "meta_push_2",
- "meta_send_stack_1",
- "meta_send_stack_2",
- "meta_send_stack_3",
- "meta_send_stack_4",
- "meta_send_op_plus",
- "meta_send_op_minus",
- "meta_send_op_equal",
- "meta_send_op_lt",
- "meta_send_op_gt",
- "meta_send_op_tequal",
- "meta_send_op_nequal",
- "push_local_depth",
- "set_local_depth",
- "create_block",
- "send_off_stack",
- "locate_method",
- "kind_of",
- "instance_of",
- "set_call_flags",
- "yield_debugger"
- };
-}// RubiniusInstructions
View
341 src/org/jruby/ast/executable/RubiniusMachine.java
@@ -1,341 +0,0 @@
-/***** 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) 2007 Ola Bini <ola.bini@gmail.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 org.jruby.MetaClass;
-import org.jruby.Ruby;
-import org.jruby.RubyArray;
-import org.jruby.RubyFixnum;
-import org.jruby.RubyModule;
-import org.jruby.RubyString;
-import org.jruby.parser.StaticScope;
-import org.jruby.parser.LocalStaticScope;
-import org.jruby.runtime.Block;
-import org.jruby.runtime.CallType;
-import org.jruby.runtime.ThreadContext;
-import org.jruby.runtime.Visibility;
-import org.jruby.runtime.builtin.IRubyObject;
-import org.jruby.internal.runtime.methods.WrapperMethod;
-import org.jruby.internal.runtime.methods.RubiniusMethod;
-import org.jruby.javasupport.util.RuntimeHelpers;
-
-/**
- * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
- */
-public class RubiniusMachine {
- public final static RubiniusMachine INSTANCE = new RubiniusMachine();
-
- public final static int getInt(char[] bytecodes, int ix) {
- int val = 0;
- val += (bytecodes[ix+0]<<24);
- val += (bytecodes[ix+1]<<16);
- val += (bytecodes[ix+2]<<8);
- val += (bytecodes[ix+3]);
- return val;
- }
-
- public IRubyObject exec(ThreadContext context, IRubyObject self, char[] bytecodes, IRubyObject[] literals, IRubyObject[] args) {
- IRubyObject[] stack = new IRubyObject[20];
- int stackTop = 0;
- stack[stackTop] = context.getRuntime().getNil();
- for(int i=0;i<args.length;i++) {
- stack[++stackTop] = args[i];
- }
- int ip = 0;
- int call_flags = -1;
- int cache_index = -1;
- Ruby runtime = context.getRuntime();
- IRubyObject recv;
- IRubyObject other;
-
- loop: while (ip < bytecodes.length) {
- int ix = ip;
- int code = bytecodes[ip++];
- /*
- System.err.print(RubiniusInstructions.NAMES[code] + " (" + code + ") ");
- if(RubiniusInstructions.ONE_INT[code]) {
- System.err.print("[" + getInt(bytecodes, ip) + "] ");
- } else if(RubiniusInstructions.TWO_INT[code]) {
- System.err.print("[" + getInt(bytecodes, ip) + ", " + getInt(bytecodes, ip+4) + "] ");
- }
- System.err.println("{" + ix + "}");
-
- for(int i=stackTop; i>=0; i--) {
- System.err.println(" [" + i + "]=" + stack[i].callMethod(context, "inspect"));
- }*/
- switch(code) {
- case RubiniusInstructions.NOOP: {
- break;
- }
- case RubiniusInstructions.ADD_METHOD: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- String name = literals[val].toString();
- RubyModule clzz = (RubyModule)stack[stackTop--];
- RubyArray method = (RubyArray)stack[stackTop--];
-
- Visibility visibility = context.getCurrentVisibility();
- if (name == "initialize" || visibility == Visibility.MODULE_FUNCTION) {
- visibility = Visibility.PRIVATE;
- }
-
- RubiniusCMethod cmethod = new RubiniusCMethod(method);
-
- StaticScope staticScope = new LocalStaticScope(context.getCurrentScope().getStaticScope());
- staticScope.setVariables(new String[cmethod.locals]);
- staticScope.determineModule();
-
- RubiniusMethod newMethod = new RubiniusMethod(clzz, cmethod, staticScope, visibility);
-
- clzz.addMethod(name, newMethod);
-
- if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
- clzz.getSingletonClass().addMethod(
- name,
- new WrapperMethod(clzz.getSingletonClass(), newMethod,
- Visibility.PUBLIC));
- clzz.callMethod(context, "singleton_method_added", literals[val]);
- }
-
- if (clzz.isSingleton()) {
- ((MetaClass) clzz).getAttached().callMethod(
- context, "singleton_method_added", literals[val]);
- } else {
- clzz.callMethod(context, "method_added", literals[val]);
- }
- stack[++stackTop] = method;
- break;
- }
- case RubiniusInstructions.META_PUSH_NEG_1: {
- stack[++stackTop] = RubyFixnum.minus_one(runtime);
- break;
- }
- case RubiniusInstructions.CHECK_ARGCOUNT: {
- int min = getInt(bytecodes, ip);
- ip += 4;
- int max = getInt(bytecodes, ip);
- ip += 4;
-
- if(args.length < min) {
- throw runtime.newArgumentError("wrong # of arguments(" + args.length + " for " + min + ")");
- } else if(max>0 && args.length>max) {
- throw runtime.newArgumentError("wrong # of arguments(" + args.length + " for " + max + ")");
- }
- break;
- }
- case RubiniusInstructions.META_PUSH_0: {
- stack[++stackTop] = RubyFixnum.zero(runtime);
- break;
- }
- case RubiniusInstructions.META_PUSH_1: {
- stack[++stackTop] = RubyFixnum.one(runtime);
- break;
- }
- case RubiniusInstructions.META_PUSH_2: {
- stack[++stackTop] = runtime.newFixnum(2);
- break;
- }
- case RubiniusInstructions.SET_LOCAL: {
- int local = getInt(bytecodes, ip);
- ip += 4;
- context.getCurrentScope().setValue(local,stack[stackTop],0);
- break;
- }
- case RubiniusInstructions.PUSH_LOCAL: {
- int local = getInt(bytecodes, ip);
- ip += 4;
- stack[++stackTop] = context.getCurrentScope().getValue(local,0);
- break;
- }
- case RubiniusInstructions.PUSH_NIL: {
- stack[++stackTop] = runtime.getNil();
- break;
- }
- case RubiniusInstructions.PUSH_TRUE: {
- stack[++stackTop] = runtime.getTrue();
- break;
- }
- case RubiniusInstructions.PUSH_FALSE: {
- stack[++stackTop] = runtime.getFalse();
- break;
- }
- case RubiniusInstructions.PUSH_SELF: {
- stack[++stackTop] = self;
- break;
- }
- case RubiniusInstructions.STRING_DUP: {
- stack[stackTop] = ((RubyString)stack[stackTop]).strDup(context.getRuntime());
- break;
- }
- case RubiniusInstructions.PUSH_LITERAL: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- stack[++stackTop] = literals[val];
- break;
- }
- case RubiniusInstructions.META_SEND_OP_LT: {
- IRubyObject t1 = stack[stackTop--];
- IRubyObject t2 = stack[stackTop--];
- if((t1 instanceof RubyFixnum) && (t2 instanceof RubyFixnum)) {
- stack[++stackTop] = (((RubyFixnum)t1).getLongValue() < ((RubyFixnum)t2).getLongValue()) ? runtime.getTrue() : runtime.getFalse();
- } else {
- stack[++stackTop] = t1.callMethod(context, "<", t2);
- }
- break;
- }
-
- case RubiniusInstructions.META_SEND_OP_GT: {
- IRubyObject t1 = stack[stackTop--];
- IRubyObject t2 = stack[stackTop--];
- if((t1 instanceof RubyFixnum) && (t2 instanceof RubyFixnum)) {
- stack[++stackTop] = (((RubyFixnum)t1).getLongValue() > ((RubyFixnum)t1).getLongValue()) ? runtime.getTrue() : runtime.getFalse();
- } else {
- stack[++stackTop] = t1.callMethod(context, ">", t2);
- }
- break;
- }
-
- case RubiniusInstructions.META_SEND_OP_PLUS: {
- IRubyObject t1 = stack[stackTop--];
- IRubyObject t2 = stack[stackTop--];
- if((t1 instanceof RubyFixnum) && (t2 instanceof RubyFixnum)) {
- stack[++stackTop] = ((RubyFixnum)t1).op_plus(context, t2);
- } else {
- stack[++stackTop] = t1.callMethod(context, "+", t2);
- }
- break;
- }
- case RubiniusInstructions.META_SEND_OP_MINUS: {
-
- IRubyObject t1 = stack[stackTop--];
- IRubyObject t2 = stack[stackTop--];
- if((t1 instanceof RubyFixnum) && (t2 instanceof RubyFixnum)) {
- stack[++stackTop] = ((RubyFixnum)t1).op_minus(context, t2);
- } else {
- stack[++stackTop] = t1.callMethod(context, "-", t2);
- }
- break;
- }
- case RubiniusInstructions.POP: {
- stackTop--;
- break;
- }
- case RubiniusInstructions.SET_CALL_FLAGS: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- call_flags = val;
- break;
- }
- case RubiniusInstructions.SET_CACHE_INDEX: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- cache_index = val;
- break;
- }
- case RubiniusInstructions.SEND_STACK: {
- int index = getInt(bytecodes, ip);
- ip += 4;
- int num_args = getInt(bytecodes, ip);
- ip += 4;
-
- String name = literals[index].toString();
- recv = stack[stackTop--];
- IRubyObject[] argu = new IRubyObject[num_args];
- for(int i=0;i<num_args;i++) {
- argu[i] = stack[stackTop--];
- }
- if((call_flags & 0x01) == 0x01) { //Functional
- stack[++stackTop] = RuntimeHelpers.invoke(context, recv, name, argu, Block.NULL_BLOCK);
- } else {
- stack[++stackTop] = RuntimeHelpers.invoke(context, recv, name, argu, CallType.NORMAL, Block.NULL_BLOCK);
- }
- break;
- }
- case RubiniusInstructions.GOTO_IF_FALSE: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- if(!stack[stackTop--].isTrue()) {
- ip = val;
- }
- break;
- }
- case RubiniusInstructions.GOTO_IF_TRUE: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- if(stack[stackTop--].isTrue()) {
- ip = val;
- }
- break;
- }
- case RubiniusInstructions.SWAP_STACK: {
- IRubyObject swap = stack[stackTop];
- stack[stackTop] = stack[stackTop-1];
- stack[stackTop-1] = swap;
- break;
- }
- case RubiniusInstructions.DUP_TOP: {
- stack[stackTop+1] = stack[stackTop];
- stackTop++;
- break;
- }
- case RubiniusInstructions.GOTO: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- ip = val;
- break;
- }
- case RubiniusInstructions.RET: {
- return stack[stackTop];
- }
- case RubiniusInstructions.PUSH_INT: {
- int val = getInt(bytecodes, ip);
- ip += 4;
- stack[++stackTop] = runtime.newFixnum(val);
- break;
- }
- case RubiniusInstructions.PUSH_CONST: {
- int index = getInt(bytecodes, ip);
- ip += 4;
-
- String name = literals[index].toString();
- stack[++stackTop] = context.getConstant(name);
- break;
- }
- default:
- System.err.println("--COULDN'T");
- if(RubiniusInstructions.ONE_INT[code]) {
- ip+=4;
- } else if(RubiniusInstructions.TWO_INT[code]) {
- ip+=8;
- }
- break;
- }
- }
- return null;
- }
-}// RubiniusMachine
View
176 src/org/jruby/ast/executable/RubiniusRunner.java
@@ -1,176 +0,0 @@
-/***** 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) 2007 Ola Bini <ola.bini@gmail.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.io.InputStream;
-import java.io.IOException;
-
-import java.util.Map;
-import java.util.HashMap;
-
-import org.jruby.Ruby;
-import org.jruby.RubyArray;
-
-import org.jruby.parser.StaticScope;
-import org.jruby.parser.LocalStaticScope;
-import org.jruby.runtime.DynamicScope;
-import org.jruby.runtime.ThreadContext;
-import org.jruby.runtime.builtin.IRubyObject;
-
-/**
- * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
- */
-public class RubiniusRunner implements Runnable {
- private Ruby runtime;
-
- public final static int RUBINIUS_BYTECODE_VERSION = 3;
-
- public RubiniusRunner(Ruby runtime, InputStream in, String filename) {
- try {
- this.runtime = runtime;
- readMagic(in);
- readVersion(in);
- readRest(in);
- in.close();
- } catch(IOException e) {
- throw new RuntimeException("Couldn't read script: " + e);
- }
- }
-
- private final void readMagic(InputStream in) throws IOException {
- byte[] first = new byte[4];
- in.read(first);
- if(first[0] != 'R' || first[1] != 'B' || first[2] != 'I' || first[3] != 'X') {
- throw new RuntimeException("File is not a compiled Rubinius file");
- }
- }
-
- private final void readVersion(InputStream in) throws IOException {
- int version = readInt(in);
- if(version != RUBINIUS_BYTECODE_VERSION) {
- throw new RuntimeException("Can't run Rubinius code with version " + version);
- }
- }
-
- public static int readInt(InputStream in) throws IOException {
- byte[] theInt = new byte[4];
- in.read(theInt);
- int val = 0;
- val += (theInt[0]<<24);
- val += (theInt[1]<<16);
- val += (theInt[2]<<8);
- val += (theInt[3]);
- return val;
- }
-
- private Map methods = new HashMap();
-
- private final void readRest(InputStream in) throws IOException {
- RubiniusCMethod obj = null;
- while((obj = unmarshalCMethod(in)) != null) {
- methods.put(obj.name, obj);
- }
- }
-
- private final byte[] unmarshalCharArray(InputStream in) throws IOException {
- int length = readInt(in);
- byte[] arr = new byte[length];
- in.read(arr);
- return arr;
- }
-
- private final String unmarshalString(InputStream in) throws IOException {
- int length = readInt(in);
- byte[] arr = new byte[length];
- in.read(arr);
- return String.valueOf(arr);
- }
-
- private final int unmarshalInt(InputStream in) throws IOException {
- int neg = in.read();
- int val = readInt(in);
- if(neg == 'n') {
- val = -val;
- }
- return val;
- }
-
- private final IRubyObject[] unmarshalTuple(InputStream in) throws IOException {
- int length = readInt(in);
- IRubyObject[] vals = new IRubyObject[length];
- for(int i=0;i<length;i++) {
- vals[i] = unmarshal(in);
- }
- return vals;
- }
-
- private final RubiniusCMethod unmarshalCMethod(InputStream in) throws IOException {
- RubyArray obj = (RubyArray)unmarshal(in);
- if(obj == null) {
- return null;
- }
- return new RubiniusCMethod(obj);
- }
-
- private final IRubyObject unmarshal(InputStream in) throws IOException {
- int tag = in.read();
- int len = -1;
- byte[] data;
- switch(tag) {
- case 'i': return runtime.newFixnum(unmarshalInt(in));
- case 's': return runtime.newString(unmarshalString(in));
- case 'x': return runtime.newSymbol(unmarshalString(in));
- case 'p': return runtime.newArray(unmarshalTuple(in));
- case 'b': return runtime.newString(unmarshalString(in));
- case 'm': return runtime.newArray(unmarshalTuple(in));
- case 'B': System.err.println("B"); return null;
- case 'd': System.err.println("d"); return null;
- case 'r': System.err.println("r"); return null;
- case 'n': return runtime.getNil();
- case 't': return runtime.getTrue();
- case 'f': return runtime.getFalse();
- }
- return null;
- }
-
- public void run() {
- RubiniusCMethod method = (RubiniusCMethod)methods.get("__script__");
- ThreadContext context = runtime.getCurrentContext();
- StaticScope scope = new LocalStaticScope(null);
-
- if (scope.getModule() == null) {
- scope.setModule(runtime.getObject());
- }
-
- scope.setVariables(new String[method.locals]);
-
- context.setFileAndLine(method.file, -1);
- context.preScopedBody(DynamicScope.newDynamicScope(scope,null));
- RubiniusMachine.INSTANCE.exec(context, runtime.getObject(), method.code, method.literals, new IRubyObject[0]);
- }
-}// RubiniusRunner
View
215 src/org/jruby/ast/executable/YARVCompiledRunner.java
@@ -1,215 +0,0 @@
-/***** 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) 2007 Ola Bini <ola@ologix.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.io.InputStream;
-import java.io.IOException;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-
-import org.jruby.Ruby;
-import org.jruby.RubyFile;
-import org.jruby.RubyArray;
-import org.jruby.RubyNumeric;
-import org.jruby.RubyString;
-import org.jruby.RubySymbol;
-import org.jruby.parser.LocalStaticScope;
-import org.jruby.parser.StaticScope;
-import org.jruby.runtime.ThreadContext;
-import org.jruby.runtime.builtin.IRubyObject;
-
-/**
- * @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
- */
-public class YARVCompiledRunner {
- private Ruby runtime;
- private YARVMachine ym = YARVMachine.INSTANCE;
-
- private YARVMachine.InstructionSequence iseq;
-
- private Map jumps = new IdentityHashMap();
- private Map labels = new HashMap();
-
- public YARVCompiledRunner(Ruby runtime, InputStream in, String filename) {
- this.runtime = runtime;
- byte[] first = new byte[4];
- try {
- in.read(first);
- if(first[0] != 'R' || first[1] != 'B' || first[2] != 'C' || first[3] != 'M') {
- throw new RuntimeException("File is not a compiled YARV file");
- }
- RubyFile f = new RubyFile(runtime,filename,in);
- IRubyObject arr = runtime.getMarshal().callMethod(runtime.getCurrentContext(),"load",f);
- iseq = transformIntoSequence(arr);
- } catch(IOException e) {
- throw new RuntimeException("Couldn't read from source",e);
- }
- }
-
- public YARVCompiledRunner(Ruby runtime, YARVMachine.InstructionSequence iseq) {
- this.runtime = runtime;
- this.iseq = iseq;
- }
-
- public IRubyObject run() {
- ThreadContext context = runtime.getCurrentContext();
- StaticScope scope = new LocalStaticScope(null, iseq.locals);
- context.setFileAndLine(iseq.filename, -1);
- return ym.exec(context, scope, iseq.body);
- }
-
- private YARVMachine.InstructionSequence transformIntoSequence(IRubyObject arr) {
- if(!(arr instanceof RubyArray)) {
- throw new RuntimeException("Error when reading compiled YARV file");
- }
- labels.clear();
- jumps.clear();
-
- YARVMachine.InstructionSequence seq = new YARVMachine.InstructionSequence(runtime,null,null,null);
- Iterator internal = (((RubyArray)arr).getList()).iterator();
- seq.magic = internal.next().toString();
- seq.major = RubyNumeric.fix2int((IRubyObject)internal.next());
- seq.minor = RubyNumeric.fix2int((IRubyObject)internal.next());
- seq.format_type = RubyNumeric.fix2int((IRubyObject)internal.next());
- IRubyObject misc = (IRubyObject)internal.next();
- if(misc.isNil()) {
- seq.misc = null;
- } else {
- seq.misc = misc;
- }
- seq.name = internal.next().toString();
- seq.filename = internal.next().toString();
- seq.line = new Object[0]; internal.next();
- seq.type = internal.next().toString();
- seq.locals = toStringArray((IRubyObject)internal.next());
- IRubyObject argo = (IRubyObject)internal.next();
- if(argo instanceof RubyArray) {
- List arglist = ((RubyArray)argo).getList();
- seq.args_argc = RubyNumeric.fix2int((IRubyObject)arglist.get(0));
- seq.args_arg_opts = RubyNumeric.fix2int((IRubyObject)arglist.get(1));
- seq.args_opt_labels = toStringArray((IRubyObject)arglist.get(2));
- seq.args_rest = RubyNumeric.fix2int((IRubyObject)arglist.get(3));
- seq.args_block = RubyNumeric.fix2int((IRubyObject)arglist.get(4));
- } else {
- seq.args_argc = RubyNumeric.fix2int(argo);
- }
-
- seq.exception = getExceptionInformation((IRubyObject)internal.next());
-
- List bodyl = ((RubyArray)internal.next()).getList();
- YARVMachine.Instruction[] body = new YARVMachine.Instruction[bodyl.size()];
- int real=0;
- int i=0;
- for(Iterator iter = bodyl.iterator();iter.hasNext();i++) {
- IRubyObject is = (IRubyObject)iter.next();
- if(is instanceof RubyArray) {
- body[real] = intoInstruction((RubyArray)is,real,seq);
- real++;
- } else if(is instanceof RubySymbol) {
- labels.put(is.toString(), new Integer(real+1));
- }
- }
- YARVMachine.Instruction[] nbody = new YARVMachine.Instruction[real];
- System.arraycopy(body,0,nbody,0,real);
- seq.body = nbody;
-
- for(Iterator iter = jumps.keySet().iterator();iter.hasNext();) {
- YARVMachine.Instruction k = (YARVMachine.Instruction)iter.next();
- k.l_op0 = ((Integer)labels.get(jumps.get(k))).intValue() - 1;
- }
-
- return seq;
- }
-
- private String[] toStringArray(IRubyObject obj) {
- if(obj.isNil()) {
- return new String[0];
- } else {
- List l = ((RubyArray)obj).getList();
- String[] s = new String[l.size()];
- int i=0;
- for(Iterator iter = l.iterator();iter.hasNext();i++) {
- s[i] = iter.next().toString();
- }
- return s;
- }
- }
-
- private YARVMachine.Instruction intoInstruction(RubyArray obj, int n, YARVMachine.InstructionSequence iseq) {
- List internal = obj.getList();
- String name = internal.get(0).toString();
- int instruction = YARVMachine.instruction(name);
- YARVMachine.Instruction i = new YARVMachine.Instruction(instruction);
- if(internal.size() > 1) {
- IRubyObject first = (IRubyObject)internal.get(1);
- if(instruction == YARVInstructions.GETLOCAL || instruction == YARVInstructions.SETLOCAL) {
- i.l_op0 = (iseq.locals.length + 1) - RubyNumeric.fix2long(first);
- } else if(instruction == YARVInstructions.PUTOBJECT || instruction == YARVInstructions.OPT_REGEXPMATCH1 || instruction == YARVInstructions.GETINLINECACHE) {
- i.o_op0 = first;
- } else if(first instanceof RubyString || first instanceof RubySymbol ) {
- i.s_op0 = first.toString();
- } else if(first instanceof RubyNumeric) {
- i.l_op0 = RubyNumeric.fix2long(first);
- }
- if(instruction == YARVInstructions.SEND) {
- i.i_op1 = RubyNumeric.fix2int((IRubyObject)internal.get(2));
- i.i_op3 = RubyNumeric.fix2int((IRubyObject)internal.get(4));
- }
- if(instruction == YARVInstructions.DEFINEMETHOD) {
- i.iseq_op = transformIntoSequence((IRubyObject)internal.get(2));
- }
- if(isJump(instruction)) {
- i.index = n;
- jumps.put(i, internal.get(jumpIndex(instruction)).toString());
- }
- }
- return i;
- }
-
- private boolean isJump(int i) {
- return i == YARVInstructions.JUMP || i == YARVInstructions.BRANCHIF || i == YARVInstructions.BRANCHUNLESS ||
- i == YARVInstructions.GETINLINECACHE || i == YARVInstructions.SETINLINECACHE;
- }
-
- private int jumpIndex(int i) {
- if(i == YARVInstructions.GETINLINECACHE) {
- return 2;
- } else {
- return 1;
- }
- }
-
- private Object[] getExceptionInformation(IRubyObject obj) {
- // System.err.println(obj.callMethod(runtime.getCurrentContext(),"inspect"));
- return new Object[0];
- }
-}// YARVCompiledRunner
View
422 src/org/jruby/ast/executable/YARVInstructions.java
@@ -1,422 +0,0 @@
-/***** 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) 2006 Charles O Nutter <headius@headius.com>
- * Copyright (C) 2007 Ola Bini <ola@ologix.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.Map;
-import java.util.HashMap;
-
-/**
- * AUTOGENERATED. Change template, not generated file.
- */
-public abstract class YARVInstructions {
- public static final int NOP = 0;
- public static final int GETLOCAL = 1;
- public static final int SETLOCAL = 2;
- public static final int GETSPECIAL = 3;
- public static final int SETSPECIAL = 4;
- public static final int GETDYNAMIC = 5;
- public static final int SETDYNAMIC = 6;
- public static final int GETINSTANCEVARIABLE = 7;
- public static final int SETINSTANCEVARIABLE = 8;
- public static final int GETCLASSVARIABLE = 9;
- public static final int SETCLASSVARIABLE = 10;
- public static final int GETCONSTANT = 11;
- public static final int SETCONSTANT = 12;
- public static final int GETGLOBAL = 13;
- public static final int SETGLOBAL = 14;
- public static final int PUTNIL = 15;
- public static final int PUTSELF = 16;
- public static final int PUTUNDEF = 17;
- public static final int PUTOBJECT = 18;
- public static final int PUTSTRING = 19;
- public static final int CONCATSTRINGS = 20;
- public static final int TOSTRING = 21;
- public static final int TOREGEXP = 22;
- public static final int NEWARRAY = 23;
- public static final int DUPARRAY = 24;
- public static final int EXPANDARRAY = 25;
- public static final int CONCATARRAY = 26;
- public static final int SPLATARRAY = 27;
- public static final int CHECKINCLUDEARRAY = 28;
- public static final int NEWHASH = 29;
- public static final int NEWRANGE = 30;
- public static final int PUTNOT = 31;
- public static final int POP = 32;
- public static final int DUP = 33;
- public static final int DUPN = 34;
- public static final int SWAP = 35;
- public static final int REPUT = 36;
- public static final int TOPN = 37;
- public static final int SETN = 38;
- public static final int EMPTSTACK = 39;
- public static final int DEFINEMETHOD = 40;
- public static final int ALIAS = 41;
- public static final int UNDEF = 42;
- public static final int DEFINED = 43;
- public static final int POSTEXE = 44;
- public static final int TRACE = 45;
- public static final int DEFINECLASS = 46;
- public static final int SEND = 47;
- public static final int INVOKESUPER = 48;
- public static final int INVOKEBLOCK = 49;
- public static final int LEAVE = 50;
- public static final int FINISH = 51;
- public static final int THROW = 52;
- public static final int JUMP = 53;
- public static final int BRANCHIF = 54;
- public static final int BRANCHUNLESS = 55;
- public static final int GETINLINECACHE = 56;
- public static final int ONCEINLINECACHE = 57;
- public static final int SETINLINECACHE = 58;
- public static final int OPT_CASE_DISPATCH = 59;
- public static final int OPT_CHECKENV = 60;
- public static final int OPT_PLUS = 61;
- public static final int OPT_MINUS = 62;
- public static final int OPT_MULT = 63;
- public static final int OPT_DIV = 64;
- public static final int OPT_MOD = 65;
- public static final int OPT_EQ = 66;
- public static final int OPT_LT = 67;
- public static final int OPT_LE = 68;
- public static final int OPT_LTLT = 69;
- public static final int OPT_AREF = 70;
- public static final int OPT_ASET = 71;
- public static final int OPT_LENGTH = 72;
- public static final int OPT_SUCC = 73;
- public static final int OPT_REGEXPMATCH1 = 74;
- public static final int OPT_REGEXPMATCH2 = 75;
- public static final int OPT_CALL_NATIVE_COMPILED = 76;
- public static final int BITBLT = 77;
- public static final int ANSWER = 78;
- public static final int GETLOCAL_OP_2 = 79;
- public static final int GETLOCAL_OP_3 = 80;
- public static final int GETLOCAL_OP_4 = 81;
- public static final int SETLOCAL_OP_2 = 82;
- public static final int SETLOCAL_OP_3 = 83;
- public static final int SETLOCAL_OP_4 = 84;
- public static final int GETDYNAMIC_OP__WC__0 = 85;
- public static final int GETDYNAMIC_OP_1_0 = 86;
- public static final int GETDYNAMIC_OP_2_0 = 87;
- public static final int GETDYNAMIC_OP_3_0 = 88;
- public static final int GETDYNAMIC_OP_4_0 = 89;
- public static final int SETDYNAMIC_OP__WC__0 = 90;
- public static final int SETDYNAMIC_OP_1_0 = 91;
- public static final int SETDYNAMIC_OP_2_0 = 92;
- public static final int SETDYNAMIC_OP_3_0 = 93;
- public static final int SETDYNAMIC_OP_4_0 = 94;
- public static final int PUTOBJECT_OP_INT2FIX_0_0_C_ = 95;
- public static final int PUTOBJECT_OP_INT2FIX_0_1_C_ = 96;
- public static final int PUTOBJECT_OP_QTRUE = 97;
- public static final int PUTOBJECT_OP_QFALSE = 98;
- public static final int SEND_OP__WC___WC__QFALSE_0__WC_ = 99;
- public static final int SEND_OP__WC__0_QFALSE_0__WC_ = 100;
- public static final int SEND_OP__WC__1_QFALSE_0__WC_ = 101;
- public static final int SEND_OP__WC__2_QFALSE_0__WC_ = 102;
- public static final int SEND_OP__WC__3_QFALSE_0__WC_ = 103;
- public static final int SEND_OP__WC___WC__QFALSE_0X04__WC_ = 104;
- public static final int SEND_OP__WC__0_QFALSE_0X04__WC_ = 105;
- public static final int SEND_OP__WC__1_QFALSE_0X04__WC_ = 106;
- public static final int SEND_OP__WC__2_QFALSE_0X04__WC_ = 107;
- public static final int SEND_OP__WC__3_QFALSE_0X04__WC_ = 108;
- public static final int SEND_OP__WC__0_QFALSE_0X0C__WC_ = 109;
- public static final int UNIFIED_PUTOBJECT_PUTOBJECT = 110;
- public static final int UNIFIED_PUTOBJECT_PUTSTRING = 111;
- public static final int UNIFIED_PUTOBJECT_SETLOCAL = 112;
- public static final int UNIFIED_PUTOBJECT_SETDYNAMIC = 113;
- public static final int UNIFIED_PUTSTRING_PUTSTRING = 114;
- public static final int UNIFIED_PUTSTRING_PUTOBJECT = 115;
- public static final int UNIFIED_PUTSTRING_SETLOCAL = 116;
- public static final int UNIFIED_PUTSTRING_SETDYNAMIC = 117;
- public static final int UNIFIED_DUP_SETLOCAL = 118;
- public static final int UNIFIED_GETLOCAL_GETLOCAL = 119;
- public static final int UNIFIED_GETLOCAL_PUTOBJECT = 120;
-
- public static final Map<String, Integer> INSTS_TO_INDEX = new HashMap<String, Integer>();
- static {
- INSTS_TO_INDEX.put("nop",new Integer(0));
- INSTS_TO_INDEX.put("getlocal",new Integer(1));
- INSTS_TO_INDEX.put("setlocal",new Integer(2));
- INSTS_TO_INDEX.put("getspecial",new Integer(3));
- INSTS_TO_INDEX.put("setspecial",new Integer(4));
- INSTS_TO_INDEX.put("getdynamic",new Integer(5));
- INSTS_TO_INDEX.put("setdynamic",new Integer(6));
- INSTS_TO_INDEX.put("getinstancevariable",new Integer(7));
- INSTS_TO_INDEX.put("setinstancevariable",new Integer(8));
- INSTS_TO_INDEX.put("getclassvariable",new Integer(9));
- INSTS_TO_INDEX.put("setclassvariable",new Integer(10));
- INSTS_TO_INDEX.put("getconstant",new Integer(11));
- INSTS_TO_INDEX.put("setconstant",new Integer(12));
- INSTS_TO_INDEX.put("getglobal",new Integer(13));
- INSTS_TO_INDEX.put("setglobal",new Integer(14));
- INSTS_TO_INDEX.put("putnil",new Integer(15));
- INSTS_TO_INDEX.put("putself",new Integer(16));
- INSTS_TO_INDEX.put("putundef",new Integer(17));
- INSTS_TO_INDEX.put("putobject",new Integer(18));
- INSTS_TO_INDEX.put("putstring",new Integer(19));
- INSTS_TO_INDEX.put("concatstrings",new Integer(20));
- INSTS_TO_INDEX.put("tostring",new Integer(21));
- INSTS_TO_INDEX.put("toregexp",new Integer(22));
- INSTS_TO_INDEX.put("newarray",new Integer(23));
- INSTS_TO_INDEX.put("duparray",new Integer(24));
- INSTS_TO_INDEX.put("expandarray",new Integer(25));
- INSTS_TO_INDEX.put("concatarray",new Integer(26));
- INSTS_TO_INDEX.put("splatarray",new Integer(27));
- INSTS_TO_INDEX.put("checkincludearray",new Integer(28));
- INSTS_TO_INDEX.put("newhash",new Integer(29));
- INSTS_TO_INDEX.put("newrange",new Integer(30));
- INSTS_TO_INDEX.put("putnot",new Integer(31));
- INSTS_TO_INDEX.put("pop",new Integer(32));
- INSTS_TO_INDEX.put("dup",new Integer(33));
- INSTS_TO_INDEX.put("dupn",new Integer(34));
- INSTS_TO_INDEX.put("swap",new Integer(35));
- INSTS_TO_INDEX.put("reput",new Integer(36));
- INSTS_TO_INDEX.put("topn",new Integer(37));
- INSTS_TO_INDEX.put("setn",new Integer(38));
- INSTS_TO_INDEX.put("emptstack",new Integer(39));
- INSTS_TO_INDEX.put("definemethod",new Integer(40));
- INSTS_TO_INDEX.put("alias",new Integer(41));
- INSTS_TO_INDEX.put("undef",new Integer(42));
- INSTS_TO_INDEX.put("defined",new Integer(43));
- INSTS_TO_INDEX.put("postexe",new Integer(44));
- INSTS_TO_INDEX.put("trace",new Integer(45));
- INSTS_TO_INDEX.put("defineclass",new Integer(46));
- INSTS_TO_INDEX.put("send",new Integer(47));
- INSTS_TO_INDEX.put("invokesuper",new Integer(48));
- INSTS_TO_INDEX.put("invokeblock",new Integer(49));
- INSTS_TO_INDEX.put("leave",new Integer(50));
- INSTS_TO_INDEX.put("finish",new Integer(51));
- INSTS_TO_INDEX.put("throw",new Integer(52));
- INSTS_TO_INDEX.put("jump",new Integer(53));
- INSTS_TO_INDEX.put("branchif",new Integer(54));
- INSTS_TO_INDEX.put("branchunless",new Integer(55));
- INSTS_TO_INDEX.put("getinlinecache",new Integer(56));
- INSTS_TO_INDEX.put("onceinlinecache",new Integer(57));
- INSTS_TO_INDEX.put("setinlinecache",new Integer(58));
- INSTS_TO_INDEX.put("opt_case_dispatch",new Integer(59));
- INSTS_TO_INDEX.put("opt_checkenv",new Integer(60));
- INSTS_TO_INDEX.put("opt_plus",new Integer(61));
- INSTS_TO_INDEX.put("opt_minus",new Integer(62));
- INSTS_TO_INDEX.put("opt_mult",new Integer(63));
- INSTS_TO_INDEX.put("opt_div",new Integer(64));
- INSTS_TO_INDEX.put("opt_mod",new Integer(65));
- INSTS_TO_INDEX.put("opt_eq",new Integer(66));
- INSTS_TO_INDEX.put("opt_lt",new Integer(67));
- INSTS_TO_INDEX.put("opt_le",new Integer(68));
- INSTS_TO_INDEX.put("opt_ltlt",new Integer(69));
- INSTS_TO_INDEX.put("opt_aref",new Integer(70));
- INSTS_TO_INDEX.put("opt_aset",new Integer(71));
- INSTS_TO_INDEX.put("opt_length",new Integer(72));
- INSTS_TO_INDEX.put("opt_succ",new Integer(73));
- INSTS_TO_INDEX.put("opt_regexpmatch1",new Integer(74));
- INSTS_TO_INDEX.put("opt_regexpmatch2",new Integer(75));
- INSTS_TO_INDEX.put("opt_call_native_compiled",new Integer(76));
- INSTS_TO_INDEX.put("bitblt",new Integer(77));
- INSTS_TO_INDEX.put("answer",new Integer(78));
- INSTS_TO_INDEX.put("getlocal_op_2",new Integer(79));
- INSTS_TO_INDEX.put("getlocal_op_3",new Integer(80));
- INSTS_TO_INDEX.put("getlocal_op_4",new Integer(81));
- INSTS_TO_INDEX.put("setlocal_op_2",new Integer(82));
- INSTS_TO_INDEX.put("setlocal_op_3",new Integer(83));
- INSTS_TO_INDEX.put("setlocal_op_4",new Integer(84));
- INSTS_TO_INDEX.put("getdynamic_op__wc__0",new Integer(85));
- INSTS_TO_INDEX.put("getdynamic_op_1_0",new Integer(86));
- INSTS_TO_INDEX.put("getdynamic_op_2_0",new Integer(87));
- INSTS_TO_INDEX.put("getdynamic_op_3_0",new Integer(88));
- INSTS_TO_INDEX.put("getdynamic_op_4_0",new Integer(89));
- INSTS_TO_INDEX.put("setdynamic_op__wc__0",new Integer(90));
- INSTS_TO_INDEX.put("setdynamic_op_1_0",new Integer(91));
- INSTS_TO_INDEX.put("setdynamic_op_2_0",new Integer(92));
- INSTS_TO_INDEX.put("setdynamic_op_3_0",new Integer(93));
- INSTS_TO_INDEX.put("setdynamic_op_4_0",new Integer(94));
- INSTS_TO_INDEX.put("putobject_op_int2fix_0_0_c_",new Integer(95));
- INSTS_TO_INDEX.put("putobject_op_int2fix_0_1_c_",new Integer(96));
- INSTS_TO_INDEX.put("putobject_op_qtrue",new Integer(97));
- INSTS_TO_INDEX.put("putobject_op_qfalse",new Integer(98));
- INSTS_TO_INDEX.put("send_op__wc___wc__qfalse_0__wc_",new Integer(99));
- INSTS_TO_INDEX.put("send_op__wc__0_qfalse_0__wc_",new Integer(100));
- INSTS_TO_INDEX.put("send_op__wc__1_qfalse_0__wc_",new Integer(101));
- INSTS_TO_INDEX.put("send_op__wc__2_qfalse_0__wc_",new Integer(102));
- INSTS_TO_INDEX.put("send_op__wc__3_qfalse_0__wc_",new Integer(103));
- INSTS_TO_INDEX.put("send_op__wc___wc__qfalse_0x04__wc_",new Integer(104));
- INSTS_TO_INDEX.put("send_op__wc__0_qfalse_0x04__wc_",new Integer(105));
- INSTS_TO_INDEX.put("send_op__wc__1_qfalse_0x04__wc_",new Integer(106));
- INSTS_TO_INDEX.put("send_op__wc__2_qfalse_0x04__wc_",new Integer(107));
- INSTS_TO_INDEX.put("send_op__wc__3_qfalse_0x04__wc_",new Integer(108));
- INSTS_TO_INDEX.put("send_op__wc__0_qfalse_0x0c__wc_",new Integer(109));
- INSTS_TO_INDEX.put("unified_putobject_putobject",new Integer(110));
- INSTS_TO_INDEX.put("unified_putobject_putstring",new Integer(111));
- INSTS_TO_INDEX.put("unified_putobject_setlocal",new Integer(112));
- INSTS_TO_INDEX.put("unified_putobject_setdynamic",new Integer(113));
- INSTS_TO_INDEX.put("unified_putstring_putstring",new Integer(114));
- INSTS_TO_INDEX.put("unified_putstring_putobject",new Integer(115));
- INSTS_TO_INDEX.put("unified_putstring_setlocal",new Integer(116));
- INSTS_TO_INDEX.put("unified_putstring_setdynamic",new Integer(117));
- INSTS_TO_INDEX.put("unified_dup_setlocal",new Integer(118));
- INSTS_TO_INDEX.put("unified_getlocal_getlocal",new Integer(119));
- INSTS_TO_INDEX.put("unified_getlocal_putobject",new Integer(120));
- }
- public static int instruction(String name) {
- return ((Integer)INSTS_TO_INDEX.get(name)).intValue();
- }
-
- public static final String[] INDEX_TO_NAME = new String[] {
- "nop",
- "getlocal",
- "setlocal",
- "getspecial",
- "setspecial",
- "getdynamic",
- "setdynamic",
- "getinstancevariable",
- "setinstancevariable",
- "getclassvariable",
- "setclassvariable",
- "getconstant",
- "setconstant",
- "getglobal",
- "setglobal",
- "putnil",
- "putself",
- "putundef",
- "putobject",
- "putstring",
- "concatstrings",
- "tostring",
- "toregexp",
- "newarray",
- "duparray",
- "expandarray",
- "concatarray",
- "splatarray",
- "checkincludearray",
- "newhash",
- "newrange",
- "putnot",
- "pop",
- "dup",
- "dupn",
- "swap",
- "reput",
- "topn",
- "setn",
- "emptstack",
- "definemethod",
- "alias",
- "undef",
- "defined",
- "postexe",
- "trace",
- "defineclass",
- "send",
- "invokesuper",
- "invokeblock",
- "leave",
- "finish",
- "throw",
- "jump",
- "branchif",
- "branchunless",
- "getinlinecache",
- "onceinlinecache",
- "setinlinecache",
- "opt_case_dispatch",
- "opt_checkenv",
- "opt_plus",
- "opt_minus",
- "opt_mult",
- "opt_div",
- "opt_mod",
- "opt_eq",
- "opt_lt",
- "opt_le",
- "opt_ltlt",
- "opt_aref",
- "opt_aset",
- "opt_length",
- "opt_succ",
- "opt_regexpmatch1",
- "opt_regexpmatch2",
- "opt_call_native_compiled",
- "bitblt",
- "answer",
- "getlocal_op_2",
- "getlocal_op_3",
- "getlocal_op_4",
- "setlocal_op_2",
- "setlocal_op_3",
- "setlocal_op_4",
- "getdynamic_op__wc__0",
- "getdynamic_op_1_0",
- "getdynamic_op_2_0",
- "getdynamic_op_3_0",
- "getdynamic_op_4_0",
- "setdynamic_op__wc__0",
- "setdynamic_op_1_0",
- "setdynamic_op_2_0",
- "setdynamic_op_3_0",
- "setdynamic_op_4_0",
- "putobject_op_int2fix_0_0_c_",
- "putobject_op_int2fix_0_1_c_",
- "putobject_op_qtrue",
- "putobject_op_qfalse",
- "send_op__wc___wc__qfalse_0__wc_",
- "send_op__wc__0_qfalse_0__wc_",
- "send_op__wc__1_qfalse_0__wc_",
- "send_op__wc__2_qfalse_0__wc_",
- "send_op__wc__3_qfalse_0__wc_",
- "send_op__wc___wc__qfalse_0x04__wc_",
- "send_op__wc__0_qfalse_0x04__wc_",
- "send_op__wc__1_qfalse_0x04__wc_",
- "send_op__wc__2_qfalse_0x04__wc_",
- "send_op__wc__3_qfalse_0x04__wc_",
- "send_op__wc__0_qfalse_0x0c__wc_",
- "unified_putobject_putobject",
- "unified_putobject_putstring",
- "unified_putobject_setlocal",
- "unified_putobject_setdynamic",
- "unified_putstring_putstring",
- "unified_putstring_putobject",
- "unified_putstring_setlocal",
- "unified_putstring_setdynamic",
- "unified_dup_setlocal",
- "unified_getlocal_getlocal",
- "unified_getlocal_putobject"};
-
- public static String name(int index) {
- return INDEX_TO_NAME[index];
- }
-
- public static final int ARGS_SPLAT_FLAG = 2;
- public static final int ARGS_BLOCKARG_FLAG = 4;
- public static final int FCALL_FLAG = 8;
- public static final int VCALL_FLAG = 16;
- public static final int TAILCALL_FLAG = 32;
- public static final int TAILRECURSION_FLAG = 64;
- public static final int SUPER = 128;
-}
View
62 src/org/jruby/ast/executable/YARVInstructions.java.template
@@ -1,62 +0,0 @@
-/***** 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) 2006 Charles O Nutter <headius@headius.com>
- * Copyright (C) 2007 Ola Bini <ola@ologix.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.Map;
-import java.util.HashMap;
-
-/**
- * AUTOGENERATED. Change template, not generated file.
- */
-public abstract class YARVInstructions {<% INSTRUCTIONS.each_with_index do |ins, ix| %>
- public static final int <%= ins.name.upcase %> = <%= ix %>;<% end %>
-
- public static final Map INSTS_TO_INDEX = new HashMap();
- static {<% INSTRUCTIONS.each_with_index do |ins, ix| %>
- INSTS_TO_INDEX.put("<%= ins.name %>",new Integer(<%=ix%>));<% end %>
- }
- public static int instruction(String name) {
- return ((Integer)INSTS_TO_INDEX.get(name)).intValue();
- }
-
- public static final String[] INDEX_TO_NAME = new String[] { <% sep=''; INSTRUCTIONS.each do |ins| %><%=sep%>
- "<%=ins.name%><% sep=', ' %>"<% end %>};
-
- public static String name(int index) {
- return INDEX_TO_NAME[index];
- }
-
- public static final int ARGS_SPLAT_FLAG = 2;
- public static final int ARGS_BLOCKARG_FLAG = 4;
- public static final int FCALL_FLAG = 8;
- public static final int VCALL_FLAG = 16;
- public static final int TAILCALL_FLAG = 32;
- public static final int TAILRECURSION_FLAG = 64;
- public static final int SUPER = 128;
-}
View
720 src/org/jruby/ast/executable/YARVMachine.java
@@ -1,720 +0,0 @@
-package org.jruby.ast.executable;
-
-import org.jruby.Ruby;
-import org.jruby.RubyBignum;
-import org.jruby.RubyFixnum;
-import org.jruby.RubyHash;
-import org.jruby.RubyModule;
-import org.jruby.RubyString;
-import org.jruby.MetaClass;
-import org.jruby.RubySymbol;
-import org.jruby.parser.StaticScope;
-import org.jruby.parser.LocalStaticScope;
-import org.jruby.runtime.CallSite;
-import org.jruby.runtime.CallType;
-import org.jruby.runtime.ThreadContext;
-import org.jruby.runtime.Visibility;
-import org.jruby.runtime.builtin.IRubyObject;
-import org.jruby.common.IRubyWarnings.ID;
-import org.jruby.internal.runtime.methods.YARVMethod;
-import org.jruby.internal.runtime.methods.WrapperMethod;
-import org.jruby.javasupport.util.RuntimeHelpers;
-import org.jruby.runtime.MethodIndex;
-import org.jruby.runtime.scope.ManyVarsDynamicScope;
-
-public class YARVMachine {
- private static final boolean TAILCALL_OPT = Boolean.getBoolean("jruby.tailcall.enabled");
-
- public static final YARVMachine INSTANCE = new YARVMachine();
-
- public static int instruction(String name) {
- return YARVInstructions.instruction(name);
- }
-
- public static class InstructionSequence {
- public String magic;
- public int major;
- public int minor;
- public int format_type;
- public Object misc;
- public String name;
- public String filename;
- public Object[] line;
- public String type;
-
- public String[] locals;
-
- public int args_argc;
- public int args_arg_opts;
- public String[] args_opt_labels;
- public int args_rest;
- public int args_block;
-
- public Object[] exception;
-
- public Instruction[] body;
-
- public InstructionSequence(Ruby runtime, String name, String file, String type) {
- magic = "YARVInstructionSimpledataFormat";
- major = 1;
- minor = 1;
- format_type = 1;
- misc = runtime.getNil();
- this.name = name;
- this.filename = file;
- this.line = new Object[0];
- this.type = type;
- this.locals = new String[0];
- this.args_argc = 0;
- this.args_arg_opts = 0;
- this.exception = new Object[0];
- }
- }
-
- public static class Instruction {
- public int bytecode;
- public int line_no;
- public String s_op0;
- public IRubyObject o_op0;
- public Object _tmp;
- public long l_op0;
- public long l_op1;
- public int i_op1;
- public InstructionSequence iseq_op;
- public Instruction[] ins_op;
- public int i_op3;
-
- public int index;
- public int methodIndex = -1;
- public CallSite callAdapter;
-
- public Instruction(int bytecode) {
- this.bytecode = bytecode;
- }
-
- public Instruction(int bytecode, String op) {
- this.bytecode = bytecode;
- this.s_op0 = op.intern();
- }
-
- public Instruction(int bytecode, String op, InstructionSequence op1) {
- this.bytecode = bytecode;
- this.s_op0 = op.intern();
- this.iseq_op = op1;
- }
-
- public Instruction(int bytecode, long op) {
- this.bytecode = bytecode;
- this.l_op0 = op;
- }
-
- public Instruction(int bytecode, IRubyObject op) {
- this.bytecode = bytecode;
- this.o_op0 = op;
- }
-
- public Instruction(int bytecode, String op, int op1, Instruction[] op2, int op3) {
- this.bytecode = bytecode;
- this.s_op0 = op;
- this.i_op1 = op1;
- this.ins_op = op2;
- this.i_op3 = op3;
- }
-
- @Override
- public String toString() {
- return "[:" + YARVInstructions.name(bytecode) + ", " +
- (s_op0 != null ? s_op0 : (o_op0 != null ? o_op0.toString() : ("" + l_op0))) + "]";
- }
- }
-
- IRubyObject[] stack = new IRubyObject[8192];
- int stackTop = 0;
-
- /*
- private void printStack(String message, int fromIndex) {
- System.out.println("(" + message + ") Stack:");
- for (int i = fromIndex; i < stackTop; i++) {
- System.out.println("" + i + ": " + (stack[i] == null ? "null" : stack[i].inspect().toString()));
- }
- }*/
-
- /**
- * Push a value onto the stack
- *
- * @param value to be pushed
- */
- private void push(IRubyObject value) {
- //System.out.println("push(" + value.inspect() + ")");
- stack[stackTop] = value;
- stackTop++;
- }
-
- /**
- * Swap top two values in the stack
- */
- private void swap() {
- stack[stackTop + 1] = stack[stackTop];
- stack[stackTop] = stack[stackTop - 1];
- stack[stackTop - 1] = stack[stackTop + 1];
- }
-
- /**
- * Duplicate top 'n' values in the stack
- *
- * @param length
- */
- private void dupn(int length) {
- System.arraycopy(stack, stackTop - length, stack, stackTop, length);
- stackTop += length;
- }
-
- /**
- * Peek at top value in the stack
- *
- * @return the top value
- */
- private IRubyObject peek() {
- return stack[stackTop];
- }
-
- /**
- * pop top value in the stack
- *
- * @return the top value
- */
- private IRubyObject pop() {
- //System.out.println("pop(" + stack[stackTop-1].inspect() + ")");
- return stack[--stackTop];
- }
-
- /**
- * Pop top arr.length values into supplied arr.
- *
- * @param arr to be populated from the stack
- * @return the array passed in
- */
- private IRubyObject[] popArray(IRubyObject arr[]) {
- stackTop -= arr.length;
- System.arraycopy(stack, stackTop, arr, 0, arr.length);
-
- /*
- System.out.print("popArray:");
- for (int i = 0; i < arr.length; i++) {
- System.out.print(" " + arr[0].inspect());
- }
- System.out.println("");
- */
-
- return arr;
- }
-
- /**
- * set the nth stack value to value
- * @param depth nth index of stack
- * @param value to be set
- */
- private void setn(int depth, IRubyObject value) {
- stack[stackTop - depth] = value;
- }
-
- /**
- * push nth stack value
- *
- * @param depth which element to push
- */
- private void topn(int depth) {
- push(stack[stackTop - depth]);
- }
-
- /**
- * Set/Replace top stack value with value
- *
- * @param value to replace current stack value
- */
- public void set(IRubyObject value) {
- stack[stackTop] = value;
- }
-
- public void unimplemented(int bytecode) {
- System.err.println("Not implemented, YARVMachine." + YARVInstructions.name(bytecode));
- }
-
- /**
- * Top-level exec into YARV machine.
- *
- * @param context thread that is executing this machine (Note: We need to make n machines with
- * each belonging to an individual context)
- * @param scope of exec (evals will sometimes pass in something interesting)
- * @param bytecodes to be executed
- * @return last value pop'd of machine stack
- */
- public IRubyObject exec(ThreadContext context, StaticScope scope, Instruction[] bytecodes) {
- try {
- IRubyObject self = context.getRuntime().getObject();
-
- context.preScopedBody(new ManyVarsDynamicScope(scope));
-
- if (scope.getModule() == null) {
- scope.setModule(context.getRuntime().getObject());
- }
-
- return exec(context, self, bytecodes);
- } finally {
- context.postScopedBody();
- }
- }
-
- public IRubyObject exec(ThreadContext context, IRubyObject self, Instruction[] bytecodes) {
- Ruby runtime = context.getRuntime();
-
- // Where this frames stack begins.
- int stackStart = stackTop;
- int ip = 0;
- IRubyObject other;
-
- yarvloop: while (ip < bytecodes.length) {
- //System.err.println("Executing: " + YARVInstructions.name(bytecodes[ip].bytecode));
- switch (bytecodes[ip].bytecode) {
- case YARVInstructions.NOP:
- break;
- case YARVInstructions.GETGLOBAL:
- push(runtime.getGlobalVariables().get(bytecodes[ip].s_op0));
- break;
- case YARVInstructions.SETGLOBAL:
- runtime.getGlobalVariables().set(bytecodes[ip].s_op0, pop());
- break;
- case YARVInstructions.GETLOCAL:
- push(context.getCurrentScope().getValue((int) bytecodes[ip].l_op0, 0));
- break;
- case YARVInstructions.SETLOCAL:
- context.getCurrentScope().setValue((int) bytecodes[ip].l_op0, pop(), 0);
- break;
- case YARVInstructions.GETINSTANCEVARIABLE:
- push(self.getInstanceVariables().fastGetInstanceVariable(bytecodes[ip].s_op0));
- break;
- case YARVInstructions.SETINSTANCEVARIABLE:
- self.getInstanceVariables().fastSetInstanceVariable(bytecodes[ip].s_op0, pop());
- break;
- case YARVInstructions.GETCLASSVARIABLE: {
- RubyModule rubyClass = context.getRubyClass();
- String name = bytecodes[ip].s_op0;
-
- if (rubyClass == null) {
- push(self.getMetaClass().fastGetClassVar(name));
- } else if (!rubyClass.isSingleton()) {
- push(rubyClass.fastGetClassVar(name));
- } else {
- RubyModule module = (RubyModule)(((MetaClass)rubyClass).getAttached());
-
- if (module != null) {
- push(module.fastGetClassVar(name));
- } else {
- push(runtime.getNil());
- }
- }
- break;
- }
- case YARVInstructions.SETCLASSVARIABLE: {
- RubyModule rubyClass = context.getCurrentScope().getStaticScope().getModule();
-
- if (rubyClass == null) {
- rubyClass = self.getMetaClass();
- } else if (rubyClass.isSingleton()) {
- rubyClass = (RubyModule)(((MetaClass)rubyClass).getAttached());
- }
-
- rubyClass.fastSetClassVar(bytecodes[ip].s_op0, pop());
- break;
- }
- case YARVInstructions.GETCONSTANT:
- push(context.getConstant(bytecodes[ip].s_op0));
- break;
- case YARVInstructions.SETCONSTANT:
- context.setConstantInCurrent(bytecodes[ip].s_op0, pop());
- runtime.incGlobalState();
- break;
- case YARVInstructions.PUTNIL:
- push(context.getRuntime().getNil());
- break;
- case YARVInstructions.PUTSELF:
- push(self);
- break;
- case YARVInstructions.PUTOBJECT:
- //System.out.println("PUTOBJECT: " + bytecodes[ip].o_op0);
- push(bytecodes[ip].o_op0);
- break;
- case YARVInstructions.PUTSTRING:
- push(context.getRuntime().newString(bytecodes[ip].s_op0));
- break;
- case YARVInstructions.CONCATSTRINGS: {
- StringBuilder concatter = new StringBuilder();
-
- for (int i = 0; i < bytecodes[ip].l_op0; i++) {
- concatter.append(pop().toString());
- }
-
- push(runtime.newString(concatter.toString()));