diff --git a/src/org/jruby/Ruby.java b/src/org/jruby/Ruby.java index 04b4b7ce7df..7799c54dd84 100644 --- a/src/org/jruby/Ruby.java +++ b/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 chop!ing every line read * @param split Whether to split each line read using String#split - * @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("
",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(); diff --git a/src/org/jruby/RubyInstanceConfig.java b/src/org/jruby/RubyInstanceConfig.java index edf59dd3bd4..26ed4acb7c2 100644 --- a/src/org/jruby/RubyInstanceConfig.java +++ b/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; } diff --git a/src/org/jruby/ast/executable/RubiniusCMethod.java b/src/org/jruby/ast/executable/RubiniusCMethod.java deleted file mode 100644 index b999fc90c26..00000000000 --- a/src/org/jruby/ast/executable/RubiniusCMethod.java +++ /dev/null @@ -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 - * - * 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 Ola Bini - */ -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 diff --git a/src/org/jruby/ast/executable/RubiniusInstructions.java b/src/org/jruby/ast/executable/RubiniusInstructions.java deleted file mode 100644 index ebfc73d4630..00000000000 --- a/src/org/jruby/ast/executable/RubiniusInstructions.java +++ /dev/null @@ -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 - * - * 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 Ola Bini - */ -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 diff --git a/src/org/jruby/ast/executable/RubiniusMachine.java b/src/org/jruby/ast/executable/RubiniusMachine.java deleted file mode 100644 index 9161fd774df..00000000000 --- a/src/org/jruby/ast/executable/RubiniusMachine.java +++ /dev/null @@ -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 - * - * 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 Ola Bini - */ -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=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 - * - * 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 Ola Bini - */ -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 - * - * 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 Ola Bini - */ -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 diff --git a/src/org/jruby/ast/executable/YARVInstructions.java b/src/org/jruby/ast/executable/YARVInstructions.java deleted file mode 100644 index 69bdc25e1e7..00000000000 --- a/src/org/jruby/ast/executable/YARVInstructions.java +++ /dev/null @@ -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 - * Copyright (C) 2007 Ola Bini - * - * 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 INSTS_TO_INDEX = new HashMap(); - 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; -} diff --git a/src/org/jruby/ast/executable/YARVInstructions.java.template b/src/org/jruby/ast/executable/YARVInstructions.java.template deleted file mode 100644 index 013e08488fa..00000000000 --- a/src/org/jruby/ast/executable/YARVInstructions.java.template +++ /dev/null @@ -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 - * Copyright (C) 2007 Ola Bini - * - * 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; -} diff --git a/src/org/jruby/ast/executable/YARVMachine.java b/src/org/jruby/ast/executable/YARVMachine.java deleted file mode 100644 index 24cdaa53767..00000000000 --- a/src/org/jruby/ast/executable/YARVMachine.java +++ /dev/null @@ -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())); - break; - } - case YARVInstructions.TOSTRING: - IRubyObject top = peek(); - if (!(top instanceof RubyString)) { - set(top.callMethod(context, "to_s")); - } - break; - case YARVInstructions.NEWARRAY: - push(runtime.newArrayNoCopy(popArray(new IRubyObject[(int) bytecodes[ip].l_op0]))); - break; - case YARVInstructions.DUPARRAY: - push(bytecodes[ip].o_op0.dup()); - break; - case YARVInstructions.NEWHASH: - int hsize = (int)bytecodes[ip].l_op0; - RubyHash h = RubyHash.newHash(runtime); - IRubyObject v,k; - for(int i = hsize; i>0; i -= 2) { - v = pop(); - k = pop(); - h.op_aset(context, k, v); - } - push(h); - break; - case YARVInstructions.PUTNOT: - push(peek().isTrue() ? runtime.getFalse() : runtime.getTrue()); - break; - case YARVInstructions.POP: - pop(); - break; - case YARVInstructions.DUP: - push(peek()); - break; - case YARVInstructions.DUPN: - dupn((int) bytecodes[ip].l_op0); - break; - case YARVInstructions.SWAP: - swap(); - break; - case YARVInstructions.TOPN: - topn((int) bytecodes[ip].l_op0); - break; - case YARVInstructions.SETN: - setn((int) bytecodes[ip].l_op0, peek()); - break; - case YARVInstructions.EMPTSTACK: - stackTop = stackStart; - break; - case YARVInstructions.DEFINEMETHOD: - RubyModule containingClass = context.getRubyClass(); - - if (containingClass == null) { - throw runtime.newTypeError("No class to add method."); - } - - String mname = bytecodes[ip].iseq_op.name; - if (containingClass == runtime.getObject() && mname == "initialize") { - runtime.getWarnings().warn(ID.REDEFINING_DANGEROUS, "redefining Object#initialize may cause infinite loop", "Object#initialize"); - } - - Visibility visibility = context.getCurrentVisibility(); - if (mname == "initialize" || visibility == Visibility.MODULE_FUNCTION) { - visibility = Visibility.PRIVATE; - } - - if (containingClass.isSingleton()) { - IRubyObject attachedObject = ((MetaClass) containingClass).getAttached(); - - if (attachedObject instanceof RubyFixnum || attachedObject instanceof RubySymbol) { - throw runtime.newTypeError("can't define singleton method \"" + - mname + "\" for " + attachedObject.getType()); - } - } - - StaticScope sco = new LocalStaticScope(null); - sco.setVariables(bytecodes[ip].iseq_op.locals); - YARVMethod newMethod = new YARVMethod(containingClass, bytecodes[ip].iseq_op, sco, visibility); - - containingClass.addMethod(mname, newMethod); - - if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) { - RubyModule singleton = containingClass.getSingletonClass(); - singleton.addMethod(mname, new WrapperMethod(singleton, newMethod, Visibility.PUBLIC)); - containingClass.callMethod(context, "singleton_method_added", runtime.fastNewSymbol(mname)); - } - - // 'class << state.self' and 'class << obj' uses defn as opposed to defs - if (containingClass.isSingleton()) { - ((MetaClass) containingClass).getAttached().callMethod(context, - "singleton_method_added", runtime.fastNewSymbol(mname)); - } else { - containingClass.callMethod(context, "method_added", runtime.fastNewSymbol(mname)); - } - push(runtime.getNil()); - runtime.incGlobalState(); - break; - case YARVInstructions.SEND: { - ip = send(runtime, context, self, bytecodes, stackStart, ip); - break; - } - case YARVInstructions.LEAVE: - break yarvloop; - case YARVInstructions.JUMP: - ip = (int) bytecodes[ip].l_op0; - continue yarvloop; - case YARVInstructions.BRANCHIF: - ip = pop().isTrue() ? (int) bytecodes[ip].l_op0 : ip + 1; - continue yarvloop; - case YARVInstructions.BRANCHUNLESS: { - ip = !pop().isTrue() ? (int) bytecodes[ip].l_op0 : ip + 1; - continue yarvloop; - } - case YARVInstructions.GETINLINECACHE: - if(bytecodes[ip].l_op1 == runtime.getGlobalState()) { - push(bytecodes[ip].o_op0); - ip = (int) bytecodes[ip].l_op0; - continue yarvloop; - } - break; - case YARVInstructions.ONCEINLINECACHE: - if(bytecodes[ip].l_op1 > 0) { - push(bytecodes[ip].o_op0); - ip = (int) bytecodes[ip].l_op0; - continue yarvloop; - } - break; - case YARVInstructions.SETINLINECACHE: - int we = (int)bytecodes[ip].l_op0; - bytecodes[we].o_op0 = peek(); - bytecodes[we].l_op1 = runtime.getGlobalState(); - break; - case YARVInstructions.OPT_PLUS: - op_plus(runtime, context, pop(), pop()); - break; - case YARVInstructions.OPT_MINUS: - op_minus(runtime, context, pop(), pop()); - break; - case YARVInstructions.OPT_MULT: - other = pop(); - push(pop().callMethod(context, "*", other)); - break; - case YARVInstructions.OPT_DIV: - other = pop(); - push(pop().callMethod(context, "/", other)); - break; - case YARVInstructions.OPT_MOD: - other = pop(); - push(pop().callMethod(context,"%",other)); - break; - case YARVInstructions.OPT_EQ: - other = pop(); - push(pop().callMethod(context, "==", other)); - break; - case YARVInstructions.OPT_LT: - op_lt(runtime, context, pop(), pop()); - break; - case YARVInstructions.OPT_LE: - other = pop(); - push(pop().callMethod(context, "<=", other)); - break; - case YARVInstructions.OPT_LTLT: - other = pop(); - push(pop().callMethod(context, "<<", other)); - break; - case YARVInstructions.OPT_AREF: - other = pop(); - push(pop().callMethod(context, "[]",other)); - break; - case YARVInstructions.OPT_ASET: { - //YARV will never emit this, for some reason. - IRubyObject value = pop(); - other = pop(); - push(RuntimeHelpers.invoke(context, pop(), "[]=", other,value)); - break; - } - case YARVInstructions.OPT_LENGTH: - push(pop().callMethod(context, "length")); - break; - case YARVInstructions.OPT_SUCC: - push(pop().callMethod(context, "succ")); - break; - case YARVInstructions.OPT_REGEXPMATCH1: - push(bytecodes[ip].o_op0.callMethod(context, "=~", peek())); - break; - case YARVInstructions.OPT_REGEXPMATCH2: - other = pop(); - push(pop().callMethod(context, "=~", other)); - break; - case YARVInstructions.ANSWER: - push(runtime.newFixnum(42)); - break; - case YARVInstructions.GETSPECIAL: - case YARVInstructions.SETSPECIAL: - case YARVInstructions.GETDYNAMIC: - case YARVInstructions.SETDYNAMIC: - case YARVInstructions.PUTUNDEF: - // ko1 said this is going away - case YARVInstructions.TOREGEXP: - case YARVInstructions.NEWRANGE: - case YARVInstructions.REPUT: - case YARVInstructions.OPT_CASE_DISPATCH: - case YARVInstructions.OPT_CHECKENV: - case YARVInstructions.EXPANDARRAY: - // masgn array to values - case YARVInstructions.CONCATARRAY: - case YARVInstructions.SPLATARRAY: - case YARVInstructions.CHECKINCLUDEARRAY: - case YARVInstructions.ALIAS: - case YARVInstructions.UNDEF: - case YARVInstructions.DEFINED: - case YARVInstructions.POSTEXE: - case YARVInstructions.TRACE: - case YARVInstructions.DEFINECLASS: - case YARVInstructions.INVOKESUPER: - case YARVInstructions.INVOKEBLOCK: - case YARVInstructions.FINISH: - case YARVInstructions.THROW: - case YARVInstructions.OPT_CALL_NATIVE_COMPILED: - case YARVInstructions.BITBLT: - case YARVInstructions.GETLOCAL_OP_2: case YARVInstructions.GETLOCAL_OP_3: - case YARVInstructions.GETLOCAL_OP_4: case YARVInstructions.SETLOCAL_OP_2: - case YARVInstructions.SETLOCAL_OP_3: case YARVInstructions.SETLOCAL_OP_4: - case YARVInstructions.GETDYNAMIC_OP__WC__0: - case YARVInstructions.GETDYNAMIC_OP_1_0: case YARVInstructions.GETDYNAMIC_OP_2_0: - case YARVInstructions.GETDYNAMIC_OP_3_0: case YARVInstructions.GETDYNAMIC_OP_4_0: - case YARVInstructions.SETDYNAMIC_OP__WC__0: - case YARVInstructions.SETDYNAMIC_OP_1_0: case YARVInstructions.SETDYNAMIC_OP_2_0: - case YARVInstructions.SETDYNAMIC_OP_3_0: case YARVInstructions.SETDYNAMIC_OP_4_0: - case YARVInstructions.PUTOBJECT_OP_INT2FIX_0_0_C_: - case YARVInstructions.PUTOBJECT_OP_INT2FIX_0_1_C_: - case YARVInstructions.PUTOBJECT_OP_QTRUE: case YARVInstructions.PUTOBJECT_OP_QFALSE: - case YARVInstructions.SEND_OP__WC___WC__QFALSE_0__WC_: - case YARVInstructions.SEND_OP__WC__0_QFALSE_0__WC_: - case YARVInstructions.SEND_OP__WC__1_QFALSE_0__WC_: - case YARVInstructions.SEND_OP__WC__2_QFALSE_0__WC_: - case YARVInstructions.SEND_OP__WC__3_QFALSE_0__WC_: - case YARVInstructions.SEND_OP__WC___WC__QFALSE_0X04__WC_: - case YARVInstructions.SEND_OP__WC__0_QFALSE_0X04__WC_: - case YARVInstructions.SEND_OP__WC__1_QFALSE_0X04__WC_: - case YARVInstructions.SEND_OP__WC__2_QFALSE_0X04__WC_: - case YARVInstructions.SEND_OP__WC__3_QFALSE_0X04__WC_: - case YARVInstructions.SEND_OP__WC__0_QFALSE_0X0C__WC_: - case YARVInstructions.UNIFIED_PUTOBJECT_PUTOBJECT: - case YARVInstructions.UNIFIED_PUTOBJECT_PUTSTRING: - case YARVInstructions.UNIFIED_PUTOBJECT_SETLOCAL: - case YARVInstructions.UNIFIED_PUTOBJECT_SETDYNAMIC: - case YARVInstructions.UNIFIED_PUTSTRING_PUTSTRING: - case YARVInstructions.UNIFIED_PUTSTRING_PUTOBJECT: - case YARVInstructions.UNIFIED_PUTSTRING_SETLOCAL: - case YARVInstructions.UNIFIED_PUTSTRING_SETDYNAMIC: - case YARVInstructions.UNIFIED_DUP_SETLOCAL: - case YARVInstructions.UNIFIED_GETLOCAL_GETLOCAL: - case YARVInstructions.UNIFIED_GETLOCAL_PUTOBJECT: - unimplemented(bytecodes[ip].bytecode); - break; - } - ip++; - } - - return pop(); - } - - private void op_plus(Ruby runtime, ThreadContext context, IRubyObject other, IRubyObject receiver) { - if (other instanceof RubyFixnum && receiver instanceof RubyFixnum) { - long receiverValue = ((RubyFixnum) receiver).getLongValue(); - long otherValue = ((RubyFixnum) other).getLongValue(); - long result = receiverValue + otherValue; - if ((~(receiverValue ^ otherValue) & (receiverValue ^ result) & RubyFixnum.SIGN_BIT) != 0) { - push(RubyBignum.newBignum(runtime, receiverValue).op_plus(context, other)); - } - - push(runtime.newFixnum(result)); - } else { - push(receiver.callMethod(context, "+", other)); - } - } - - private void op_minus(Ruby runtime, ThreadContext context, IRubyObject other, IRubyObject receiver) { - if (other instanceof RubyFixnum && receiver instanceof RubyFixnum) { - long receiverValue = ((RubyFixnum) receiver).getLongValue(); - long otherValue = ((RubyFixnum) other).getLongValue(); - long result = receiverValue - otherValue; - if ((~(receiverValue ^ otherValue) & (receiverValue ^ result) & RubyFixnum.SIGN_BIT) != 0) { - push(RubyBignum.newBignum(runtime, receiverValue).op_minus(context, other)); - } - - push(runtime.newFixnum(result)); - } else { - push(receiver.callMethod(context, "-", other)); - } - } - - private void op_lt(Ruby runtime, ThreadContext context, IRubyObject other, IRubyObject receiver) { - if (other instanceof RubyFixnum && receiver instanceof RubyFixnum) { - long receiverValue = ((RubyFixnum) receiver).getLongValue(); - long otherValue = ((RubyFixnum) other).getLongValue(); - - push(runtime.newBoolean(receiverValue < otherValue)); - } else { - push(receiver.callMethod(context, "<", other)); - } - } - - private int send(Ruby runtime, ThreadContext context, IRubyObject self, Instruction[] bytecodes, int stackStart, int ip) { - Instruction instruction = bytecodes[ip]; - String name = instruction.s_op0; - int size = instruction.i_op1; - int flags = instruction.i_op3; - - // ENEBO: We need to define a YarvBlock - //Instruction[] blockBytecodes = bytecodes[ip].ins_op; - // TODO: block stuff - - IRubyObject[] args; - if (size == 0) { - args = IRubyObject.NULL_ARRAY; - } else { - args = new IRubyObject[size]; - popArray(args); - } - - // FCalls and VCalls use a nil as a place holder, but this is just extra stack - // traffic. Also extra flag activity (tiny perf-wise). I would think three - // send instructions makes more sense... - IRubyObject recv; - CallType callType; - if ((flags & YARVInstructions.VCALL_FLAG) == 0) { - if ((flags & YARVInstructions.FCALL_FLAG) == 0) { - recv = pop(); - callType = CallType.NORMAL; - } else { - pop(); - recv = self; - callType = CallType.FUNCTIONAL; - } - } else { - pop(); - recv = self; - callType = CallType.VARIABLE; - } - - if (instruction.callAdapter == null) { - instruction.callAdapter = MethodIndex.getCallSite(name.intern()); - } - - if (TAILCALL_OPT && (bytecodes[ip+1].bytecode == YARVInstructions.LEAVE || - (flags & YARVInstructions.TAILCALL_FLAG) == YARVInstructions.TAILCALL_FLAG) && - recv == self && name.equals(context.getFrameName())) { - stackTop = stackStart; - ip = -1; - - for(int i=0;i - * - * 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.compiler; - -import org.jruby.ast.Node; -import org.jruby.compiler.yarv.StandardYARVCompiler; - -/** - * @author Ola Bini - */ -public class YARVNodesCompiler { - public void compile(Node node, StandardYARVCompiler context) { - context.compile(node, null); - } -}// YARVNodesCompiler diff --git a/src/org/jruby/compiler/yarv/StandardYARVCompiler.java b/src/org/jruby/compiler/yarv/StandardYARVCompiler.java deleted file mode 100644 index 4691007f16c..00000000000 --- a/src/org/jruby/compiler/yarv/StandardYARVCompiler.java +++ /dev/null @@ -1,800 +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 - * - * 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.compiler.yarv; - -import java.util.List; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.IdentityHashMap; - -import org.jruby.Ruby; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.ast.AndNode; -import org.jruby.ast.ArgumentNode; -import org.jruby.ast.ArrayNode; -import org.jruby.ast.BlockNode; -import org.jruby.ast.BlockPassNode; -import org.jruby.ast.CallNode; -import org.jruby.ast.ConstDeclNode; -import org.jruby.ast.ConstNode; -import org.jruby.ast.DefnNode; -import org.jruby.ast.NewlineNode; -import org.jruby.ast.NotNode; -import org.jruby.ast.FixnumNode; -import org.jruby.ast.IfNode; -import org.jruby.ast.ListNode; -import org.jruby.ast.LocalAsgnNode; -import org.jruby.ast.LocalVarNode; -import org.jruby.ast.OrNode; -import org.jruby.ast.VCallNode; -import org.jruby.ast.IArgumentNode; -import org.jruby.ast.HashNode; -import org.jruby.ast.Node; -import org.jruby.ast.NodeType; -import org.jruby.ast.RootNode; -import org.jruby.ast.StrNode; -import org.jruby.ast.UntilNode; -import org.jruby.ast.WhileNode; -import org.jruby.ast.executable.YARVInstructions; -import org.jruby.ast.executable.YARVMachine; -import org.jruby.ast.types.ILiteralNode; -import org.jruby.ast.types.INameNode; - -/** - * @author Ola Bini - */ -public class StandardYARVCompiler { - private YARVMachine.InstructionSequence iseq; - private Ruby runtime; - private int last_line = -1; - - private LinkAnchor current_iseq; - - private String[] locals = new String[0]; - - private static final int COMPILE_OK=1; - //private static final int COMPILE_NG=0; - - // Counter for label - private int label_no = 0; - - - private static abstract class LinkElement { - public LinkElement next; - public LinkElement prev; - - public void insert(LinkElement other) { - other.prev = prev; - other.next = this; - prev = other; - if (other.prev != null) other.prev.next = other; - } - - public void remove() { - prev.next = next; - if (next != null) next.prev = prev; - } - - public void replace(LinkElement other) { - other.prev = prev; - other.next = next; - if (prev != null) prev.next = other; - if (next != null) next.prev = other; - } - } - - private static class LinkAnchor extends LinkElement { - LinkElement last; - - public LinkAnchor() { - last = this; - } - - public void add(LinkElement element) { - element.prev = last; - last.next = element; - last = element; - - verify_list("add"); - } - - public void append(LinkAnchor other) { - if (other.next != null) { - last.next = other.next; - other.next.prev = last; - last = other.last; - } - - verify_list("append"); - } - - public void insert(LinkAnchor other) { - if (other.next != null) { - LinkElement first = next; - next = other.next; - next.prev = this; - other.last.next = first; - if (first != null) { - first.prev = other.last; - } else { - last = other.last; - } - } - - verify_list("append"); - } - - public boolean isEmpty() { - return next == null; - } - - public LinkElement pop() { - LinkElement element = last; - - last = last.prev; - last.next = null; - - verify_list("pop"); - - return element; - } - - public LinkElement shift() { - LinkElement elem = next; - - if (null != elem) next = elem.next; - - return elem; - } - - public int size() { - int size = 0; - - for (LinkElement elem = next; elem != null; elem = elem.next) { - size++; - } - - return size; - } - - private void verify_list(String info) { - int flag = 0; - LinkElement plist = this; - for (LinkElement list = next; list != null; list = list.next) { - if (plist != list.prev) flag++; - - plist = list; - } - - if (last != plist && last != null) flag |= 0x70000; - - if (flag != 0) { - throw new RuntimeException("list verify error: " + Integer.toString(flag, 16) + - " (" + info + ")"); - } - } - - public LinkElement first() { - // TODO Auto-generated method stub - return null; - } - } - - private static class Label extends LinkElement { - /* Label number (identifier) */ - int id; - - // int position; Unused - // int sc_state; - // int set; Unused - // int sp; - - public Label(int line, int id) { - next = null; - this.id = id; - //sc_state = 0; - //labelobj.sp = -1; - } - } - - private static class Insn extends LinkElement { - YARVMachine.Instruction i; - } - - /* - private static class EnsureRange { - Label begin; - Label end; - EnsureRange next; - } - */ - - private Label NEW_LABEL(int l) { Label label = new Label(l, label_no); label_no++; return label;} - private static void ADD_LABEL(LinkAnchor anchor, LinkElement elem) { anchor.add(elem); } - private static void ADD_ELEM(LinkAnchor anchor, LinkElement elem) { anchor.add(elem); } - //private static void INSERT_ELEM_PREV(LinkElement elem1, LinkElement elem2) { elem1.insert(elem2); } - //private static void REPLACE_ELEM(LinkElement elem1, LinkElement elem2) { elem1.replace(elem2); } - //private static void REMOVE_ELEM(LinkElement element) { element.remove(); } - //private static LinkElement FIRST_ELEMENT(LinkAnchor anchor) { return anchor.first(); } - private static LinkElement POP_ELEMENT(LinkAnchor anchor) { return anchor.pop(); } - //private static LinkElement SHIFT_ELEMENT(LinkAnchor anchor) { return anchor.shift(); } - //private static int LIST_SIZE(LinkAnchor anchor) { return anchor.size(); } - private static boolean LIST_SIZE_ZERO(LinkAnchor anchor) { return anchor.isEmpty(); } - private static void APPEND_LIST(LinkAnchor anc1, LinkAnchor anc2) { anc1.append(anc2); } - //private static void INSERT_LIST(LinkAnchor anc1, LinkAnchor anc2) { anc1.insert(anc2); } - private static void ADD_SEQ(LinkAnchor seq1, LinkAnchor seq2) { seq1.append(seq2); } - - private int debug_compile(String msg, int v) { - debugs(msg); - return v; - } - - private int COMPILE(LinkAnchor anchor, String desc, Node node) { - return debug_compile("== " + desc, iseq_compile_each(anchor, node, false)); - } - - private int COMPILE(LinkAnchor anchor, String desc, Node node, boolean poped) { - return debug_compile("== " + desc, iseq_compile_each(anchor, node, poped)); - } - - private int COMPILE_POPED(LinkAnchor anchor, String desc, Node node) { - return debug_compile("== " + desc, iseq_compile_each(anchor, node, true)); - } - - private LinkAnchor DECL_ANCHOR() { - return new LinkAnchor(); - } - - public StandardYARVCompiler(Ruby runtime) { - this.runtime = runtime; - } - - private void debugs(String s) { - System.err.println(s); - } - - public void compile(Node node) { - iseq_compile(null,node); - } - - public void compile(Node node, Compiler context) { - compile(node); - } - - public void iseq_compile(IRubyObject self, Node node) { - LinkAnchor list_anchor = DECL_ANCHOR(); - - debugs("[compile step 1 (traverse each node)]"); - - /* KRI switched to making newline a flag of a node rather than a whole node */ - while (node.getNodeType() == NodeType.NEWLINENODE) { - node = ((NewlineNode) node).getNextNode(); - } - - COMPILE(list_anchor, "top level node", node); - ADD_INSN(list_anchor, last_line, YARVInstructions.LEAVE); - current_iseq = list_anchor; - - } - - private int nd_line(Node node) { - return node.getPosition() != null ? node.getPosition().getStartLine() : last_line; - } - - private String nd_file(Node node) { - if(node.getPosition() != null) { - return node.getPosition().getFile(); - } - return null; - } - - private int iseq_compile_each(LinkAnchor ret, Node node, boolean poped) { - if(node == null) { - if(!poped) { - debugs("NODE_NIL(implicit)"); - ADD_INSN(ret, 0, YARVInstructions.PUTNIL); - return COMPILE_OK; - } - return COMPILE_OK; - } - last_line = nd_line(node); - - LinkAnchor recv = null; - LinkAnchor args = null; - - compileLoop: while(true) { - switch(node.getNodeType()) { - case BLOCKNODE: - List l = ((BlockNode)node).childNodes(); - int sz = l.size(); - for(int i=0;i0) { - compile_array(list, lnode, false); - size = ((Insn)POP_ELEMENT(list)).i.l_op0; - ADD_SEQ(ret, list); - } - - ADD_INSN1(ret, nd_line(node), YARVInstructions.NEWHASH, size); - - if(poped) { - ADD_INSN(ret, nd_line(node), YARVInstructions.POP); - } - break compileLoop; - case FIXNUMNODE: - FixnumNode iVisited = (FixnumNode) node; - if(!poped) { - ADD_INSN1(ret, nd_line(node), YARVInstructions.PUTOBJECT, iVisited.getFixnum(runtime)); - } - break compileLoop; - case WHILENODE: - case UNTILNODE:{ - Label next_label = NEW_LABEL(nd_line(node)); /* next */ - Label redo_label = NEW_LABEL(nd_line(node)); /* redo */ - Label break_label = NEW_LABEL(nd_line(node)); /* break */ - Label end_label = NEW_LABEL(nd_line(node)); - - ADD_LABEL(ret, redo_label); - - Node body = null; - if(node instanceof WhileNode) { - body = ((WhileNode)node).getBodyNode(); - } else if(node instanceof UntilNode) { - body = ((UntilNode)node).getBodyNode(); - } - COMPILE_POPED(ret, "while body", body); - ADD_LABEL(ret, next_label); /* next */ - - if(node instanceof WhileNode) { - compile_branch_condition(ret, ((WhileNode)node).getConditionNode(), redo_label, end_label); - } else if(node instanceof UntilNode) { - /* untile */ - compile_branch_condition(ret, ((UntilNode)node).getConditionNode(),end_label, redo_label); - } else { - ADD_CALL_RECEIVER(ret, nd_line(node)); - //TODO: ADD_CALL(ret, nd_line(node), ID2SYM(idGets), INT2FIX(0)); - ADD_INSNL(ret, nd_line(node), YARVInstructions.BRANCHIF, redo_label) ; - /* opt_n */ - } - - ADD_LABEL(ret, end_label); - ADD_INSN(ret, nd_line(node), YARVInstructions.PUTNIL); - ADD_LABEL(ret, break_label); /* braek */ - if (poped) { - ADD_INSN(ret, nd_line(node), YARVInstructions.POP); - } - break compileLoop; - } - case SELFNODE: - if (!poped) ADD_INSN(ret, nd_line(node), YARVInstructions.PUTSELF); - break compileLoop; - case NILNODE: - if (!poped) ADD_INSN(ret, nd_line(node), YARVInstructions.PUTNIL); - break compileLoop; - case TRUENODE: - if (!poped) ADD_INSN1(ret, nd_line(node), YARVInstructions.PUTOBJECT, runtime.getTrue()); - break compileLoop; - case FALSENODE: - if (!poped) ADD_INSN1(ret, nd_line(node), YARVInstructions.PUTOBJECT, runtime.getFalse()); - break compileLoop; - default: - debugs(" ... doesn't handle node: " + node); - break compileLoop; - } - } - - return COMPILE_OK; - } - - private int compile_branch_condition(LinkAnchor ret, Node cond, Label then_label, Label else_label) { - switch(cond.getNodeType()) { - case NOTNODE: - compile_branch_condition(ret, ((NotNode)cond).getConditionNode(), else_label, then_label); - break; - case ANDNODE: { - Label label = NEW_LABEL(nd_line(cond)); - compile_branch_condition(ret, ((AndNode)cond).getFirstNode(), label, else_label); - ADD_LABEL(ret, label); - compile_branch_condition(ret, ((AndNode)cond).getSecondNode(), then_label, else_label); - break; - } - case ORNODE: { - Label label = NEW_LABEL(nd_line(cond)); - compile_branch_condition(ret, ((OrNode)cond).getFirstNode(), then_label, label); - ADD_LABEL(ret, label); - compile_branch_condition(ret, ((OrNode)cond).getSecondNode(), then_label, else_label); - break; - } - case TRUENODE: - case STRNODE: - ADD_INSNL(ret, nd_line(cond), YARVInstructions.JUMP, then_label); - break; - case FALSENODE: - case NILNODE: - ADD_INSNL(ret, nd_line(cond), YARVInstructions.JUMP, else_label); - break; - default: - COMPILE(ret, "branch condition", cond); - ADD_INSNL(ret, nd_line(cond), YARVInstructions.BRANCHUNLESS, else_label); - ADD_INSNL(ret, nd_line(cond), YARVInstructions.JUMP, then_label); - break; - } - - return COMPILE_OK; - } - - private int compile_array(LinkAnchor ret, Node node_root, boolean opt_p) { - Node node = node_root; - int len = ((ArrayNode)node).size(); - int line = nd_line(node); - LinkAnchor anchor = DECL_ANCHOR(); - List c = node.childNodes(); - for(Iterator iter = c.iterator(); iter.hasNext();) { - node = (Node)iter.next(); - if(opt_p && !(node instanceof ILiteralNode)) { - opt_p = false; - } - COMPILE(anchor, "array element", node); - } - - if(opt_p) { - List l = new ArrayList(); - for(Iterator iter = c.iterator(); iter.hasNext();) { - node = (Node)iter.next(); - switch(node.getNodeType()) { - case FIXNUMNODE: - l.add(((FixnumNode)node).getFixnum(runtime)); - break; - default: - debugs(" ... doesn't handle array literal node: " + node); - break; - } - } - ADD_INSN1(ret, nd_line(node_root), YARVInstructions.DUPARRAY, runtime.newArray(l)); - } else { - ADD_INSN1(anchor, line, YARVInstructions.NEWARRAY, len); - APPEND_LIST(ret, anchor); - } - - return len; - } - - private int[] setup_arg(LinkAnchor args, IArgumentNode node) { - int[] n = new int[] {0,0}; - Node argn = node.getArgsNode(); - LinkAnchor arg_block = DECL_ANCHOR(); - LinkAnchor args_push = DECL_ANCHOR(); - boolean blockArgs = false; - - if (argn != null) { - if (argn instanceof BlockPassNode) { - BlockPassNode blockPassNode = (BlockPassNode) argn; - COMPILE(arg_block, "block", blockPassNode.getBodyNode()); - - blockArgs = true; - argn = blockPassNode.getArgsNode(); - } - - switch(argn.getNodeType()) { - case SPLATNODE: - break; - case ARGSCATNODE: - break; - case ARGSPUSHNODE: - break; - default: - n[0] = compile_array(args,argn,false); - POP_ELEMENT(args); - break; - } - } - - if (!LIST_SIZE_ZERO(args_push)) ADD_SEQ(args, args_push); - if (blockArgs) ADD_SEQ(args, arg_block); - - return n; - } - - private Insn new_insn(YARVMachine.Instruction i) { - Insn n = new Insn(); - n.i = i; - n.next = null; - return n; - } - - private void insn_set_specialized_instruction(YARVMachine.Instruction instruction, int insn_id) - { - instruction.bytecode = insn_id; - //iobj->operand_size = 0; - //return COMPILE_OK; - } - - - private void ADD_CALL_RECEIVER(LinkAnchor seq, int line) { - ADD_INSN(seq, line, YARVInstructions.PUTNIL); - } - - private void ADD_INSN(LinkAnchor seq, int line, int insn) { - YARVMachine.Instruction i = new YARVMachine.Instruction(insn); - i.line_no = line; - debugs("ADD_INSN(" + line + ", " + YARVInstructions.name(insn) + ")"); - ADD_ELEM(seq, new_insn(i)); - } - - private YARVMachine.Instruction ADD_SEND_R(LinkAnchor seq, int line, String name, int argc, Object block, int flags) { - YARVMachine.Instruction i = new YARVMachine.Instruction(YARVInstructions.SEND); - i.line_no = line; - i.s_op0 = name; - i.i_op1 = argc; - i.i_op3 = flags; - debugs("ADD_SEND_R(" + line + ", " + YARVInstructions.name(YARVInstructions.SEND) + ", " + name + ", " + argc + ", " + flags + ")"); - ADD_ELEM(seq, new_insn(i)); - return i; - } - - private void ADD_INSN1(LinkAnchor seq, int line, int insn, IRubyObject obj) { - YARVMachine.Instruction i = new YARVMachine.Instruction(insn); - i.line_no = line; - i.o_op0 = obj; - debugs("ADD_INSN1(" + line + ", " + YARVInstructions.name(insn) + ", " + obj + ")"); - ADD_ELEM(seq, new_insn(i)); - } - - private void ADD_INSN1(LinkAnchor seq, int line, int insn, long op) { - YARVMachine.Instruction i = new YARVMachine.Instruction(insn); - i.line_no = line; - i.l_op0 = op; - debugs("ADD_INSN1(" + line + ", " + YARVInstructions.name(insn) + ", " + op + ")"); - ADD_ELEM(seq, new_insn(i)); - } - - private void ADD_INSNL(LinkAnchor seq, int line, int insn, Label l) { - YARVMachine.Instruction i = new YARVMachine.Instruction(insn); - i.line_no = line; - i._tmp = l; - debugs("ADD_INSNL(" + line + ", " + YARVInstructions.name(insn) + ", " + l + ")"); - ADD_ELEM(seq, new_insn(i)); - } - - private void ADD_INSN1(LinkAnchor seq, int line, int insn, String obj) { - YARVMachine.Instruction i = new YARVMachine.Instruction(insn); - i.line_no = line; - i.s_op0 = obj; - debugs("ADD_INSN1(" + line + ", " + YARVInstructions.name(insn) + ", " + obj + ")"); - ADD_ELEM(seq, new_insn(i)); - } - - private void ADD_INSN3(LinkAnchor seq, int line, int insn, String name, YARVMachine.InstructionSequence iseq, long n) { - YARVMachine.Instruction i = new YARVMachine.Instruction(insn); - i.line_no = line; - i.s_op0 = name; - i.iseq_op = iseq; - i.l_op0 = n; - debugs("ADD_INSN3(" + line + ", " + YARVInstructions.name(insn) + ", " + name + ", " + iseq + ", " + n + ")"); - ADD_ELEM(seq, new_insn(i)); - } - - public YARVMachine.InstructionSequence getInstructionSequence(String name, String filename, String level) { - iseq = new YARVMachine.InstructionSequence(runtime, name, filename, level); - List l = new ArrayList(); - Map jumps = new IdentityHashMap(); - Map labels = new IdentityHashMap(); - int real=0; - for (LinkElement elm = current_iseq; elm != null; elm = elm.next) { - if (elm instanceof Insn) { - Insn i = (Insn)elm; - if (isJump(i.i.bytecode)) jumps.put(i, i.i._tmp); - - l.add(i.i); - real++; - } else if (elm instanceof Label) { - labels.put(elm, new Integer(real+1)); - } - } - for(Iterator iter = jumps.keySet().iterator();iter.hasNext();) { - Insn k = (Insn)iter.next(); - k.i.l_op0 = ((Integer)labels.get(jumps.get(k))).intValue() - 1; - k.i._tmp = null; - } - - debugs("instructions: " + l); - iseq.body = (YARVMachine.Instruction[])l.toArray(new YARVMachine.Instruction[l.size()]); - iseq.locals = locals; - return iseq; - } - - private boolean isJump(int i) { - return i == YARVInstructions.JUMP || i == YARVInstructions.BRANCHIF || - i == YARVInstructions.BRANCHUNLESS || i == YARVInstructions.GETINLINECACHE || - i == YARVInstructions.SETINLINECACHE; - } -} diff --git a/src/org/jruby/internal/runtime/methods/RubiniusMethod.java b/src/org/jruby/internal/runtime/methods/RubiniusMethod.java deleted file mode 100644 index b544f5f6a25..00000000000 --- a/src/org/jruby/internal/runtime/methods/RubiniusMethod.java +++ /dev/null @@ -1,114 +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 - * - * 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.internal.runtime.methods; - -import org.jruby.Ruby; -import org.jruby.RubyModule; -import org.jruby.exceptions.JumpException; -import org.jruby.parser.StaticScope; -import org.jruby.runtime.Arity; -import org.jruby.runtime.Block; -import org.jruby.runtime.Frame; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.Visibility; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.ast.executable.RubiniusMachine; -import org.jruby.ast.executable.RubiniusCMethod; -import org.jruby.internal.runtime.JumpTarget; -import org.jruby.runtime.EventHook; -import org.jruby.runtime.RubyEvent; - -/** - * @author Ola Bini - */ -public class RubiniusMethod extends DynamicMethod implements JumpTarget { - private RubiniusCMethod cmethod; - private StaticScope staticScope; - private Arity arity; - - public RubiniusMethod(RubyModule implementationClass, RubiniusCMethod cmethod, StaticScope staticScope, Visibility visibility) { - super(implementationClass, visibility, CallConfiguration.FrameFullScopeFull); - this.staticScope = staticScope; - this.cmethod = cmethod; - this.arity = Arity.optional(); - } - - public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject[] args, Block block) { - assert args != null; - // System.err.println("--- entering " + cmethod.name); - Ruby runtime = context.getRuntime(); - - callConfig.pre(context, self, klazz, name, block, staticScope, this); - - try { - if (runtime.hasEventHooks()) { - traceCall(context, runtime, name); - } - - return RubiniusMachine.INSTANCE.exec(context, self, cmethod.code, cmethod.literals, args); - } catch (JumpException.ReturnJump rj) { - if (rj.getTarget() == this) return (IRubyObject) rj.getValue(); - - - throw rj; - } finally { - if (runtime.hasEventHooks()) { - traceReturn(context, runtime, name); - } - - callConfig.post(context); - // System.err.println("--- returning from " + cmethod.name); - } - } - - private void traceReturn(ThreadContext context, Ruby runtime, String name) { - if (!runtime.hasEventHooks()) { - return; - } - - Frame frame = context.getPreviousFrame(); - - runtime.callEventHooks(context, RubyEvent.RETURN, frame.getFile(), frame.getLine(), name, getImplementationClass()); - } - - private void traceCall(ThreadContext context, Ruby runtime, String name) { - if (!runtime.hasEventHooks()) { - return; - } - - runtime.callEventHooks(context, RubyEvent.CALL, context.getFile(), context.getLine(), name, getImplementationClass()); - } - - public Arity getArity() { - return this.arity; - } - - public DynamicMethod dup() { - return new RubiniusMethod(getImplementationClass(), cmethod, staticScope, getVisibility()); - } -}// RubiniusMethod diff --git a/src/org/jruby/internal/runtime/methods/YARVMethod.java b/src/org/jruby/internal/runtime/methods/YARVMethod.java deleted file mode 100644 index 75603adfc58..00000000000 --- a/src/org/jruby/internal/runtime/methods/YARVMethod.java +++ /dev/null @@ -1,185 +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 - * - * 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.internal.runtime.methods; - -import java.util.ArrayList; -import org.jruby.Ruby; -import org.jruby.RubyArray; -import org.jruby.RubyModule; -import org.jruby.exceptions.JumpException; -import org.jruby.parser.StaticScope; -import org.jruby.runtime.Arity; -import org.jruby.runtime.Block; -import org.jruby.runtime.DynamicScope; -import org.jruby.runtime.Frame; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.Visibility; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.ast.executable.YARVMachine; -import org.jruby.internal.runtime.JumpTarget; -import org.jruby.runtime.RubyEvent; - -/** - * @author Ola Bini - * @version $Revision: 1.2 $ - */ -public class YARVMethod extends DynamicMethod implements JumpTarget { - private YARVMachine.InstructionSequence iseq; - private StaticScope staticScope; - private Arity arity; - - public YARVMethod(RubyModule implementationClass, YARVMachine.InstructionSequence iseq, StaticScope staticScope, Visibility visibility) { - super(implementationClass, visibility, CallConfiguration.FrameFullScopeFull); - this.staticScope = staticScope; - this.iseq = iseq; - - boolean opts = iseq.args_arg_opts > 0 || iseq.args_rest > 0; - boolean req = iseq.args_argc > 0; - if(!req && !opts) { - this.arity = Arity.noArguments(); - } else if(req && !opts) { - this.arity = Arity.fixed(iseq.args_argc); - } else if(opts && !req) { - this.arity = Arity.optional(); - } else { - this.arity = Arity.required(iseq.args_argc); - } - } - - public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klazz, String name, IRubyObject[] args, Block block) { - assert args != null; - - Ruby runtime = context.getRuntime(); - - callConfig.pre(context, self, klazz, name, block, staticScope, this); - - try { - prepareArguments(context, runtime, args); - getArity().checkArity(runtime, args); - - if (runtime.hasEventHooks()) traceCall(context, runtime, name); - - DynamicScope scope = context.getCurrentScope(); - - // Why not setArgValues - scope.setArgValues(args, args.length); - - return YARVMachine.INSTANCE.exec(context, self, iseq.body); - } catch (JumpException.ReturnJump rj) { - if (rj.getTarget() == this) return (IRubyObject) rj.getValue(); - - throw rj; - } finally { - if (runtime.hasEventHooks()) traceReturn(context, runtime, name); - - callConfig.post(context); - } - } - - private void prepareArguments(ThreadContext context, Ruby runtime, IRubyObject[] args) { - context.setFileAndLine(iseq.filename, -1); - - int expectedArgsCount = iseq.args_argc; - int restArg = iseq.args_rest; - boolean hasOptArgs = iseq.args_arg_opts > 0; - - if (expectedArgsCount > args.length) { - throw runtime.newArgumentError("Wrong # of arguments(" + args.length + " for " + expectedArgsCount + ")"); - } - - // optArgs and restArgs require more work, so isolate them and ArrayList creation here - if (hasOptArgs || restArg != -1) { - prepareOptOrRestArgs(context, runtime, args, expectedArgsCount, restArg, hasOptArgs); - } - } - - private IRubyObject[] prepareOptOrRestArgs(ThreadContext context, Ruby runtime, IRubyObject[] args, int expectedArgsCount, int restArg, boolean hasOptArgs) { - if (restArg == 0 && hasOptArgs) { - int opt = expectedArgsCount + iseq.args_arg_opts; - - if (opt < args.length) { - throw runtime.newArgumentError("wrong # of arguments(" + args.length + " for " + opt + ")"); - } - } - - int count = expectedArgsCount + iseq.args_arg_opts + iseq.args_rest; - - ArrayList allArgs = new ArrayList(); - - // Combine static and optional args into a single list allArgs - for (int i = 0; i < count && i < args.length; i++) { - allArgs.add(args[i]); - } - - if (restArg != 0) { - for (int i = expectedArgsCount; i < args.length; i++) { - allArgs.add(args[i]); - } - - // only set in scope if named - if (restArg >= 0) { - RubyArray array = runtime.newArray(args.length - expectedArgsCount); - for (int i = expectedArgsCount; i < args.length; i++) { - array.append(args[i]); - } - - context.getCurrentScope().setValue(restArg, array, 0); - } - } - - args = (IRubyObject[])allArgs.toArray(new IRubyObject[allArgs.size()]); - return args; - } - - private void traceReturn(ThreadContext context, Ruby runtime, String name) { - if (!runtime.hasEventHooks()) { - return; - } - - Frame frame = context.getPreviousFrame(); - - runtime.callEventHooks(context, RubyEvent.RETURN, frame.getFile(), frame.getLine(), name, getImplementationClass()); - } - - private void traceCall(ThreadContext context, Ruby runtime, String name) { - if (!runtime.hasEventHooks()) { - return; - } - - runtime.callEventHooks(context, RubyEvent.CALL, context.getFile(), context.getLine(), name, getImplementationClass()); - } - - @Override - public Arity getArity() { - return this.arity; - } - - public DynamicMethod dup() { - return new YARVMethod(getImplementationClass(), iseq, staticScope, getVisibility()); - } -}// YARVMethod diff --git a/src/org/jruby/management/Config.java b/src/org/jruby/management/Config.java index a823d8e988a..dafb465c109 100644 --- a/src/org/jruby/management/Config.java +++ b/src/org/jruby/management/Config.java @@ -126,22 +126,10 @@ public boolean isDebug() { return ruby.get().getInstanceConfig().isDebug(); } - public boolean isYARVEnabled() { - return ruby.get().getInstanceConfig().isYARVEnabled(); - } - public String getInputFieldSeparator() { return ruby.get().getInstanceConfig().getInputFieldSeparator(); } - public boolean isRubiniusEnabled() { - return ruby.get().getInstanceConfig().isRubiniusEnabled(); - } - - public boolean isYARVCompileEnabled() { - return ruby.get().getInstanceConfig().isYARVCompileEnabled(); - } - public String getKCode() { return ruby.get().getInstanceConfig().getKCode().name(); } diff --git a/src/org/jruby/management/ConfigMBean.java b/src/org/jruby/management/ConfigMBean.java index bfe3c0a930d..d0b4e398a39 100644 --- a/src/org/jruby/management/ConfigMBean.java +++ b/src/org/jruby/management/ConfigMBean.java @@ -29,10 +29,7 @@ public interface ConfigMBean { public boolean isSplit(); public boolean isVerbose(); public boolean isDebug(); - public boolean isYARVEnabled(); public String getInputFieldSeparator(); - public boolean isRubiniusEnabled(); - public boolean isYARVCompileEnabled(); public String getKCode(); public String getRecordSeparator(); public int getSafeLevel(); diff --git a/test/org/jruby/ast/executable/YARVMachineTest.java b/test/org/jruby/ast/executable/YARVMachineTest.java deleted file mode 100644 index 4f767ba0742..00000000000 --- a/test/org/jruby/ast/executable/YARVMachineTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.jruby.ast.executable; - -import org.jruby.Ruby; -import org.jruby.ast.executable.YARVMachine.Instruction; -import org.jruby.parser.LocalStaticScope; -import org.jruby.parser.StaticScope; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.builtin.IRubyObject; - -import junit.framework.TestCase; - -public class YARVMachineTest extends TestCase { - public static Instruction[] getSimpleTest(Ruby runtime) { - return new Instruction[] { - new Instruction(YARVInstructions.PUTSTRING, "Hello, YARV!"), // S: "HY" - new Instruction(YARVInstructions.DUP), // S: "HY", "HY" - new Instruction(YARVInstructions.SETLOCAL, 0), // S: "HY"; L: "HY" - new Instruction(YARVInstructions.GETLOCAL, 0), // S: "HY", "HY" - new Instruction(YARVInstructions.POP), // S: "HY" - new Instruction(YARVInstructions.SETLOCAL, 1), // S: ; L: "HY", "HY" - new Instruction(YARVInstructions.PUTOBJECT, runtime.getTrue()), // S: true; L: "HY", "HY" - new Instruction(YARVInstructions.BRANCHIF, 10), // S: ; L: "HY", "HY" - new Instruction(YARVInstructions.PUTSTRING, "Wrong String"), - new Instruction(YARVInstructions.JUMP, 11), - new Instruction(YARVInstructions.GETLOCAL, 1), // S: "HY"; L: "HY", "HY" - new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(2)), // S: "HY", 2; L: "HY", "HY" - new Instruction(YARVInstructions.SEND, "*", 1, null, 0), // S: "HYHY"; L: "HY", "HY" - new Instruction(YARVInstructions.PUTNIL), // S: "HYHY", nil; L: "HY", "HY" - new Instruction(YARVInstructions.SEND, "to_s", 0, null, YARVInstructions.VCALL_FLAG | YARVInstructions.FCALL_FLAG), // S: "HYHY", Object; ... - new Instruction(YARVInstructions.SEND, "+", 1, null, 0) // S: "HYHYObject"; L: "HY", "HY" - }; - }; - - public static Instruction[] getFib(Ruby runtime, int n){ - return new Instruction[] { - // local var n declared (argument) - new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(n)), // fib index - new Instruction(YARVInstructions.SETLOCAL, 0), - // method begins here - // local var i declared - new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(0)), - new Instruction(YARVInstructions.SETLOCAL, 1), - // local var j declared - new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(1)), - new Instruction(YARVInstructions.SETLOCAL, 2), - // local var cur declared - new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(1)), - new Instruction(YARVInstructions.SETLOCAL, 3), - // while begins here, instruction 8 - new Instruction(YARVInstructions.GETLOCAL, 3), - new Instruction(YARVInstructions.GETLOCAL, 0), - new Instruction(YARVInstructions.SEND, "<=", 1, null, 0), - new Instruction(YARVInstructions.BRANCHUNLESS, 25), - // local var k declared, k = i - new Instruction(YARVInstructions.GETLOCAL, 1), - new Instruction(YARVInstructions.SETLOCAL, 4), - // i = j - new Instruction(YARVInstructions.GETLOCAL, 2), - new Instruction(YARVInstructions.SETLOCAL, 1), - // j = k + j - new Instruction(YARVInstructions.GETLOCAL, 4), - new Instruction(YARVInstructions.GETLOCAL, 2), - new Instruction(YARVInstructions.SEND, "+", 1, null, 0), - new Instruction(YARVInstructions.SETLOCAL, 2), - // cur = cur + 1 - new Instruction(YARVInstructions.GETLOCAL, 3), - new Instruction(YARVInstructions.PUTOBJECT, runtime.newFixnum(1)), - new Instruction(YARVInstructions.SEND, "+", 1, null, 0), - new Instruction(YARVInstructions.SETLOCAL, 3), - // end while - new Instruction(YARVInstructions.JUMP, 8), - // return i, instruction 25 - new Instruction(YARVInstructions.GETLOCAL, 1) - }; - }; - - public void testSimpleExecution() { - YARVMachine ym = new YARVMachine(); - - Ruby runtime = Ruby.newInstance(System.in, System.out, System.err); - ThreadContext context = runtime.getCurrentContext(); - - StaticScope scope = new LocalStaticScope(null); - scope.setVariables(new String[] { "zero", "one" }); - assertEquals("Hello, YARV!Hello, YARV!Object", ym.exec(context, scope, getSimpleTest(runtime)).toString()); - } - - public void testIterativeFib() { - YARVMachine ym = new YARVMachine(); - - Ruby runtime = Ruby.newInstance(System.in, System.out, System.err); - ThreadContext context = runtime.getCurrentContext(); - - StaticScope scope = new LocalStaticScope(null); - scope.setVariables(new String[] {"n", "i", "j", "cur", "k"}); - assertEquals("55", ym.exec(context, scope, getFib(runtime,10)).toString()); - - IRubyObject fib5k = ym.exec(context, scope, getFib(runtime,5000)); - assertEquals("38789684543883256337019163083259053120821277146462451061605972148955501390440370" + - "9701082291646221066947929345285888297381348310200895498294036143015691147893836421656" + - "3944106910214505634133706558656238254656700712525929903854933813928836378347518908762" + - "9707120333370529231076930085180938498018038478139967488817655546537882916442689129803" + - "8461377896902150229308247566634622492307188332480328037503913035290330450584270114763" + - "5242270210934637699104006714174883298422891491273104054328753298044273676822977244987" + - "7498745556919077038806370468327948113589737399931101062193081490185708153978543791953" + - "0561751076105307568878376603366735544525884488624161921055345749367589784902798823435" + - "1023599844663934853256411952221859563060475364645470760330902420806382584929156452876" + - "2915757591423438091423029174910889841552098544324865940797935713168416928680395453095" + - "4538869811466508206686289742063932343848846524098874239587380197699382031717420893226" + - "5468879364002630797780058759129671389634214252579116872755600360311370547754724604639" + - "987588046985178408674382863125", fib5k.toString()); - } - - public static void main(String[] args) { - new YARVMachineTest().testIterativeFib(); - } -} diff --git a/test/org/jruby/test/MainTestSuite.java b/test/org/jruby/test/MainTestSuite.java index 4183b8e6660..fffad99d49a 100644 --- a/test/org/jruby/test/MainTestSuite.java +++ b/test/org/jruby/test/MainTestSuite.java @@ -36,7 +36,6 @@ import junit.framework.Test; import junit.framework.TestSuite; -import org.jruby.ast.executable.YARVMachineTest; import org.jruby.ext.posix.JavaFileStatTest; import org.jruby.javasupport.TestJava; import org.jruby.javasupport.TestJavaClass; @@ -73,7 +72,6 @@ public static Test suite() throws Throwable { suite.addTestSuite(TestRubyException.class); suite.addTestSuite(TestAdoptedThreading.class); suite.addTestSuite(TestRubyArray.class); - suite.addTestSuite(YARVMachineTest.class); suite.addTestSuite(TestRaiseException.class); suite.addTestSuite(PlatformTest.class); suite.addTestSuite(ShellLauncherTest.class); diff --git a/test/org/jruby/test/TestRubyBase.java b/test/org/jruby/test/TestRubyBase.java index 0693a8d1f34..df6dc679792 100644 --- a/test/org/jruby/test/TestRubyBase.java +++ b/test/org/jruby/test/TestRubyBase.java @@ -67,8 +67,7 @@ protected String eval(String script) throws Exception { runtime.getGlobalVariables().set("$stderr", lStream); runtime.runNormally( - runtime.parseFile(new ByteArrayInputStream(script.getBytes()), "test", runtime.getCurrentContext().getCurrentScope()), - false); + runtime.parseFile(new ByteArrayInputStream(script.getBytes()), "test", runtime.getCurrentContext().getCurrentScope())); StringBuffer sb = new StringBuffer(new String(result.toByteArray())); for (int idx = sb.indexOf("\n"); idx != -1; idx = sb.indexOf("\n")) { sb.deleteCharAt(idx);