Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: EPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Eclipse 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/epl-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 Charles O Nutter <headius@headius.com> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the EPL, 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 EPL, the GPL or the LGPL. END LICENSE BLOCK ***
 
 
 package org.jruby.compiler.impl;
 
 import org.jruby.Ruby;
 import  org.objectweb.asm.Label;
 import static org.jruby.util.CodegenUtils.*;

Author(s):
headius
 
     private int baseVariableIndex;
 
     public StackBasedVariableCompiler(
             BaseBodyCompiler methodCompiler,
             SkinnyMethodAdapter method,
             StaticScope scope,
             boolean specificArity,
             int argsIndex,
             int firstTempIndex) {
         super(methodCompilermethodscopespecificArityargsIndexfirstTempIndex);
         this. = firstTempIndex;
     }
 
     public void beginMethod(CompilerCallback argsCallbackStaticScope scope) {
         // fill in all vars with nil so compiler is happy about future accesses
         if (scope.getNumberOfVariables() > 0) {
             // if we don't have opt args, start after args (they will be assigned later)
             // this is for crap like def foo(a = (b = true; 1)) which numbers b before a
             // FIXME: only starting after required args, since opt args may access others
             // and rest args conflicts with compileRoot using "0" to indicate [] signature.
             if (scope.getRequiredArgs() < scope.getNumberOfVariables()) {
                 int start = scope.getRequiredArgs();
                 .loadNil();
                 for (int i = starti < scope.getNumberOfVariables(); i++) {
                     if (i + 1 < scope.getNumberOfVariables()) ..dup();
                     assignLocalVariable(ifalse);
                 }
             }
 
             // temp locals must start after last real local
              += scope.getNumberOfVariables();
         }
 
         if (argsCallback != null) {
             argsCallback.call();
         }
     }
     
     public void declareLocals(StaticScope scope, Label start, Label end) {
         // declare locals for Java debugging purposes
         String[] variables = scope.getVariables();
         for (int i = 0; i < variables.lengthi++) {
             .local( + ivariables[i], IRubyObject.class);
         }
     }
 
     public void beginClass(StaticScope scope) {
         assert scope != null : "compiling a class body with no scope";
         
         // fill in all vars with nil so compiler is happy about future accesses
         if (scope.getNumberOfVariables() > 0) {
             // if we don't have opt args, start after args (they will be assigned later)
             // this is for crap like def foo(a = (b = true; 1)) which numbers b before a
             // FIXME: only starting after required args, since opt args may access others
            // and rest args conflicts with compileRoot using "0" to indicate [] signature.
            int start = scope.getRequiredArgs();
            for (int i = starti < scope.getNumberOfVariables(); i++) {
                .loadNil();
                assignLocalVariable(ifalse);
            }
            // temp locals must start after last real local
             += scope.getNumberOfVariables();
        }
    }
    public void beginClosure(CompilerCallback argsCallbackStaticScope scope) {
        assert scope != null : "compiling a closure body with no scope";
        
        // store the local vars in a local variable
        .invokeThreadContext("getCurrentScope"sig(DynamicScope.class));
        
        boolean first = true;
        for (int i = 0; i < scope.getNumberOfVariables(); i++) {
            if (first) {
                .loadNil();
                first = false;
            }
            // assign, duping value for all but last
            assignLocalVariable(ii + 1 < scope.getNumberOfVariables());
        }
        // temp locals must start after last real local
         += scope.getNumberOfVariables();
        if (argsCallback != null) {
            // load block
            .loadRuntime();
            .aload(.getClosureIndex());
            .invokeUtilityMethod("processBlockArgument"sig(IRubyObject.classparams(Ruby.classBlock.class)));
            // load args (the IRubyObject representing incoming normal args)
            .aload();
            argsCallback.call();
        }
    }
    public void beginFlatClosure(CompilerCallback argsCallbackStaticScope scope) {
        throw new NotCompilableException("Can't have flat closure with stack-based scope");
    }
    public void assignLocalVariable(int indexboolean expr) {
        if (expr) {
            .dup();
        }
        .astore( + index);
    }
    private void assignLocalVariable(int indexCompilerCallback valueboolean expr) {
        value.call();
        assignLocalVariable(indexexpr);
    }
    public void assignLocalVariable(int indexint depth,boolean expr) {
        if (depth == 0) {
            assignLocalVariable(indexexpr);
        } else {
            assignHeapLocal(depthindexexpr);
        }
    }
    public void assignLocalVariable(int indexint depthCompilerCallback valueboolean expr) {
        if (depth == 0) {
            assignLocalVariable(indexvalueexpr);
        } else {
            assignHeapLocal(valuedepthindexexpr);
        }
    }
    public void retrieveLocalVariable(int index) {
        .aload( + index);
    }
    public void retrieveLocalVariable(int indexint depth) {
        if (depth == 0) {
            retrieveLocalVariable(index);
        } else {
            retrieveHeapLocal(depthindex);
        }
    }
New to GrepCode? Check out our FAQ X