コード例 #1
0
 public virtual Instruction GetInstruction(LightCompiler compiler) {
     compiler.Compile(_context);
     if (_isLocal) {
         return new LookupNameInstruction(_name);
     } else {
         return new LookupGlobalNameInstruction(_name);
     }
 }
コード例 #2
0
        public void AddInstructions(LightCompiler compiler) {
            Instruction instr = DynamicInstructionN.CreateUntypedInstruction(_binder, ArgumentCount);
            if (instr == null) {
                var lightBinder = _binder as ILightCallSiteBinder;
                if (lightBinder == null || !lightBinder.AcceptsArgumentArray) {
                    compiler.Compile(Reduce());
                    return;
                }

                Debug.Assert(Type == typeof(object));
                instr = new DynamicSplatInstruction(ArgumentCount, CallSite<Func<CallSite, ArgumentArray, object>>.Create(_binder));
            }

            for (int i = 0; i < ArgumentCount; i++) {
                compiler.Compile(GetArgument(i));
            }

            compiler.Instructions.Emit(instr);
        }
コード例 #3
0
 public void AddInstructions(LightCompiler compiler) {
     compiler.Compile(_target);
     switch (Type.GetTypeCode(_binder.Type)) {
         case TypeCode.Boolean:
             compiler.Instructions.Emit(BooleanConversionInstruction.Instance);
             break;
         default:
             compiler.Instructions.Emit(new TypedConversionInstruction(_binder.Type));
             break;
     }
 }
コード例 #4
0
 public override void AddInstructions(LightCompiler compiler)
 {
     if (Argument0.Type == typeof(CodeContext))
     {
         compiler.Compile(Argument0);
         compiler.Compile(Argument1);
         compiler.Instructions.EmitDynamic<CodeContext, object, object>(Binder);
     }
     else if (Argument1.Type == typeof(CodeContext))
     {
         // GetMember sites
         compiler.Compile(Argument0);
         compiler.Compile(Argument1);
         compiler.Instructions.EmitDynamic<object, CodeContext, object>(Binder);
     }
     else
     {
         base.AddInstructions(compiler);
     }
 }
コード例 #5
0
 public override Instruction GetInstruction(LightCompiler compiler) {
     compiler.Compile(this._value);
     return new SetGlobalInstruction(Global);
 }
コード例 #6
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(FunctionDefinition._functionParam);
     compiler.Instructions.Emit(GetLocalClosureFromFunctionInstruction.Instance);
 }
コード例 #7
0
        public override void AddInstructions(LightCompiler compiler) {
            if (ArgumentCount > 15) {
                compiler.Compile(Reduce());
            } else if (GetArgument(0).Type == typeof(CodeContext)) {
                for (int i = 0; i < ArgumentCount; i++) {
                    compiler.Compile(GetArgument(i));
                }

                switch(ArgumentCount) {
                    case 1: compiler.Instructions.EmitDynamic<CodeContext, object>(Binder); break;
                    case 2: compiler.Instructions.EmitDynamic<CodeContext, object, object>(Binder); break;
                    case 3: compiler.Instructions.EmitDynamic<CodeContext, object, object, object>(Binder); break;
                    case 4: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object>(Binder); break;
                    case 5: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object>(Binder); break;
                    case 6: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object>(Binder); break;
                    case 7: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object>(Binder); break;
                    case 8: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object>(Binder); break;
                    case 9: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object>(Binder); break;
                    case 10: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object, object>(Binder); break;
                    case 11: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object, object, object>(Binder); break;
                    case 12: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object, object, object, object>(Binder); break;
                    case 13: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object, object, object, object, object>(Binder); break;
                    case 14: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object, object, object, object, object, object>(Binder); break;
                    case 15: compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>(Binder); break;                    
                }
            } else {
                base.AddInstructions(compiler);
            }
        }
コード例 #8
0
ファイル: BinaryExpression.cs プロジェクト: rudimk/dlr-dotnet
        void IInstructionProvider.AddInstructions(LightCompiler compiler) {
            if (NeedComparisonTransformation()) {
                // chained comparisons aren't supported for optimized light compiling
                compiler.Compile(Reduce());
                return;
            }

            switch (_op) {
                case PythonOperator.Is:
                    compiler.Compile(_left);
                    compiler.Compile(_right);
                    compiler.Instructions.Emit(IsInstruction.Instance);
                    break;
                case PythonOperator.IsNot:
                    compiler.Compile(_left);
                    compiler.Compile(_right);
                    compiler.Instructions.Emit(IsNotInstruction.Instance);
                    break;
                default:
                    compiler.Compile(Reduce());
                    break;
            }
        }
