Ejemplo n.º 1
0
        public ModuleContext(TotemModule module, TotemContext creatingContext)
        {
            ContractUtils.RequiresNotNull(module, "module");
            ContractUtils.RequiresNotNull(creatingContext, "creatingContext");

            _globals = module.Dictionary;
        }
Ejemplo n.º 2
0
 internal TraceBackFrame(CodeContext context, TotemDictionary globals, object locals, FunctionCode code)
 {
     _globals = globals;
     _locals = locals;
     _code = code;
     _context = context;
 }
Ejemplo n.º 3
0
        public CodeContext(TotemDictionary dict, ModuleContext moduleContext)
        {
            ContractUtils.RequiresNotNull(dict, "dict");
            ContractUtils.RequiresNotNull(moduleContext, "moduleContext");

            _moduleContext = moduleContext;
            _dict = dict;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new CodeContext which is backed by the specified Python dictionary.
        /// </summary>
        public CodeContext(TotemDictionary/*!*/ dict, CodeContext globalContext, TotemContext/*!*/ context)
        {
            ContractUtils.RequiresNotNull(dict, "dict");
            ContractUtils.RequiresNotNull(context, "context");

            _context = context;
            _dict = dict;
            _globalContext = globalContext;
        }
Ejemplo n.º 5
0
        public ModuleContext(TotemDictionary globals, TotemContext creatingContext)
        {
            ContractUtils.RequiresNotNull(globals, "globals");
            ContractUtils.RequiresNotNull(creatingContext, "creatingContext");

            _globals = globals;
            _totemContext = creatingContext;
            _globalContext = new CodeContext(globals, this);
            _module = new TotemModule(globals);
            _module.Scope.SetExtension(_totemContext.ContextId, new TotemScopeExtension(_totemContext, _module, this));
        }
Ejemplo n.º 6
0
        public TotemFunction(CodeContext/*!*/ context, FunctionCode code, TotemDictionary globals, string name, object[] defaults, object[] closure)
            : base(context.LanguageContext.GetType<Types.Function>())
        {
            Assert.NotNull(context, code);

            _context = context;
            _defaults = defaults ?? ArrayUtils.EmptyObjects;
            _code = code;
            _name = code.Name;

            Debug.Assert(_defaults.Length <= code.ArgCount);

            Closure = closure;
        }
Ejemplo n.º 7
0
 /*!*/
 protected static CodeContext CreateTopLevelCodeContext(TotemDictionary/*!*/ dict, LanguageContext/*!*/ context)
 {
     CodeContext modContext = new CodeContext(dict, null, (TotemContext)context);
     return modContext;
 }
Ejemplo n.º 8
0
        public static bool CheckDictionaryMembers(TotemDictionary dict, string[] names)
        {
            if (dict.Count != names.Length)
                return false;

            foreach (string name in names)
                if (!dict.ContainsKey(name))
                    return false;

            return true;
        }
Ejemplo n.º 9
0
        public static object GetFunctionParametersValue(TotemFunction function, int index, string name, TotemArray extraArgs, TotemDictionary dict)
        {
            object val;
            if (extraArgs != null && extraArgs.Count > 0)
                return extraArgs.Shift();

            if (dict != null && dict.TryRemoveValue(name, out val))
                return val;

            return function.Defaults[index];
        }
Ejemplo n.º 10
0
        public static object ExtractDictionaryArgument(TotemFunction function, string name, int argCnt, TotemDictionary dict)
        {
            object val;
            if (dict.TryGetValue(name, out val))
            {
                dict.Remove(name);
                return val;
            }

            throw TypeError("{0}() takes exactly {1} arguments ({2} given)", function.Name, function.NormalArgumentCount, argCnt);
        }
Ejemplo n.º 11
0
        public TotemContext(ScriptDomainManager manager, IDictionary<string, object> options)
            : base(manager)
        {
            _options = new TotemOptions(options);
            _builtinModulesDict = CreateBuiltinTable();

            TotemDictionary defaultScope = new TotemDictionary();
            ModuleContext moduleContext = new ModuleContext(defaultScope, this);
            _defaultContext = moduleContext.GlobalContext;


            TotemBinder binder = new TotemBinder(this, _defaultContext);
            _sharedOverloadResolverFactory = new TotemOverloadResolverFactory(binder, Expression.Constant(_defaultContext));
            _binder = binder;

            if (DefaultContext._default == null)
            {
                DefaultContext.InitializeDefaults(_defaultContext);
            }

            RecursionLimit = _options.RecursionLimit;

            InitializeBuiltins();
        }
Ejemplo n.º 12
0
        public static void AddDictionaryArgument(TotemFunction function, string name, object value, TotemDictionary dict)
        {
            if (dict.ContainsKey(name))
                throw MultipleKeywordArgumentError(function, name);

            dict[name] = value;
        }
Ejemplo n.º 13
0
 protected static CodeContext CreateTopLevelCodeContext(TotemDictionary dict, LanguageContext context)
 {
     CodeContext modContext = new CodeContext(dict, null);
     return modContext;
 }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
 internal TotemModule(TotemContext context, Scope scope)
 {
     _dict = new TotemDictionary(new ScopeDictionaryStorage(context, scope));
     _scope = scope;
 }
Ejemplo n.º 16
0
 internal TotemModule(TotemDictionary dict)
 {
     _dict = dict;
 }
Ejemplo n.º 17
0
        public static TotemDictionary CopyAndVerifyTotemDictionary(TotemFunction function, TotemDictionary dict)
        {
            if (dict._storage.HasNonStringAttributes())
                throw TypeError("{0}() keywords must be strings", function.Name);

            return new TotemDictionary(dict);
        }