internal virtual TotemVariable BindVariable(TotemNameBinder binder, string name) { TotemVariable ret; if (!LookupVariable(name, out ret)) { ret = Parent.BindVariable(binder, name); SetVariable(name, ret); } return ret; }
internal virtual TotemVariable DefineVariable(TotemNameBinder binder, string name) { TotemVariable ret; if (LookupVariable(name, out ret) && ret.Kind == VariableKind.Local && ret.Scope == this) throw new NameErrorException("Cannot redefine " + name); ret = new TotemVariable(name, VariableKind.Local, this); SetVariable(name, ret); return ret; }
internal override TotemVariable BindVariable(TotemNameBinder binder, string name) { TotemVariable ret; if (!LookupVariable(name, out ret)) { ret = Parent.BindVariable(binder, name); ret.AccessedInNestedScope = true; ret.Scope.AddCellVariable(ret); SetVariable(name, ret); } return ret; }
internal override void FinishBind(TotemNameBinder binder) { if (_freeVars != null && _freeVars.Count > 0) { ReadOnlyCollectionBuilder<TotemVariable> closureVariables = new ReadOnlyCollectionBuilder<TotemVariable>(); _closureType = MutableTuple.MakeTupleType(_freeVars.Select(v => typeof(ClosureCell)).ToArray()); _localClosureTuple = Expression.Parameter(_closureType, "$closure"); for (var i = 0; i < _freeVars.Count; i++) { var variable = _freeVars[i]; _variableMapping[variable] = new ClosureExpression(variable, Expression.Property(_localClosureTuple, String.Format("Item{0:D3}", i)), null); closureVariables.Add(variable); } _closureVariables = closureVariables.ToReadOnlyCollection(); } if (_scopeVars != null) foreach (var local in _scopeVars) { if (local.Kind == VariableKind.Parameter) // handled in subclass continue; // scope variables, defined in this scope Debug.Assert(local.Kind == VariableKind.Local); Debug.Assert(local.Scope == this); if (local.AccessedInNestedScope) { // Closure variable _variableMapping[local] = new ClosureExpression(local, Expression.Parameter(typeof(ClosureCell), local.Name), null); } else { // Not used in nested function-scopes _variableMapping[local] = Expression.Parameter(typeof(object), local.Name); } } }
internal virtual void FinishBind(TotemNameBinder binder) { if (_freeVars != null) foreach (var variable in _freeVars) { // Free variables, defined in outer scopes. // Note that this scope is only a lexical scope (like a loop // or BlockStatement), thus we don't need to query a local // closure-tuple, we simply ask the parent scope for the // binding. _variableMapping[variable] = Parent._variableMapping[variable]; } if (_scopeVars != null) foreach (var local in _scopeVars) { // scope variables, defined in this scope Debug.Assert(local.Kind == VariableKind.Local); Debug.Assert(local.Scope == this); if (local.AccessedInNestedScope) { // Closure variable _variableMapping[local] = new ClosureExpression(local, Expression.Parameter(typeof(ClosureCell), local.Name), null); } else { // Not used in nested function-scopes _variableMapping[local] = Expression.Parameter(typeof(object), local.Name); } } }
internal virtual void Bind(TotemNameBinder binder) { }
internal override void FinishBind(TotemNameBinder binder) { foreach (var param in _parameters) _variableMapping[param.TotemVariable] = param.FinishBind(); base.FinishBind(binder); }
internal override TotemVariable BindVariable(TotemNameBinder binder, string name) { TotemVariable ret; if (!LookupVariable(name, out ret)) { ret = new TotemVariable(name, VariableKind.Global, this); SetVariable(name, ret); return ret; } return ret; }
internal override void FinishBind(TotemNameBinder binder) { base.FinishBind(binder); TotemGlobal[] globalArray = new TotemGlobal[_globalVars == null ? 0 : _globalVars.Count]; Dictionary<string, TotemGlobal> globals = new Dictionary<string, TotemGlobal>(); GlobalDictionaryStorage storage = new GlobalDictionaryStorage(globals, globalArray); var modContext = _moduleContext = new ModuleContext(new TotemDictionary(storage), TotemContext); //if (_mode == CompilationMode.ToDisk) //{ // _arrExpression = _globalArray; //} //else //{ var newArray = new ConstantExpr(globalArray); newArray.Parent = this; _arrayExpression = newArray; //} if (_globalVars != null) { int globalIndex = 0; foreach (var variable in _globalVars) { TotemGlobal global = new TotemGlobal(modContext.GlobalContext, variable.Name); _globalVariables[variable] = CompilationMode.GetGlobal(GetGlobalContext(), globals.Count, variable, global); globalArray[globalIndex++] = globals[variable.Name] = global; } } CompilationMode.PublishContext(modContext.GlobalContext, _contextInfo); }