public static RubyTopLevelScope/*!*/ CreateMainTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language, out object self, out RuntimeFlowControl/*!*/ rfc, string dataPath, int dataOffset) { Assert.NotNull(locals, globalScope, language); RubyContext context = (RubyContext)language; RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false); RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, locals); scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject); scope.SetDebugName("top-main"); var objectClass = context.ObjectClass; objectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope)); if (dataOffset >= 0) { RubyFile dataFile; if (context.DomainManager.Platform.FileExists(dataPath)) { dataFile = new RubyFile(context, dataPath, RubyFileMode.RDONLY); dataFile.Seek(dataOffset, SeekOrigin.Begin); } else { dataFile = null; } objectClass.SetConstant("DATA", dataFile); } self = scope.SelfObject; rfc = scope.RuntimeFlowControl; return scope; }
internal ScriptCode(CodeBlock code, LanguageContext languageContext, CompilerContext compilerContext) { Assert.NotNull(code, languageContext, compilerContext); _code = code; _languageContext = languageContext; _compilerContext = compilerContext; }
public static RubyTopLevelScope/*!*/ CreateMainTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language, out object self, out RuntimeFlowControl/*!*/ rfc, string dataPath, int dataOffset) { Assert.NotNull(locals, globalScope, language); GlobalScopeExtension rubyGlobalScope = (GlobalScopeExtension)language.EnsureScopeExtension(globalScope); RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, locals); scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject); scope.SetDebugName(rubyGlobalScope.IsHosted ? "top-primary-hosted" : "top-primary"); // define TOPLEVEL_BINDING constant: if (!rubyGlobalScope.IsHosted) { var objectClass = rubyGlobalScope.Context.ObjectClass; objectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope)); if (dataOffset >= 0) { RubyFile dataFile; if (File.Exists(dataPath)) { dataFile = new RubyFile(rubyGlobalScope.Context, dataPath, RubyFileMode.RDONLY); dataFile.Seek(dataOffset, SeekOrigin.Begin); } else { dataFile = null; } objectClass.SetConstant("DATA", dataFile); } } self = scope.SelfObject; rfc = scope.RuntimeFlowControl; return scope; }
/// <summary> /// Called only from OptimizedModuleGenerator. ModuleContext will be set later. /// </summary> internal CodeContext(Scope scope, LanguageContext languageContext) { Assert.NotNull(scope, languageContext); _languageContext = languageContext; _moduleContext = null; _scope = scope; }
public static RubyTopLevelScope/*!*/ CreateTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language, out object self, out RuntimeFlowControl/*!*/ rfc) { RubyTopLevelScope scope = CreateTopLevelScopeInternal(locals, globalScope, language); self = scope.SelfObject; rfc = scope.RuntimeFlowControl; return scope; }
public ToyEngine(LanguageProvider provider, EngineOptions engineOptions) : base(provider, engineOptions) { IronPython.Runtime.Operations.Ops.Bool2Object(true); //awful initialization hack IronPython.Runtime.Operations.Ops.RegisterAssembly(typeof(ToyEngine).Assembly); _defaultContext = new ToyContext(this); _defaultBinder = new DefaultActionBinder(new CodeContext(null, _defaultContext)); }
public CodeContext(Scope scope, LanguageContext languageContext, ModuleContext moduleContext) { Assert.NotNull(scope, languageContext, moduleContext); _languageContext = languageContext; _moduleContext = moduleContext; _scope = scope; }
public StaticGlobalAllocator(LanguageContext/*!*/ context, string name) { _typeGen = Snippets.Shared.DefineType(name, typeof(object), false, false); _codeContextField = _typeGen.AddStaticField(typeof(CodeContext), "__global_context"); _codeContext = CreateFieldBuilderExpression(_codeContextField); _scope = new Scope(new PythonDictionary(new GlobalDictionaryStorage(_globalVals))); _context = new CodeContext(_scope, context); }
public TokenizerTests() { _languageContext = A.Fake<LanguageContext>(); _textContentProvider = A.Fake<TextContentProvider>(); A.CallTo(() => _languageContext.CanCreateSourceCode).Returns(true); A.CallTo(() => _textContentProvider.GetReader()).ReturnsLazily(() => new SourceCodeReader(_codeReader, Encoding.Unicode)); _codeReader = new StringReader(""); }
public static RubyTopLevelScope/*!*/ CreateTopLevelHostedScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language, out object self, out RuntimeFlowControl/*!*/ rfc) { RubyContext context = (RubyContext)language; RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, true); // reuse existing top-level scope if available: RubyTopLevelScope scope = rubyGlobalScope.TopLocalScope; if (scope == null) { scope = new RubyTopLevelScope(rubyGlobalScope, null, locals); scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject); scope.SetDebugName("top-level-hosted"); rubyGlobalScope.TopLocalScope = scope; } self = scope.SelfObject; rfc = scope.RuntimeFlowControl; return scope; }
/// <summary> /// Trys to lookup the provided name in the current scope. Search includes /// names that are only visible to the provided LanguageContext. /// </summary> public bool TryGetObjectName(LanguageContext context, object name, out object value) { //if (_contextScopes != null) { // if (_contextScopes.TryGetObjectName(context, name, out value)) { // return true; // } //} if (_dict.TryGetObjectValue(name, out value)) return true; value = null; return false; }
/// <summary> /// Attemps to remove the provided object name from this scope removing names visible /// to both the current context and all contexts. /// </summary> public bool TryRemoveObjectName(LanguageContext context, object name) { bool fRemoved = false; //if (_contextScopes != null) fRemoved = _contextScopes.TryRemoveObjectName(context, name); //if (_attrs == null || _attrs.CheckDeletable(name)) { fRemoved = _dict.RemoveObjectKey(name) || fRemoved; //} return fRemoved; }
/// <summary> /// Attemps to remove the provided name from this scope's context specific dictionary /// </summary> public bool TryRemoveForContext(LanguageContext context, SymbolId name) { //if (_contextScopes != null) { // return _contextScopes.TryRemoveName(context, name); //} return false; }
/// <summary> /// Determines if this context or any outer scope contains the defined name that /// is available from the provided LanguageContext. /// </summary> public bool ContainsName(LanguageContext context, SymbolId name) { object tmp; return(TryLookupName(context, name, out tmp)); }
private static string GetFullPathAndValidateCase(LanguageContext/*!*/ context, string path, bool isDir) { #if !SILVERLIGHT // check for a match in the case of the filename, unfortunately we can't do this // in Silverlight becauase there's no way to get the original filename. PlatformAdaptationLayer pal = context.DomainManager.Platform; string dir = Path.GetDirectoryName(path); if (!pal.DirectoryExists(dir)) { return null; } try { string file = Path.GetFileName(path); string[] files = isDir ? pal.GetDirectories(dir, file) : pal.GetFiles(dir, file); if (files.Length != 1 || Path.GetFileName(files[0]) != file) { return null; } return Path.GetFullPath(files[0]); } catch (IOException) { return null; } #else return path; #endif }
public bool TryRemoveObjectName(LanguageContext context, object name) { bool fRemoved = false; int id = context.ContextId.Id; if (id < _dicts.Count && _dicts[id] != null) { if (_attrs == null || id > _attrs.Count || _attrs[id].CheckDeletable(name)) { fRemoved = _dicts[id].RemoveObjectKey(name); } } return fRemoved; }
/// <summary> /// Returns the list of Keys and Values available to all languages in addition to those /// keys which are only available to the provided LanguageContext. /// /// Keys marked with DontEnumerate flag will not be returned. /// </summary> public IEnumerable<KeyValuePair<object, object>> GetAllItems(LanguageContext context) { foreach (KeyValuePair<object, object> kvp in _dict) { //if (_attrs == null || _attrs.CheckEnumerable(kvp.Key)) { yield return kvp; //} } //if (_contextScopes != null) { // // TODO: Filter dups // foreach (KeyValuePair<object, object> kvp in _contextScopes.GetItems(context)) { // if (_attrs == null || _attrs.CheckEnumerable(kvp.Key)) yield return kvp; // } //} }
/// <summary> /// Trys to lookup the provided name in the current scope's context specific dictionary. /// Search includes names that are only visible to the provided LanguageContext. /// </summary> public bool TryGetNameForContext(LanguageContext context, SymbolId name, out object value) { #if FULL if (_contextScopes != null) { if (_contextScopes.TryGetName(context, name, out value)) { return true; } } #endif value = null; return false; }
/// <summary> /// Returns the list of Keys available to all languages in addition to those keys /// which are only available to the provided LanguageContext. /// /// Keys marked with the DontEnumerate flag will not be returned. /// </summary> public IEnumerable<SymbolId> GetKeys(LanguageContext context) { foreach (SymbolId si in _dict.SymbolAttributes.Keys) { //if (_attrs == null || _attrs.CheckEnumerable(si)) yield return si; } #if FULL if (_contextScopes != null) { foreach (KeyValuePair<object, object> kvp in _contextScopes.GetItems(context)) { if (kvp.Key is SymbolId) { if (_dict.ContainsKey((SymbolId)kvp.Key)) continue; yield return (SymbolId)kvp.Key; } } } #endif }
public override string ToString() { return(String.Format("ScriptCode '{0}' from {1}", SourceUnit.Path, LanguageContext.GetType().Name)); }
public static ScriptCode Load(DlrMainCallTarget method, LanguageContext language, string path) { SourceUnit su = new SourceUnit(language, NullTextContentProvider.Null, path, SourceCodeKind.File); return(new ScriptCode(null, method, su)); }
public override string ToString() { return($"ScriptCode '{SourceUnit.Path}' from {LanguageContext.GetType().Name}"); }
/// <summary> /// Attempts to lookup the provided object name in this scope or any outer scope. Lookup /// includes searching for names that are visible to the provided LanguageContext as well /// as those available to all contexts. /// </summary> public bool TryLookupObjectName(LanguageContext context, object name, out object value) { Scope curScope = this; do { if (curScope == this || curScope.IsVisible) { if (curScope.TryGetObjectName(context, name, out value)) { return true; } } curScope = curScope.Parent; } while (curScope != null); value = null; return false; }
/// <summary> /// Returns the list of Keys available to all languages in addition to those keys /// which are only available to the provided LanguageContext. /// /// Keys marked with the DontEnumerate flag will not be returned. /// </summary> public IEnumerable<object> GetAllKeys(LanguageContext context) { foreach (object key in _dict.Keys) { //if (_attrs == null || _attrs.CheckEnumerable(key)) yield return key; } //if (_contextScopes != null) { // foreach (KeyValuePair<object, object> kvp in _contextScopes.GetItems(context)) { // if (_dict.ContainsObjectKey(kvp.Key)) continue; // if (_attrs == null || _attrs.CheckEnumerable(kvp.Key)) yield return kvp.Key; // } //} }
internal static Delegate/*!*/ CompileLambda(LambdaExpression/*!*/ lambda, LanguageContext/*!*/ context) { return CompileLambda(lambda, context.DomainManager.Configuration.DebugMode, context.Options.NoAdaptiveCompilation, context.Options.CompilationThreshold); }
public bool TryGetName(LanguageContext context, SymbolId name, out object value) { int id = context.ContextId.Id; if (id < _dicts.Count && _dicts[id] != null) { if (_dicts[id].TryGetValue(name, out value)) { return true; } } value = null; return false; }
/// <summary> /// Trys to lookup the provided name in the current scope's context specific dictionary. /// Search includes names that are only visible to the provided LanguageContext. /// </summary> public bool TryGetNameForContext(LanguageContext context, SymbolId name, out object value) { value = null; return(false); }
public IEnumerable<KeyValuePair<object, object>> GetItems(LanguageContext lc) { int id = lc.ContextId.Id; if (id < _dicts.Count && _dicts[id] != null) { foreach (KeyValuePair<object, object> kvp in _dicts[id]) { if (_attrs == null || id > _attrs.Count || _attrs[id].CheckEnumerable(kvp.Key)) { yield return kvp; } } } yield break; }
/// <summary> /// Removes the provided name from this scope removing names /// visible to both the current context and all contexts. /// </summary> public void RemoveNameForContext(LanguageContext context, SymbolId name) { if (!TryRemoveForContext(context, name)) { throw context.MissingName(name); } }
/// <summary> /// Attempts to lookup the provided name in this scope or any outer scope. The /// search includes looking for names that are only visible to the provided LanguageContext. /// /// If the name is not defined the language defined MissingName exception is thrown. /// </summary> public object LookupName(LanguageContext context, SymbolId name) { object res; if (!TryLookupName(context, name, out res)) { throw context.MissingName(name); } return res; }
/// <summary> /// Attemps to remove the provided name from this scope removing names visible /// to both the current context and all contexts. /// </summary> public bool TryRemoveName(LanguageContext context, SymbolId name) { bool fRemoved = false; //if (_contextScopes != null) fRemoved = _contextScopes.TryRemoveName(context, name); // TODO: Ideally, we could do this without having to do two lookups. object removedObject; if (//(_attrs == null || _attrs.CheckDeletable(name)) && _dict.TryGetValue(name, out removedObject) && removedObject != Uninitialized.Instance) { fRemoved = _dict.Remove(name) || fRemoved; } return fRemoved; }
protected static CodeContext/*!*/ CreateTopLevelCodeContext(PythonDictionary/*!*/ dict, LanguageContext/*!*/ context) { ModuleContext modContext = new ModuleContext(dict, (PythonContext)context); return modContext.GlobalContext; }
/// <summary> /// Determines if this context or any outer scope contains the defined name that /// is available from the provided LanguageContext. /// </summary> public bool ContainsName(LanguageContext context, SymbolId name) { object tmp; return TryLookupName(context, name, out tmp); }
public IronSchemeScriptEngine(LanguageProvider lp, EngineOptions eo, LanguageContext lc) : base(lp, eo, lc) { ((IronSchemeLanguageContext)LanguageContext).se = this; }
/// <summary> /// Removes the provided name from this scope removing names /// visible to both the current context and all contexts. /// </summary> public bool RemoveName(LanguageContext context, SymbolId name) { if (!TryRemoveName(context, name)) { throw context.MissingName(name); } return true; }