public ClosureExpression(Ast.TotemVariable/*!*/ variable, Expression/*!*/ closureCell, ParameterExpression parameter) { Assert.NotNull(closureCell); _variable = variable; _closureCell = closureCell; _parameter = parameter; }
public override MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global) { return new LookupGlobalVariable( globalContext, variable.Name, variable.Kind == VariableKind.Local ); }
public override MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global) { Assert.NotNull(global); return new TotemGlobalVariableExpression( Ast.ArrayIndex( TotemAst._globalArray, Ast.Constant(arrayIndex) ), variable, global ); }
public FunctionDefinition(string name, Parameter/*!*/[]/*!*/ parameters, Statement body) { ContractUtils.RequiresNotNullItems(parameters, "parameters"); if (name == null) { _name = "<lambda$" + Interlocked.Increment(ref _lambdaId) + ">"; _isLambda = true; } else { _name = name; } _parameters = parameters; _body = body; _argsVariable = new TotemVariable("arguments", VariableKind.Parameter, this); }
public abstract MSAst.Expression GetGlobal(MSAst.Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global);
internal override bool ExposesLocalVariable(TotemVariable variable) { return NeedsLocalsDictionary; }
private bool TryGetAnyVariable(string name, out TotemVariable variable) { if (_variables != null) { return _variables.TryGetValue(name, out variable); } else { variable = null; return false; } }
public ClosureInfo(TotemVariable variable, bool accessedInScope) { Variable = variable; AccessedInScope = accessedInScope; }
internal bool TryGetVariable(string name, out TotemVariable variable) { if (TryGetAnyVariable(name, out variable)) { return true; } else { variable = null; return false; } }
private static bool HasClosureVariable(List<ClosureInfo> closureVariables, TotemVariable variable) { if (closureVariables == null) { return false; } for (int i = 0; i < closureVariables.Count; i++) { if (closureVariables[i].Variable == variable) { return true; } } return false; }
internal virtual MSAst.Expression GetVariableExpression(TotemVariable variable) { if (variable.IsGlobal) { return GlobalParent.ModuleVariables[variable]; } Debug.Assert(_variableMapping.ContainsKey(variable)); return _variableMapping[variable]; }
public TotemGlobalVariableExpression(Expression/*!*/ globalExpr, Ast.TotemVariable/*!*/ variable, TotemGlobal/*!*/ global, bool lightEh) { Assert.NotNull(globalExpr, variable); _target = globalExpr; _global = global; _variable = variable; _lightEh = lightEh; }
//internal TotemReference Reference(string name) //{ // if (_references == null) // { // _references = new Dictionary<string, TotemReference>(StringComparer.Ordinal); // } // TotemReference reference; // if (!_references.TryGetValue(name, out reference)) // { // _references[name] = reference = new TotemReference(name); // } // return reference; //} //internal bool IsReferenced(string name) //{ // TotemReference reference; // return _references != null && _references.TryGetValue(name, out reference); //} internal TotemVariable CreateVariable(string name, VariableKind kind) { EnsureVariables(); Debug.Assert(!_variables.ContainsKey(name)); TotemVariable variable; _variables[name] = variable = new TotemVariable(name, kind, this); return variable; }
internal override bool ExposesLocalVariable(TotemVariable variable) { return true; }
internal void AddGlobalVariable(TotemVariable variable) { EnsureVariables(); _variables[variable.Name] = variable; }
internal void AddFreeVariable(TotemVariable variable, bool accessedInScope) { if (_freeVars == null) { _freeVars = new List<TotemVariable>(); } if (!_freeVars.Contains(variable)) { _freeVars.Add(variable); } }
internal void AddCellVariable(TotemVariable variable) { if (_cellVars == null) { _cellVars = new List<string>(); } if (!_cellVars.Contains(variable.Name)) { _cellVars.Add(variable.Name); } }
internal override bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable) { // Functions expose their locals to direct access ContainsNestedFreeVariables = true; if (TryGetVariable(name, out variable)) { variable.AccessedInNestedScope = true; if (variable.Kind == VariableKind.Local || variable.Kind == VariableKind.Parameter) { from.AddFreeVariable(variable, true); for (ScopeStatement scope = from.Parent; scope != this; scope = scope.Parent) { scope.AddFreeVariable(variable, false); } AddCellVariable(variable); } else { from.AddReferencedGlobal(name); } return true; } return false; }
internal virtual bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable) { // Hide scope contents by default (only functions expose their locals) variable = null; return false; }
internal abstract bool ExposesLocalVariable(TotemVariable variable);
internal override bool TryBindOuter(ScopeStatement from, string name, out TotemVariable variable) { // Unbound variable from.AddReferencedGlobal(name); if (from.HasLateBoundVariableSets) { // If the context contains unqualified exec, new locals can be introduced // Therefore we need to turn this into a fully late-bound lookup which // happens when we don't have a PythonVariable. variable = null; return false; } else { // Create a global variable to bind to. variable = EnsureGlobalVariable(name); return true; } }