本文整理汇总了C#中CodeBlock.Lookup方法的典型用法代码示例。如果您正苦于以下问题:C# CodeBlock.Lookup方法的具体用法?C# CodeBlock.Lookup怎么用?C# CodeBlock.Lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeBlock
的用法示例。
在下文中一共展示了CodeBlock.Lookup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public override Expression Generate(object args, CodeBlock cb)
{
SymbolId s = (SymbolId)Builtins.First(args);
assigns[s] = true;
if (libraryglobals.ContainsKey(s))
{
libraryglobals.Remove(s);
}
if (libraryglobalsN.ContainsKey(s))
{
libraryglobalsN.Remove(s);
}
if (libraryglobalsX.ContainsKey(s))
{
libraryglobalsX.Remove(s);
}
setstack.Push(s);
NameHint = Builtins.UnGenSymInternal(s);
var prevvh = VarHint;
VarHint = s;
Expression value = GetAst(Builtins.Second(args), cb);
VarHint = prevvh;
setstack.Pop();
NameHint = SymbolId.Invalid;
Variable v = cb.Lookup(s);
Statement r = null;
if (v == null)
{
r = Ast.Statement(Ast.SimpleCallHelper(SetSymbolValue, Ast.Constant(s), value));
}
else
{
//Trace.Assert(cb.Parent != null);
value = Ast.ConvertHelper(value, v.Type);
r = Ast.Write(v, value);
}
if (SpanHint != SourceSpan.Invalid || SpanHint != SourceSpan.None)
{
r.SetLoc(SpanHint);
}
return Ast.Void(r);
}
示例2: GetAst
protected internal static Expression GetAst(object args, CodeBlock cb, bool istailposition)
{
if (args is Annotation)
{
args = ((Annotation)args).stripped;
}
Cons c = args as Cons;
if (c != null)
{
if (c.car is SymbolId)
{
SymbolId f = (SymbolId)c.car;
Variable var = cb.Lookup(f);
if (var != null && !assigns.ContainsKey(f))
{
var = null;
}
object m;
#if OPTIMIZATIONS
#if !BLAH
CodeBlockExpression cbe;
//// needs to do the same for overloads...
if (SimpleGenerator.libraryglobals.TryGetValue(f, out cbe))
{
Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);
if (cbe.Block.ParameterCount < 9 && cbe.Block.ParameterCount == ppp.Length)
{
//inline here? we could for simple bodies, but we need to copy the entire structure
if (!(cbe.Block.HasEnvironment || cbe.Block.IsClosure))
{
if (cbe.Block.Body is ReturnStatement)
{
ReturnStatement rs = (ReturnStatement)cbe.Block.Body;
if (!ScriptDomainManager.Options.DebugMode &&
!ScriptDomainManager.Options.LightweightDebugging &&
!cb.IsGlobal && IsSimpleExpression(rs.Expression))
{
return InlineCall(cb, Ast.CodeBlockExpression(RewriteBody(cbe.Block), false, cbe.IsStronglyTyped), ppp);
}
}
}
if (cbe.Block != cb.Parent && cbe.Block != cb) // do TCE later
{
return CallNormal(cbe, ppp);
}
}
}
// varargs
if (SimpleGenerator.libraryglobalsX.TryGetValue(f, out cbe))
{
Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);
if (cbe.Block.ParameterCount < 9 && cbe.Block.ParameterCount - 1 <= ppp.Length)
{
//inline here?
return CallVarArgs(cbe, ppp);
}
}
// overloads
CodeBlockDescriptor[] cbd;
if (SimpleGenerator.libraryglobalsN.TryGetValue(f, out cbd))
{
Expression[] ppp = GetAstListNoCast(c.cdr as Cons, cb);
foreach (CodeBlockDescriptor d in cbd)
{
if (d.codeblock.Block.ParameterCount < 9)
{
if (ppp.Length == d.arity || (d.varargs && ppp.Length > d.arity))
{
if (d.varargs)
{
//inline here?
return CallVarArgs(d.codeblock, ppp);
}
else
{
//inline here?
//if (d.codeblock.Block != cb.Parent && d.codeblock.Block != cb) // do TCE later, not yet
{
return CallNormal(d.codeblock, ppp);
}
}
}
}
}
}
#endif
//.........这里部分代码省略.........
示例3: RewriteExpression
static Expression RewriteExpression(CodeBlock cb, Expression e)
{
if (e is MethodCallExpression)
{
MethodCallExpression mce = (MethodCallExpression)e;
List<Expression> args = new List<Expression>();
foreach (var arg in mce.Arguments)
{
args.Add(RewriteExpression(cb, arg));
}
return Ast.Call(RewriteExpression(cb, mce.Instance), mce.Method, args.ToArray());
}
if (e is BoundExpression)
{
BoundExpression be = (BoundExpression)e;
return Ast.Read(cb.Lookup(be.Variable.Name));
}
if (e is BinaryExpression)
{
BinaryExpression be = (BinaryExpression)e;
return new BinaryExpression(be.NodeType, RewriteExpression(cb, be.Left), RewriteExpression(cb, be.Right));
}
if (e is UnaryExpression)
{
UnaryExpression ue = (UnaryExpression)e;
if (ue.NodeType == AstNodeType.Convert)
{
return Ast.ConvertHelper(RewriteExpression(cb, ue.Operand), ue.Type);
}
return null;
}
if (e is TypeBinaryExpression)
{
TypeBinaryExpression tbe = (TypeBinaryExpression)e;
return Ast.TypeIs(RewriteExpression(cb, tbe.Expression), tbe.TypeOperand);
}
if (e is ConditionalExpression)
{
ConditionalExpression ce = (ConditionalExpression)e;
return Ast.Condition(RewriteExpression(cb, ce.Test), RewriteExpression(cb, ce.IfTrue), RewriteExpression(cb, ce.IfFalse));
}
return e;
}
示例4: Read
static Expression Read(SymbolId name, CodeBlock cb, Type type)
{
SymbolId sname = name;
Variable v = cb.Lookup(sname);
if (v == null)
{
if (assigns.ContainsKey(sname))
{
return Ast.Read(sname);
}
else
{
CodeBlock tl = GetTopLevel(cb);
v = tl.CreateVariable(sname, Variable.VariableKind.Global, typeof(object), Ast.Read(sname));
return Ast.Read(v);
}
}
return Ast.ReadDefined(v);
}