public ModuleContext(TotemModule module, TotemContext creatingContext) { ContractUtils.RequiresNotNull(module, "module"); ContractUtils.RequiresNotNull(creatingContext, "creatingContext"); _globals = module.Dictionary; }
internal TraceBackFrame(CodeContext context, TotemDictionary globals, object locals, FunctionCode code) { _globals = globals; _locals = locals; _code = code; _context = context; }
public CodeContext(TotemDictionary dict, ModuleContext moduleContext) { ContractUtils.RequiresNotNull(dict, "dict"); ContractUtils.RequiresNotNull(moduleContext, "moduleContext"); _moduleContext = moduleContext; _dict = dict; }
/// <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; }
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)); }
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; }
/*!*/ protected static CodeContext CreateTopLevelCodeContext(TotemDictionary/*!*/ dict, LanguageContext/*!*/ context) { CodeContext modContext = new CodeContext(dict, null, (TotemContext)context); return modContext; }
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; }
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]; }
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); }
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(); }
public static void AddDictionaryArgument(TotemFunction function, string name, object value, TotemDictionary dict) { if (dict.ContainsKey(name)) throw MultipleKeywordArgumentError(function, name); dict[name] = value; }
protected static CodeContext CreateTopLevelCodeContext(TotemDictionary dict, LanguageContext context) { CodeContext modContext = new CodeContext(dict, null); return modContext; }
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); }
internal TotemModule(TotemContext context, Scope scope) { _dict = new TotemDictionary(new ScopeDictionaryStorage(context, scope)); _scope = scope; }
internal TotemModule(TotemDictionary dict) { _dict = dict; }
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); }