当前位置: 首页>>代码示例>>C#>>正文


C# Ast.PythonAst类代码示例

本文整理汇总了C#中IronPython.Compiler.Ast.PythonAst的典型用法代码示例。如果您正苦于以下问题:C# PythonAst类的具体用法?C# PythonAst怎么用?C# PythonAst使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PythonAst类属于IronPython.Compiler.Ast命名空间,在下文中一共展示了PythonAst类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ lambda, CompilerContext/*!*/ compilerContext, PythonAst/*!*/ ast) {
            PythonContext context = (PythonContext)compilerContext.SourceUnit.LanguageContext;

            Type t = _typeGen.FinishType();
#if SILVERLIGHT
            _finalType.Value = t;
#endif

            // create the CodeContext for this optimized module
            InitOptimizedCodeContext(t);
            t.GetField("__global_context").SetValue(null, _context);

            // publish the cached constants
            foreach (var ci in _constants) {
                FieldInfo fi = t.GetField(ci.Value.Field.Name);
                fi.SetValue(null, ci.Key);
            }

            // publish all of the call site instances
            foreach (SiteInfo si in _sites) {
                FieldInfo fi = t.GetField(si.Field.Name);

                fi.SetValue(null, CallSite.Create(si.DelegateType, si.Binder));
            }

            // initialize all of the cached symbol IDs.
            ScriptingRuntimeHelpers.InitializeSymbols(t);

            string name = ((PythonCompilerOptions)compilerContext.Options).ModuleName ?? "<unnamed>";
            var func = Ast.Lambda<Func<object>>(lambda, name, new MSAst.ParameterExpression[0]);
            return new RuntimeScriptCode(compilerContext, func, ast, _context);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:32,代码来源:StaticGlobalAllocator.cs

示例2: ReduceAst

 public override MSAst.LambdaExpression ReduceAst(PythonAst instance, string name) {
     return Ast.Lambda<Func<CodeContext, FunctionCode, object>>(
         AstUtils.Convert(instance.ReduceWorker(), typeof(object)),
         name,
         PythonAst._arrayFuncParams
     );
 }
开发者ID:BenHall,项目名称:ironruby,代码行数:7,代码来源:LookupCompilationMode.cs

