internal override TotemVariable BindVariable(TotemNameBinder binder, string name) { TotemVariable variable; if (name == "arguments") { return ArgumentsVariable; } // First try variables local to this scope if (TryGetVariable(name, out variable)) { if (variable.Kind == VariableKind.Global) { AddReferencedGlobal(name); } return variable; } // Try to bind in outer scopes for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent) { if (parent.TryBindOuter(this, name, out variable)) { return variable; } } return null; }
internal override void FinishBind(TotemNameBinder binder) { _variableMapping[ArgumentsVariable] = _argumentsParam; foreach (var param in _parameters) { _variableMapping[param.TotemVariable] = param.FinishBind(NeedsLocalsDictionary); } base.FinishBind(binder); }
public ParameterBinder(TotemNameBinder binder) { _binder = binder; }
internal override void Bind(TotemNameBinder binder) { base.Bind(binder); if (((TotemContext)binder.Context.SourceUnit.LanguageContext).TotemOptions.FullFrames) { // force a dictionary if we have enabled full frames for sys._getframe support NeedsLocalsDictionary = true; } }
public DefineBinder(TotemNameBinder binder) { _binder = binder; }
internal static void BindAst(TotemAst ast, CompilerContext context) { Assert.NotNull(ast, context); TotemNameBinder binder = new TotemNameBinder(context); binder.Bind(ast); }
internal virtual void FinishBind(TotemNameBinder binder) { List<ClosureInfo> closureVariables = null; if (FreeVariables != null && FreeVariables.Count > 0) { _localParentTuple = Ast.Parameter(Parent.GetClosureTupleType(), "$tuple"); foreach (var variable in _freeVars) { var parentClosure = Parent._closureVariables; Debug.Assert(parentClosure != null); for (int i = 0; i < parentClosure.Length; i++) { if (parentClosure[i].Variable == variable) { _variableMapping[variable] = new ClosureExpression(variable, Ast.Property(_localParentTuple, String.Format("Item{0:D3}", i)), null); break; } } Debug.Assert(_variableMapping.ContainsKey(variable)); if (closureVariables == null) { closureVariables = new List<ClosureInfo>(); } closureVariables.Add(new ClosureInfo(variable, true)); } } if (Variables != null) { foreach (TotemVariable variable in Variables.Values) { if (!HasClosureVariable(closureVariables, variable) && !variable.IsGlobal && (variable.AccessedInNestedScope || ExposesLocalVariable(variable))) { if (closureVariables == null) { closureVariables = new List<ClosureInfo>(); } closureVariables.Add(new ClosureInfo(variable, true)); } if (variable.Kind == VariableKind.Local) { Debug.Assert(variable.Scope == this); if (variable.AccessedInNestedScope || ExposesLocalVariable(variable)) { _variableMapping[variable] = new ClosureExpression(variable, Ast.Parameter(typeof(ClosureCell), variable.Name), null); } else { _variableMapping[variable] = Ast.Parameter(typeof(object), variable.Name); } } } } if (closureVariables != null) { _closureVariables = closureVariables.ToArray(); } }
internal abstract TotemVariable BindVariable(TotemNameBinder binder, string name);
internal virtual void Bind(TotemNameBinder binder) { //if (_references != null) //{ // foreach (var reference in _references.Values) // { // TotemVariable variable; // reference.TotemVariable = variable = BindVariable(binder, reference); // // Accessing outer scope variable which is being deleted? // if (variable != null) // { // if (variable.Deleted && variable.Scope != this && !variable.Scope.IsGlobal) // { // // report syntax error // binder.ReportSyntaxError( // String.Format( // System.Globalization.CultureInfo.InvariantCulture, // "can not delete variable '{0}' referenced in nested scope", // reference.Name // ), // this); // } // } // } //} }
internal override void FinishBind(TotemNameBinder binder) { _contextInfo = CompilationMode.GetContext(); // create global variables for compiler context. TotemGlobal[] globalArray = new TotemGlobal[Variables == null ? 0 : Variables.Count]; //Dictionary<string, TotemGlobal> globals = new Dictionary<string, TotemGlobal>(); TotemDictionary globals = new TotemDictionary(); // GlobalDictionaryStorage storage = new GlobalDictionaryStorage(globals, globalArray); var codeContext = _codeContext = new CodeContext(globals, null, TotemContext); //#if FEATURE_REFEMIT // if (_mode == CompilationMode.ToDisk) { // _arrayExpression = _globalArray; // } else //#endif { var newArray = new ConstantExpression(globalArray); newArray.Parent = this; _arrayExpression = newArray; } if (Variables != null) { int globalIndex = 0; foreach (TotemVariable variable in Variables.Values) { TotemGlobal global = new TotemGlobal(codeContext, variable.Name); _globalVariables[variable] = CompilationMode.GetGlobal(GetGlobalContext(), globals.Count, variable, global); globalArray[globalIndex++] = (TotemGlobal)(globals[variable.Name] = global); } } CompilationMode.PublishContext(codeContext, _contextInfo); }
internal override TotemVariable BindVariable(TotemNameBinder binder, string name) { return EnsureVariable(name); }