public GlobalDictionaryStorage(Dictionary<string, TotemGlobal> globals, TotemGlobal[] data)
        {
            Assert.NotNull(globals, data);

            _globals = globals;
            _data = data;
        }
 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 TotemGlobalVariableExpression(Expression globalExpr, TotemVariable variable, TotemGlobal global, bool lightEh)
        {
            Assert.NotNull(globalExpr, variable);

            _target = globalExpr;
            _global = global;
            _variable = variable;
            _lightEh = lightEh;
        }
        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
            );
        }
示例#5
0
 public abstract Expression GetGlobal(Expression globalContext, int arrayIndex, TotemVariable variable, TotemGlobal global);
        //public override bool TryGetBuiltins(out object value)
        //{
        //    return TryGetCachedValue(ref _builtins, "__builtins__", out value);
        //}

        //public override bool TryGetPath(out object value)
        //{
        //    return TryGetCachedValue(ref _path, "__path__", out value);
        //}

        //public override bool TryGetPackage(out object value)
        //{
        //    return TryGetCachedValue(ref _package, "__package__", out value);
        //}

        //public override bool TryGetName(out object value)
        //{
        //    return TryGetCachedValue(ref _name, "__name__", out value);
        //}

        private bool TryGetCachedValue(ref TotemGlobal storage, string name, out object value)
        {
            if (storage == null)
            {
                if (!_globals.TryGetValue(name, out storage))
                {
                    return TryGetValue(name, out value);
                }
            }

            value = storage.RawValue;
            return value != Uninitialized.Instance;
        }
 public TotemGlobalVariableExpression(Expression globalExpr, TotemVariable variable, TotemGlobal global)
     : this(globalExpr, variable, global, false)
 { }
 public TotemSetGlobalInstruction(TotemGlobal global)
 {
     _global = global;
 }
 public TotemLightThrowGlobalInstruction(TotemGlobal global)
     : base(global)
 {
 }
示例#10
0
        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);
        }
 public TotemGlobalVariableExpression(Expression/*!*/ globalExpr, Ast.TotemVariable/*!*/ variable, TotemGlobal/*!*/ global)
     : this(globalExpr, variable, global, false)
 {
 }
示例#12
0
        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);
        }