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); } }
public override void AddInstructions(LightCompiler compiler) { if (Argument0.Type == typeof(CodeContext)) { compiler.Compile(Argument0); compiler.Compile(Argument1); compiler.Compile(Argument2); compiler.Instructions.EmitDynamic <CodeContext, object, object, object>(Binder); } else { base.AddInstructions(compiler); } }
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) { var setter = typeof(PythonOps).GetMethod(lookup.IsLocal ? nameof(PythonOps.SetLocal) : nameof(PythonOps.SetGlobal)); instructions.Emit(CallInstruction.Create(setter)); return; } MSAst.ParameterExpression functionValueParam = variable as MSAst.ParameterExpression; if (functionValueParam != null) { instructions.EmitStoreLocal(compiler.Locals.GetLocalIndex(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"); }
public void AddInstructions(LightCompiler compiler) { var endOfTrue = compiler.Instructions.MakeLabel(); var endOfFalse = compiler.Instructions.MakeLabel(); // condition compiler.Compile(_expr); compiler.CompileSetVariable(LightExceptionRewriter._lastValue, false); compiler.Instructions.Emit(IsLightExceptionInstruction.Instance); // true - an exception occured compiler.Instructions.EmitBranchFalse(endOfTrue); if (_lastValue != null) { compiler.CompileParameterExpression(_lastValue); } compiler.Instructions.EmitGoto( compiler.GetBranchLabel(_target), _retType != typeof(void), _lastValue != null && _lastValue.Type != typeof(void) ); compiler.Instructions.EmitBranch(endOfFalse, false, true); // false - no exception compiler.Instructions.MarkLabel(endOfTrue); compiler.CompileParameterExpression(LightExceptionRewriter._lastValue); compiler.Instructions.MarkLabel(endOfFalse); }
void IInstructionProvider.AddInstructions(LightCompiler compiler) { if (_items.Length == 0) { compiler.Instructions.Emit(EmptyDictInstruction.Instance); return; } compiler.Compile(Reduce()); }
private void CreateFunctionInstructions(LightCompiler compiler) { // emit context if we have a special local context CodeContext globalContext = null; 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++; } } // emit annotations int annotationCount = 0; if (ReturnAnnotation != null) { compiler.Compile(AstUtils.Convert(ReturnAnnotation, typeof(object))); compiler.Compile(AstUtils.Constant("return", typeof(string))); annotationCount++; } for (int i = _parameters.Length - 1; i >= 0; i--) { var param = _parameters[i]; if (param.Annotation != null) { compiler.Compile(AstUtils.Convert(param.Annotation, typeof(object))); compiler.Compile(AstUtils.Constant(param.Name, typeof(string))); annotationCount++; } } compiler.Instructions.Emit(new FunctionDefinitionInstruction(globalContext, this, defaultCount, annotationCount, globalName)); }
public void AddInstructions(LightCompiler compiler) { compiler.PushLabelBlock(LabelScopeKind.Block); var local = compiler.Locals.DefineLocal(_lastValue, compiler.Instructions.Count); var label = compiler.DefineLabel(_returnLabel); compiler.Compile(_body); compiler.Instructions.MarkLabel(label.GetLabel(compiler)); compiler.Locals.UndefineLocal(local, compiler.Instructions.Count); compiler.PopLabelBlock(LabelScopeKind.Block); }
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; } }
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; } }
public virtual 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); }
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(PythonVariable); CompileAssignment(compiler, variable, CreateFunctionInstructions); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(_lastValue); compiler.Instructions.Emit(IsLightExceptionInstruction.Instance); }
void IInstructionProvider.AddInstructions(LightCompiler compiler) { Arg[] args = Args; if (args.Length == 0 && ImplicitArgs.Count > 0) { args = ImplicitArgs.ToArray(); } 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()); }
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()); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(_target); compiler.Compile(_codeContext); compiler.Instructions.Emit(new GetMemberInstruction(_binder)); }
void IInstructionProvider.AddInstructions(LightCompiler compiler) { // the interpreter deals with jumps out of finally blocks just fine: compiler.Compile(_body); }
void IInstructionProvider.AddInstructions(LightCompiler compiler) { compiler.Compile(_codeContextExpr); compiler.Instructions.Emit(new LookupGlobalInstruction(_name, _isLocal, _lightThrow)); }
void IInstructionProvider.AddInstructions(LightCompiler compiler) { // optimizing bool conversions does no good in the light compiler compiler.Compile(ReduceWorker(false)); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(Expression.TryFault(_body, _fault)); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(_test); compiler.Instructions.EmitLoad(_bindingInfo); compiler.EmitCall(InterpretedCallSiteTest); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(FunctionDefinition._functionParam); compiler.Instructions.Emit(GetParentContextFromFunctionInstruction.Instance); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(_parentContext); compiler.Instructions.Emit(GetGlobalContextInstruction.Instance); }
public void AddInstructions(LightCompiler compiler) { compiler.Compile(_value); compiler.Instructions.Emit(new PythonSetGlobalInstruction(_global.Global)); }