예제 #1
0
        internal bool LookupVariable(string name, out TotemVariable variable)
        {
            variable = null;
            if (_scopeVarsLookup == null)
                return false;

            return _scopeVarsLookup.TryGetValue(name, out variable);
        }
 public override Expression GetGlobal(Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global)
 {
     return new LookupGlobalVariable(
         globalContext,
         variable.Name,
         variable.Kind == VariableKind.Local
     );
 }
        public TotemGlobalVariableExpression(Expression globalExpr, TotemVariable variable, TotemGlobal global, bool lightEh)
        {
            Assert.NotNull(globalExpr, variable);

            _target = globalExpr;
            _global = global;
            _variable = variable;
            _lightEh = lightEh;
        }
예제 #4
0
        public ClosureExpression(TotemVariable variable, Expression closureCell, ParameterExpression parameter)
        {
            ContractUtils.RequiresNotNull(closureCell, "closureCell");
            Debug.Assert(closureCell.Type == typeof(ClosureCell));

            _closureCell = closureCell;
            _parameter = parameter;
            _variable = variable;
        }
예제 #5
0
        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;
        }
예제 #6
0
        internal void AddCellVariable(TotemVariable variable)
        {
            if (_cellVars == null)
            {
                _cellVars = new List<string>();
            }

            if (!_cellVars.Contains(variable.Name))
            {
                _cellVars.Add(variable.Name);
            }
        }
        public override Expression GetGlobal(Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global)
        {
            Assert.NotNull(global);

            return new TotemGlobalVariableExpression(
                Expression.ArrayIndex(
                    TotemAst._globalArray,
                    Expression.Constant(arrayIndex)
                ),
                variable,
                global
            );
        }
예제 #8
0
 public abstract Expression GetGlobal(Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global);
예제 #9
0
        internal void SetVariable(string name, TotemVariable variable)
        {
            List<TotemVariable> list;
            if (variable.IsGlobal)
            {
                if (_globalVars == null)
                    _globalVars = new List<TotemVariable>();
                list = _globalVars;
            }
            else if (variable.Scope != this)
            {
                if (_freeVars == null)
                    _freeVars = new List<TotemVariable>();
                list = _freeVars;
            }
            else
            {
                if (_scopeVars == null)
                    _scopeVars = new List<TotemVariable>();
                list = _scopeVars;
            }
            if (_scopeVarsLookup == null)
                _scopeVarsLookup = new Dictionary<string, TotemVariable>();

            list.Add(variable);
            _scopeVarsLookup[name] = variable;
        }
예제 #10
0
        internal virtual Expression GetVariableExpression(TotemVariable variable)
        {
            if (variable.IsGlobal)
                return GlobalParent.ModuleVariables[variable];

            Debug.Assert(_variableMapping.ContainsKey(variable));
            return _variableMapping[variable];
        }
 public TotemGlobalVariableExpression(Expression globalExpr, TotemVariable variable, TotemGlobal global)
     : this(globalExpr, variable, global, false)
 { }
예제 #12
0
 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;
 }