コード例 #9
0
ファイル: FunctionDefinition.cs プロジェクト: mstram/ironruby
        private void CreateFunctionInstructions(LightCompiler compiler) {
            // emit context if we have a special local context
            CodeContext globalContext = null;

            // potential optimization to avoid loading the context:
            /*if (Parent.LocalContext == PythonAst._globalContext) {
                globalContext = GlobalParent.ModuleContext.GlobalContext;
            } else*/ {
                compiler.Compile(Parent.LocalContext);
            }

            // emit name if necessary
            PythonGlobalVariableExpression name = GetVariableExpression(_nameVariable) as PythonGlobalVariableExpression;
            PythonGlobal globalName = null;
            if (name == null) {
                compiler.Compile(((IPythonGlobalExpression)GetVariableExpression(_nameVariable)).RawValue());
            } else {
                globalName = name.Global;
            }

            // emit defaults
            int defaultCount = 0;
            for (int i = _parameters.Length - 1; i >= 0; i--) {
                var param = _parameters[i];

                if (param.DefaultValue != null) {
                    compiler.Compile(AstUtils.Convert(param.DefaultValue, typeof(object)));
                    defaultCount++;
                }
            }

            compiler.Instructions.Emit(new FunctionDefinitionInstruction(globalContext, this, defaultCount, globalName));
        }
コード例 #10
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(FunctionDefinition._functionParam);
     compiler.Instructions.Emit(GetParentContextFromFunctionInstruction.Instance);
 }
コード例 #11
0
ファイル: CallExpression.cs プロジェクト: rudimk/dlr-dotnet
        void IInstructionProvider.AddInstructions(LightCompiler compiler) {
            if (_target is NameExpression && ((NameExpression)_target).Name == "unicode") {
                compiler.Compile(Reduce());
                return;
            }

            for (int i = 0; i < _args.Length; i++) {
                if (!_args[i].GetArgumentInfo().IsSimple) {
                    compiler.Compile(Reduce());
                    return;
                }
            }

            switch (_args.Length) {
                #region Generated Python Call Expression Instruction Switch

                // *** BEGIN GENERATED CODE ***
                // generated by function: gen_call_expression_instruction_switch from: generate_calls.py

                case 0:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Instructions.Emit(new Invoke0Instruction(Parent.PyContext));
                    return;
                case 1:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Compile(_args[0].Expression);
                    compiler.Instructions.Emit(new Invoke1Instruction(Parent.PyContext));
                    return;
                case 2:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Compile(_args[0].Expression);
                    compiler.Compile(_args[1].Expression);
                    compiler.Instructions.Emit(new Invoke2Instruction(Parent.PyContext));
                    return;
                case 3:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Compile(_args[0].Expression);
                    compiler.Compile(_args[1].Expression);
                    compiler.Compile(_args[2].Expression);
                    compiler.Instructions.Emit(new Invoke3Instruction(Parent.PyContext));
                    return;
                case 4:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Compile(_args[0].Expression);
                    compiler.Compile(_args[1].Expression);
                    compiler.Compile(_args[2].Expression);
                    compiler.Compile(_args[3].Expression);
                    compiler.Instructions.Emit(new Invoke4Instruction(Parent.PyContext));
                    return;
                case 5:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Compile(_args[0].Expression);
                    compiler.Compile(_args[1].Expression);
                    compiler.Compile(_args[2].Expression);
                    compiler.Compile(_args[3].Expression);
                    compiler.Compile(_args[4].Expression);
                    compiler.Instructions.Emit(new Invoke5Instruction(Parent.PyContext));
                    return;
                case 6:
                    compiler.Compile(Parent.LocalContext);
                    compiler.Compile(_target);
                    compiler.Compile(_args[0].Expression);
                    compiler.Compile(_args[1].Expression);
                    compiler.Compile(_args[2].Expression);
                    compiler.Compile(_args[3].Expression);
                    compiler.Compile(_args[4].Expression);
                    compiler.Compile(_args[5].Expression);
                    compiler.Instructions.Emit(new Invoke6Instruction(Parent.PyContext));
                    return;

                // *** END GENERATED CODE ***

                #endregion
            }
            compiler.Compile(Reduce());
        }
コード例 #12
0
 void IInstructionProvider.AddInstructions(LightCompiler compiler) {
     // the interpreter deals with jumps out of finally blocks just fine:
     compiler.Compile(_body);
 }
コード例 #13
0
 public void AddInstructions(LightCompiler compiler) {
     compiler.Compile(_target);
     compiler.Compile(_codeContext);
     compiler.Instructions.Emit(new GetMemberInstruction(_binder));
 }
