public static Expression Assign(Expression left, Expression right)
        {
            GlobalVariableExpression assignable = left as GlobalVariableExpression;

            if (assignable != null)
            {
                return(new AssignmentExtensionExpression(left, right));
            }

            return(Expression.Assign(left, right));
        }
        protected override Expression RewriteGet(GlobalVariableExpression node) {
            EnsureUniqueName(node);

            return AstUtils.Convert(
                Expression.Call(
                    typeof(ScriptingRuntimeHelpers).GetMethod(node.IsLocal ? "LookupName" : "LookupGlobalName"),
                    new Expression[]{
                        Context,
                        AstUtils.Constant(SymbolTable.StringToId(node.Name))
                    }
                ),
                node.Type
            );
        }
        protected Expression MapToExpression(GlobalVariableExpression variable) {
            Expression result;
            if (_mapToExpression.TryGetValue(variable, out result)) {
                return result;
            }

            EnsureUniqueName(_globalNames, variable);

            result = Expression.Property(
                MakeWrapper(variable),
                typeof(ModuleGlobalWrapper).GetProperty("CurrentValue")
            );

            return _mapToExpression[variable] = result;
        }
Exemple #4
0
 protected abstract Expression RewriteGet(GlobalVariableExpression node);
Exemple #5
0
        protected static void EnsureUniqueName(IDictionary<string, GlobalVariableExpression> varsByName, GlobalVariableExpression node) {
            GlobalVariableExpression n2;
            if (varsByName.TryGetValue(node.Name, out n2)) {
                if (node == n2) {
                    return;
                }
                throw Error.GlobalsMustBeUnique();
            }

            varsByName.Add(node.Name, node);
        }
 private Expression RewriteGet(GlobalVariableExpression node) {
     if (_wrappers == null) {
         return new LookupNameExpression(node.IsLocal, SymbolTable.StringToId(node.Name), Context);
     } else {
         return new GlobalGetExpression(GetWrapper(node));
     }
 }
 private ModuleGlobalWrapper GetWrapper(GlobalVariableExpression node) {
     ModuleGlobalWrapper ret;
     if (!_wrappers.TryGetValue(node, out ret)) {
         ret = new ModuleGlobalWrapper(_codeContext, SymbolTable.StringToId(node.Name));
         _wrappers[node] = ret;
     }
     return ret;
 }
 private void EnsureUniqueName(GlobalVariableExpression node) {
     EnsureUniqueName(node.IsLocal ? _localNames : _globalNames, node);
 }
 protected override Expression RewriteGet(GlobalVariableExpression node) {
     return AstUtils.Convert(MapToExpression(node), node.Type);
 }
 protected abstract Expression MakeWrapper(GlobalVariableExpression variable);