本文整理汇总了C#中IEnvironment.Lookup方法的典型用法代码示例。如果您正苦于以下问题:C# IEnvironment.Lookup方法的具体用法?C# IEnvironment.Lookup怎么用?C# IEnvironment.Lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnvironment
的用法示例。
在下文中一共展示了IEnvironment.Lookup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Analyze
public IExpression Analyze(Object expr, IEnvironment env, Location enclosingLoc)
{
Symbol symbol = expr as Symbol;
if (symbol != null) {
if (symbol.IsDynamic)
return new DynamicVar(symbol);
Object var = env.Lookup(symbol);
if (var is LocalVariable)
return new LocalVar((LocalVariable)var);
else
return new GlobalVar((Symbol)var);
}
if (!(expr is Cons)) //must be literal
return new QuoteExpr(expr);
Cons exprs = (Cons)expr;
Location loc = (Location)InnerReader.LocationTable[expr];
if (loc != null)
InnerReader.LocationTable.Remove(expr);
else
loc = enclosingLoc;
Object f = exprs.First;
Cons args = exprs.Rest;
//see if it's a macro
Symbol s = f as Symbol;
if (s != null && s.IsDefined && s.GlobalValue is Macro) {
Macro m = (Macro)s.GlobalValue;
Object[] argarray = Cons.ToVector(args);
Object mexprs = null;
try {
mexprs = m.Invoke(argarray);
} catch (Exception ex) {
BacktraceFrame frame = new BacktraceFrame(loc, s, args);
throw BacktraceException.Push(ex, frame, this);
}
try {
return Analyze(mexprs, env, loc);
} catch (Exception ex) {
BacktraceFrame frame = new BacktraceFrame(loc, "when expanding ", exprs);
throw BacktraceException.Push(ex, frame, this);
}
}
Int32 numargs = Cons.GetLength(args);
if (f == DLET)
return new DynamicLet(args, env, this, loc);
else if (f == FN)
return new Closure(args, env, this, loc);
else if (f == MACRO)
return new Macro(args, env, this, loc);
else if (f == WHILE)
return new WhileExpression(args, env, this, loc);
else if (f == BLOCK) {
if (numargs == 0)
return new QuoteExpr(null);
//remove block from block of one
else if (numargs == 1)
return Analyze(args.First, env, loc);
else
return new BlockExpression(args, env, this, loc);
} else if (f == OR) {
if (numargs == 0)
return new QuoteExpr(null);
else
return new OrExpression(args, env, this, loc);
} else if (f == IF)
return new IfExpression(args, env, this, loc);
else if (f == QUOTE)
return new QuoteExpr(args.First);
else if (f == SET)
return new SetExpression(args, env, this, loc);
else //presume funcall
return new ApplyExpression(exprs, env, this, loc);
}