本文整理汇总了C#中CodeContext类的典型用法代码示例。如果您正苦于以下问题:C# CodeContext类的具体用法?C# CodeContext怎么用?C# CodeContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeContext类属于命名空间,在下文中一共展示了CodeContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public override object Build(CodeContext context, object[] args) {
SymbolDictionary res = new SymbolDictionary();
for (int i = _argIndex; i < _argIndex + _names.Length; i++) {
res.Add(_names[i - _argIndex], args[i]);
}
return res;
}
示例2: 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;
}
示例3: PythonDynamicStackFrame
public PythonDynamicStackFrame(CodeContext/*!*/ context, FunctionCode/*!*/ funcCode, int line)
: base(GetMethod(context, funcCode), funcCode.co_name, funcCode.co_filename, line) {
Assert.NotNull(context, funcCode);
_context = context;
_code = funcCode;
}
示例4: field_size_limit
public static int field_size_limit(CodeContext /*!*/ context, int new_limit)
{
PythonContext ctx = PythonContext.GetContext(context);
int old_limit = (int)ctx.GetModuleState(_fieldSizeLimitKey);
ctx.SetModuleState(_fieldSizeLimitKey, new_limit);
return old_limit;
}
示例5: Import
/// <summary>
/// Gateway into importing ... called from Ops. Performs the initial import of
/// a module and returns the module.
/// </summary>
public static object Import(CodeContext/*!*/ context, string fullName, PythonTuple from, int level) {
PythonContext pc = PythonContext.GetContext(context);
if (level == -1) {
// no specific level provided, call the 4 param version so legacy code continues to work
return pc.OldImportSite.Target(
pc.OldImportSite,
context,
FindImportFunction(context),
fullName,
Builtin.globals(context),
context.Dict,
from
);
}
// relative import or absolute import, in other words:
//
// from . import xyz
// or
// from __future__ import absolute_import
return pc.ImportSite.Target(
pc.ImportSite,
context,
FindImportFunction(context),
fullName,
Builtin.globals(context),
context.Dict,
from,
level
);
}
示例6: proxy
public static object proxy(CodeContext context, object @object, object callback) {
if (PythonOps.IsCallable(context, @object)) {
return weakcallableproxy.MakeNew(context, @object, callback);
} else {
return weakproxy.MakeNew(context, @object, callback);
}
}
示例7: load_module
public static object load_module(CodeContext/*!*/ context, string name, PythonFile file, string filename, PythonTuple/*!*/ description) {
if (description == null) {
throw PythonOps.TypeError("load_module() argument 4 must be 3-item sequence, not None");
}
if (description.__len__() != 3) {
throw PythonOps.TypeError("load_module() argument 4 must be sequence of length 3, not {0}", description.__len__());
}
PythonContext pythonContext = PythonContext.GetContext(context);
// already loaded? do reload()
PythonModule module = pythonContext.GetModuleByName(name);
if (module != null) {
Importer.ReloadModule(context, module.Scope);
return module.Scope;
}
int type = PythonContext.GetContext(context).ConvertToInt32(description[2]);
switch (type) {
case PythonSource:
return LoadPythonSource(pythonContext, name, file, filename);
case CBuiltin:
return LoadBuiltinModule(context, name);
case PackageDirectory:
return LoadPackageDirectory(pythonContext, name, filename);
default:
throw PythonOps.TypeError("don't know how to import {0}, (type code {1}", name, type);
}
}
示例8: CreatePipe
public static PythonTuple CreatePipe(
CodeContext context,
object pSec /*Python passes None*/,
int bufferSize) {
IntPtr hReadPipe;
IntPtr hWritePipe;
SECURITY_ATTRIBUTES pSecA = new SECURITY_ATTRIBUTES();
pSecA.nLength = Marshal.SizeOf(pSecA);
if (pSec != null) {
/* If pSec paseed in from Python is not NULL
* there needs to be some conversion done here...*/
}
// TODO: handle failures
CreatePipePI(
out hReadPipe,
out hWritePipe,
ref pSecA,
(uint)bufferSize);
return PythonTuple.MakeTuple(
new PythonSubprocessHandle(hReadPipe),
new PythonSubprocessHandle(hWritePipe)
);
}
示例9: Call
public static object Call(CodeContext/*!*/ context, TypeGroup/*!*/ self, params object[] args) {
return PythonCalls.Call(
context,
DynamicHelpers.GetPythonTypeFromType(self.NonGenericType),
args ?? ArrayUtils.EmptyObjects
);
}
示例10: StringFormatter
public StringFormatter(CodeContext/*!*/ context, string str, object data, bool isUnicode)
{
_str = str;
_data = data;
_context = context;
_isUnicodeString = isUnicode;
}
示例11: _FileIO
public _FileIO(CodeContext/*!*/ context, int fd, [DefaultParameterValue("r")]string mode, [DefaultParameterValue(true)]bool closefd) {
if (fd < 0) {
throw PythonOps.ValueError("fd must be >= 0");
}
PythonContext pc = PythonContext.GetContext(context);
_FileIO file = (_FileIO)pc.FileManager.GetObjectFromId(pc, fd);
Console.WriteLine(file);
_context = pc;
switch (mode) {
case "r": _mode = "rb"; break;
case "w": _mode = "wb"; break;
case "a": _mode = "w"; break;
case "r+":
case "+r": _mode = "rb+"; break;
case "w+":
case "+w": _mode = "rb+"; break;
case "a+":
case "+a": _mode = "r+"; break;
default:
BadMode(mode);
break;
}
_readStream = file._readStream;
_writeStream = file._writeStream;
_closefd = closefd;
}
示例12: LuaScriptCode
public LuaScriptCode(CodeContext context, SourceUnit sourceUnit, Expression<Func<IDynamicMetaObjectProvider, dynamic>> chunk)
: base(sourceUnit)
{
Contract.Requires(chunk != null);
Context = context;
_exprLambda = chunk;
}
示例13: PrintExpressionValue
/// <summary>
/// Called from generated code when we are supposed to print an expression value
/// </summary>
public static void PrintExpressionValue(CodeContext/*!*/ context, object value)
{
Console.WriteLine(value);
//PythonContext pc = PythonContext.GetContext(context);
//object dispHook = pc.GetSystemStateValue("displayhook");
//pc.CallWithContext(context, dispHook, value);
}
示例14: __init__
public void __init__(CodeContext context,
string filename,
[DefaultParameterValue("r")]string mode,
[DefaultParameterValue(0)]int buffering,
[DefaultParameterValue(DEFAULT_COMPRESSLEVEL)]int compresslevel) {
var pythonContext = PythonContext.GetContext(context);
this.buffering = buffering;
this.compresslevel = compresslevel;
if (!mode.Contains("b") && !mode.Contains("U")) {
// bz2 files are always written in binary mode, unless they are in univeral newline mode
mode = mode + 'b';
}
if (mode.Contains("w")) {
var underlyingStream = File.Open(filename, FileMode.Create, FileAccess.Write);
if (mode.Contains("p")) {
this.bz2Stream = new ParallelBZip2OutputStream(underlyingStream);
} else {
this.bz2Stream = new BZip2OutputStream(underlyingStream);
}
} else {
this.bz2Stream = new BZip2InputStream(File.OpenRead(filename));
}
this.__init__(bz2Stream, pythonContext.DefaultEncoding, filename, mode);
}
示例15: Error
private static Exception Error(CodeContext/*!*/ context, int errno, string/*!*/ message) {
return PythonExceptions.CreateThrowable(
(PythonType)PythonContext.GetContext(context).GetModuleState(_mmapErrorKey),
errno,
message
);
}