本文整理汇总了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);
}
示例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
);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例7: Resolve
string Resolve(string variableName, PythonAst ast)
{
typeName = null;
this.variableName = variableName;
ast.Walk(this);
return typeName;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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
);
}
示例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;
}
示例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 }
);
}
示例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);
}