public void AddInstructions(LightCompiler compiler)
 {
     compiler.Instructions.Emit(_Instruction.Instance);
 }
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_value);
     compiler.Instructions.Emit(new PythonSetGlobalInstruction(_global.Global));
 }
Example #3
0
        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());
        }
Example #4
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_parentContext);
     compiler.Instructions.Emit(GetGlobalContextInstruction.Instance);
 }
Example #5
0
 public virtual object GetDebugCookie(LightCompiler compiler) => null;
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(Expression.TryFault(_body, _fault));
 }
 internal BranchLabel GetLabel(LightCompiler compiler)
 {
     EnsureLabel(compiler);
     return(_label);
 }
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_target);
     compiler.Compile(_codeContext);
     compiler.Instructions.Emit(new GetMemberInstruction(_binder));
 }
Example #9
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Instructions.Emit(MakeClosureCellInstruction.Instance);
 }
Example #10
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Instructions.EmitLoad(Context);
 }
Example #11
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_lastValue);
     compiler.Instructions.Emit(IsLightExceptionInstruction.Instance);
 }
Example #12
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(FunctionDefinition._functionParam);
     compiler.Instructions.Emit(GetParentContextFromFunctionInstruction.Instance);
 }
Example #13
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_test);
     compiler.Instructions.EmitLoad(_bindingInfo);
     compiler.Instructions.EmitCall(InterpretedCallSiteTest);
 }
 void IInstructionProvider.AddInstructions(LightCompiler compiler)
 {
     compiler.Compile(_codeContextExpr);
     compiler.Instructions.Emit(new LookupGlobalInstruction(_name, _isLocal, _lightThrow));
 }
Example #15
0
 public void AddInstructions(LightCompiler compiler)
 {
     compiler.Instructions.EmitLoad(_value);
 }
        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.Kind == ParameterKind.Normal && param.DefaultValue != null)
                {
                    compiler.Compile(AstUtils.Convert(param.DefaultValue, typeof(object)));
                    defaultCount++;
                }
            }

            // emit kwdefaults
            int kwdefaultCount = 0;

            for (int i = _parameters.Length - 1; i >= 0; i--)
            {
                var param = _parameters[i];
                if (param.Kind == ParameterKind.KeywordOnly && param.DefaultValue != null)
                {
                    compiler.Compile(AstUtils.Convert(param.DefaultValue, typeof(object)));
                    compiler.Compile(AstUtils.Constant(param.Name, typeof(string)));
                    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, kwdefaultCount, annotationCount, globalName));
        }
Example #17
0
 public virtual object GetDebugCookie(LightCompiler compiler)
 {
     return(null);
 }
Example #18
0
 public void AddInstructions(LightCompiler compiler) {
     compiler.Compile(Expression.TryFault(_body, _fault));
 }
Example #19
0
 void IInstructionProvider.AddInstructions(LightCompiler compiler)
 {
     // optimizing bool conversions does no good in the light compiler
     compiler.Compile(ReduceWorker(false));
 }
Example #20
0
 public virtual object GetDebugCookie(LightCompiler compiler)
 {
     return null;
 }
Example #21
0
        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());
        }