コード例 #14
0
 Instruction IInstructionProvider.GetInstruction(LightCompiler compiler) {
     compiler.Compile(_scope);
     return new LookupGlobalInstruction(_name, _isLocal);
 }
コード例 #15
0
 public Instruction GetInstruction(LightCompiler compiler) {
     compiler.Compile(_value);
     return new PythonSetGlobalInstruction(_global.Global);
 }
コード例 #16
0
ファイル: IfStatement.cs プロジェクト: jschementi/iron
 void IInstructionProvider.AddInstructions(LightCompiler compiler) {
     // optimizing bool conversions does no good in the light compiler
     compiler.Compile(ReduceWorker(false));
 }
コード例 #17
0
 public void AddInstructions(LightCompiler compiler) {
     compiler.Compile(_value);
     compiler.AddInstruction(new PythonSetGlobalInstruction(_global.Global));
 }
コード例 #18
0
        void IInstructionProvider.AddInstructions(LightCompiler compiler) {
            if (_items.Length == 0) {
                compiler.Instructions.Emit(EmptyDictInstruction.Instance);
                return;
            }

            compiler.Compile(Reduce());
        }
コード例 #19
0
ファイル: FunctionDefinition.cs プロジェクト: mstram/ironruby
        void IInstructionProvider.AddInstructions(LightCompiler compiler) {
            if (_decorators != null) {
                // decorators aren't supported, skip using the optimized instruction.
                compiler.Compile(Reduce());
                return;
            }

            // currently needed so we can later compile
            MSAst.Expression funcCode = GlobalParent.Constant(GetOrMakeFunctionCode());
            FuncCodeExpr = funcCode;

            var variable = Parent.GetVariableExpression(_variable);

            CompileAssignment(compiler, variable, CreateFunctionInstructions);
        }
コード例 #20
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_value);
     compiler.Instructions.Emit(new TotemSetGlobalInstruction(_global.Global));
 }
コード例 #21
0
ファイル: FunctionDefinition.cs プロジェクト: mstram/ironruby
        private static void CompileAssignment(LightCompiler compiler, MSAst.Expression variable, Action<LightCompiler> compileValue) {
            var instructions = compiler.Instructions;

            ClosureExpression closure = variable as ClosureExpression;
            if (closure != null) {
                compiler.Compile(closure.ClosureCell);
            }
            LookupGlobalVariable lookup = variable as LookupGlobalVariable;
            if (lookup != null) {
                compiler.Compile(lookup.CodeContext);
                instructions.EmitLoad(lookup.Name);
            }

            compileValue(compiler);

            if (closure != null) {
                instructions.EmitStoreField(ClosureExpression._cellField);
                return;
            }
            if (lookup != null) {
                instructions.EmitCall(typeof(PythonOps).GetMethod(lookup.IsLocal ? "SetLocal" : "SetGlobal"));
                return;
            }

            MSAst.ParameterExpression functionValueParam = variable as MSAst.ParameterExpression;
            if (functionValueParam != null) {
                instructions.EmitStoreLocal(compiler.GetVariableIndex(functionValueParam));
                return;
            }

            var globalVar = variable as PythonGlobalVariableExpression;
            if (globalVar != null) {
                instructions.Emit(new PythonSetGlobalInstruction(globalVar.Global));
                instructions.EmitPop();
                return;
            }
            Debug.Assert(false, "Unsupported variable type for light compiling function");
        }
コード例 #22
0
 void IInstructionProvider.AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_codeContextExpr);
     compiler.Instructions.Emit(new LookupGlobalInstruction(_name, _isLocal, _lightThrow));
 }
コード例 #23
0
 public override void AddInstructions(LightCompiler compiler) {
     if (Argument0.Type == typeof(CodeContext)) {
         compiler.Compile(Argument0);
         compiler.Compile(Argument1);
         compiler.Compile(Argument2);
         compiler.Compile(Argument3);
         compiler.Instructions.EmitDynamic<CodeContext, object, object, object, object>(Binder);
         return;
     } else {
         base.AddInstructions(compiler);
     }
 }
コード例 #24
0
 public override Instruction GetInstruction(LightCompiler compiler) {
     compiler.Compile(_context);
     compiler.Compile(_value);
     if (_isLocal) {
         return new SetNameInstruction(_name);
     } else {
         return new SetGlobalNameInstruction(_name);
     }
 }
コード例 #25
0
 public void AddInstructions(LightCompiler compiler) {
     compiler.Compile(_parentContext);
     compiler.Instructions.Emit(GetGlobalContextInstruction.Instance);
 }
コード例 #26
0
 void IInstructionProvider.AddInstructions(LightCompiler compiler) {
     compiler.Compile(_scope);
     compiler.AddInstruction(new LookupGlobalInstruction(_name, _isLocal));
 }