示例3: RuntimeScriptCode

 public RuntimeScriptCode(CompilerContext/*!*/ context, MSAst.Expression<Func<object>>/*!*/ expression, PythonAst/*!*/ ast, CodeContext/*!*/ codeContext)
     : base(context.SourceUnit) {
     _code = expression;
     _ast = ast;
     _context = context;
     _optimizedContext = codeContext;
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:RuntimeScriptCode.cs

示例4: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {            
            MSAst.Expression finalBody = Ast.Block(
                new[] { _globalCtx },
                Ast.Assign(
                    _globalCtx,
                    Ast.Call(typeof(PythonOps).GetMethod("CreateTopLevelCodeContext"),
                        _globalScope,
                        _language
                    )
                ),
                body
            );

            PythonCompilerOptions pco = ((PythonCompilerOptions)context.Options);
            string name = pco.ModuleName ?? "<unnamed>";
            var lambda = Ast.Lambda<Func<Scope, LanguageContext, object>>(
                finalBody, 
                name,
                new[] { _globalScope, _language } 
            );


            Func<Scope, LanguageContext, object> func;
            // TODO: adaptive compilation should be eanbled
            /*PythonContext pc = (PythonContext)context.SourceUnit.LanguageContext;
            if (pc.ShouldInterpret(pco, context.SourceUnit)) {
                func = CompilerHelpers.LightCompile(lambda);
            } else*/ {
                func = lambda.Compile(context.SourceUnit.EmitDebugSymbols);
            }

            return new PythonScriptCode(func, context.SourceUnit);
        }
开发者ID:toddb,项目名称:ironruby,代码行数:33,代码来源:DictionaryGlobalAllocator.cs

示例5: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
            PythonCompilerOptions pco = ((PythonCompilerOptions)context.Options);
            PythonContext pc = (PythonContext)context.SourceUnit.LanguageContext;

            if (body is MSAst.ConstantExpression) {
                object value = ((MSAst.ConstantExpression)body).Value;
                return new PythonScriptCode(codeCtx => value, context.SourceUnit);
            }

            var lambda = Ast.Lambda<Func<CodeContext, object>>(
                Utils.Convert(body, typeof(object)),
                pco.ModuleName ?? "<unnamed>",
                ArrayGlobalAllocator._globalContextList
            );

            Func<CodeContext, object> func;

            if (pc.ShouldInterpret(pco, context.SourceUnit)) {
                func = CompilerHelpers.LightCompile(lambda);
            } else {
                func = lambda.Compile(context.SourceUnit.EmitDebugSymbols);
            }

            return new PythonScriptCode(func, context.SourceUnit);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:25,代码来源:DictionaryGlobalAllocator.cs

示例6: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
            // create the CodeContext
            PythonGlobal[] globalArray = new PythonGlobal[_globals.Count];

            // now fill in the dictionary and create the array
            foreach (var global in _globals) {
                SymbolId globalName = SymbolTable.StringToId(global.Key);
                
                globalArray[global.Value.Index] = _globalVals[globalName];
            }
            
            _array.Array = globalArray;

            // finally build the funcion that's closed over the array and
            string name = ((PythonCompilerOptions)context.Options).ModuleName ?? "<unnamed>";
            var func = Ast.Lambda<Func<object>>(
                Ast.Block(
                    new[] { _globalArray, _globalContext },
                    Ast.Assign(_globalArray, Ast.Constant(globalArray)),
                    Ast.Assign(_globalContext, Ast.Constant(_context)),
                    body
                ),
                name,
                new MSAst.ParameterExpression[0]
            );

            return new RuntimeScriptCode(context, func, ast, _context);
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:28,代码来源:ArrayGlobalAllocator.cs

示例7: Resolve

		string Resolve(string variableName, PythonAst ast)
		{
			typeName = null;
			this.variableName = variableName;
			ast.Walk(this);
			return typeName;
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:7,代码来源:PythonLocalVariableResolver.cs

示例8: RuntimeScriptCode

        public RuntimeScriptCode(PythonAst/*!*/ ast, CodeContext/*!*/ codeContext)
            : base(ast) {
            Debug.Assert(codeContext.GlobalScope.GetExtension(codeContext.LanguageContext.ContextId) != null);
            Debug.Assert(ast.Type == typeof(MSAst.Expression<Func<FunctionCode, object>>));

            _optimizedContext = codeContext;
        }
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:RuntimeScriptCode.cs

示例9: MakeScriptCode

        public override ScriptCode MakeScriptCode(PythonAst ast) {
            PythonCompilerOptions pco = ast.CompilerContext.Options as PythonCompilerOptions;
            // reduce to LightLambda then to Lambda
            var code = (MSAst.Expression<LookupCompilationDelegate>)ast.Reduce().Reduce();

            return new PythonSavableScriptCode(code, ast.SourceUnit, ast.GetNames(), pco.ModuleName);
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:7,代码来源:ToDiskCompilationMode.cs

示例10: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast) {
            MSAst.ParameterExpression scope = Ast.Parameter(typeof(Scope), "$scope");
            MSAst.ParameterExpression language = Ast.Parameter(typeof(LanguageContext), "$language ");

            // finally build the funcion that's closed over the array and
            var func = Ast.Lambda<Func<Scope, LanguageContext, object>>(
                Ast.Block(
                    new[] { GlobalArray },
                    Ast.Assign(
                        GlobalArray, 
                        Ast.Call(
                            null,
                            typeof(PythonOps).GetMethod("GetGlobalArray"),
                            scope
                        )
                    ),
                    Utils.Convert(body, typeof(object))
                ),
                ((PythonCompilerOptions)context.Options).ModuleName,
                new MSAst.ParameterExpression[] { scope, language }
            );

            PythonCompilerOptions pco = context.Options as PythonCompilerOptions;

            return new SavableScriptCode(func, context.SourceUnit, GetNames(), pco.ModuleName);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:26,代码来源:SavableGlobalAllocator.cs

示例11: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast, Dictionary<int, bool> handlerLocations, Dictionary<int, Dictionary<int, bool>> loopAndFinallyLocations) {
            // create the CodeContext
            PythonGlobal[] globalArray = new PythonGlobal[_globals.Count];

            // now fill in the dictionary and create the array
            foreach (var global in _globals) {
                globalArray[global.Value.Index] = _globalVals[global.Key];
            }
            
            _array.Array = globalArray;

            // finally build the funcion that's closed over the array and
            string name = ((PythonCompilerOptions)context.Options).ModuleName ?? "<unnamed>";
            var func = Ast.Lambda<Func<FunctionCode, object>>(
                Ast.Block(
                    new[] { _globalArray, _globalContext },
                    Ast.Assign(_globalArray, Ast.Constant(globalArray)),
                    Ast.Assign(_globalContext, Ast.Constant(_context)),
                    Utils.Convert(body, typeof(object))
                ),
                name,
                new [] { AstGenerator._functionCode }
            );

            return new RuntimeScriptCode(context, func, ast, _context);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:26,代码来源:ArrayGlobalAllocator.cs

示例12: ReduceAst

 public override LightLambdaExpression ReduceAst(PythonAst instance, string name) {
     return Utils.LightLambda<LookupCompilationDelegate>(
         typeof(object),
         AstUtils.Convert(instance.ReduceWorker(), typeof(object)),
         name,
         PythonAst._arrayFuncParams
     );
 }
开发者ID:jschementi,项目名称:iron,代码行数:8,代码来源:LookupCompilationMode.cs

示例13: RuntimeScriptCode

        public RuntimeScriptCode(CompilerContext/*!*/ context, MSAst.Expression<Func<FunctionCode, object>>/*!*/ expression, PythonAst/*!*/ ast, CodeContext/*!*/ codeContext)
            : base(context.SourceUnit) {
            Debug.Assert(codeContext.GlobalScope.GetExtension(codeContext.LanguageContext.ContextId) != null);

            _code = expression;
            _ast = ast;
            _context = context;
            _optimizedContext = codeContext;
        }
开发者ID:techarch,项目名称:ironruby,代码行数:9,代码来源:RuntimeScriptCode.cs

示例14: ReduceAst

 public override MSAst.LambdaExpression ReduceAst(PythonAst instance, string name) {
     return Ast.Lambda<Func<FunctionCode, object>>(
             Ast.Block(
                 new[] { PythonAst._globalArray, PythonAst._globalContext },
                 Ast.Assign(PythonAst._globalArray, instance.GlobalArrayInstance),
                 Ast.Assign(PythonAst._globalContext, Ast.Constant(instance.ModuleContext.GlobalContext)),
                 AstUtils.Convert(instance.ReduceWorker(), typeof(object))
             ),
             name,
             new[] { PythonAst._functionCode }
         );
 }
开发者ID:BenHall,项目名称:ironruby,代码行数:12,代码来源:CollectableCompilationMode.cs

示例15: MakeScriptCode

        public override ScriptCode/*!*/ MakeScriptCode(MSAst.Expression/*!*/ body, CompilerContext/*!*/ context, PythonAst/*!*/ ast, Dictionary<int, bool> handlerLocations, Dictionary<int, Dictionary<int, bool>> loopAndFinallyLocations) {
            PythonCompilerOptions pco = ((PythonCompilerOptions)context.Options);
            PythonContext pc = (PythonContext)context.SourceUnit.LanguageContext;

            var lambda = Ast.Lambda<Func<CodeContext, FunctionCode, object>>(
                Utils.Convert(body, typeof(object)),
                pco.ModuleName ?? "<unnamed>",
                ArrayGlobalAllocator._arrayFuncParams
            );

            return new PythonScriptCode(context, lambda, context.SourceUnit, handlerLocations, loopAndFinallyLocations, ast.Body.Span);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:12,代码来源:DictionaryGlobalAllocator.cs


注:本文中的IronPython.Compiler.Ast.PythonAst类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。