Example #1
0
        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;
        }
Example #2
0
 internal ScriptCode(CodeBlock code, LanguageContext languageContext, CompilerContext compilerContext) {
     Assert.NotNull(code, languageContext, compilerContext);
     
     _code = code;
     _languageContext = languageContext;
     _compilerContext = compilerContext;
 }
Example #3
0
        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;
        }
Example #4
0
        /// <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;
        }
Example #5
0
        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;
        }
Example #6
0
        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));
        }
Example #7
0
        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);
        }
Example #9
0
        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("");
        }
Example #10
0
        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;
        }
Example #11
0
        /// <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;
        }
Example #12
0
        /// <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;
        }
Example #13
0
        /// <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;
        }
Example #14
0
        /// <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));
        }
Example #15
0
        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
        }
Example #16
0
            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;
            }
Example #17
0
        /// <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;
            //    }
            //}
        }
Example #18
0
        /// <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;
        }
Example #19
0
        /// <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
        }
Example #20
0
 public override string ToString()
 {
     return(String.Format("ScriptCode '{0}' from {1}", SourceUnit.Path, LanguageContext.GetType().Name));
 }
Example #21
0
        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));
        }
Example #22
0
 public override string ToString()
 {
     return($"ScriptCode '{SourceUnit.Path}' from {LanguageContext.GetType().Name}");
 }
Example #23
0
        /// <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;
        }
Example #24
0
        /// <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;
            //    }
            //}
        }
Example #25
0
 internal static Delegate/*!*/ CompileLambda(LambdaExpression/*!*/ lambda, LanguageContext/*!*/ context) {
     return CompileLambda(lambda, context.DomainManager.Configuration.DebugMode, context.Options.NoAdaptiveCompilation, context.Options.CompilationThreshold);
 }
Example #26
0
            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;
            }
Example #27
0
 /// <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);
 }
Example #28
0
            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;
            }
Example #29
0
 /// <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);
     }
 }
Example #30
0
        /// <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;
        }
Example #31
0
        /// <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;
        }
Example #32
0
 protected static CodeContext/*!*/ CreateTopLevelCodeContext(PythonDictionary/*!*/ dict, LanguageContext/*!*/ context) {
     ModuleContext modContext = new ModuleContext(dict, (PythonContext)context);
     return modContext.GlobalContext;
 }
Example #33
0
 /// <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;
 }
Example #35
0
 /// <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;
 }