OK. Tomas
_____________________________________________ From: Dino Viehland Sent: Friday, September 11, 2009 11:21 AM To: Tomas Matousek; IronRuby External Code Reviewers; Rowan Code Reviewers Cc: [email protected] Subject: RE: Code Review: Constants6 Can you just use Expression.Constant to box instead? ScopeStorage ultimately won't have access to AstUtils and it'll save me from changing it later. Otherwise DLR looks good. _____________________________________________ From: Tomas Matousek Sent: Friday, September 11, 2009 11:10 AM To: IronRuby External Code Reviewers; Rowan Code Reviewers Cc: [email protected] Subject: Code Review: Constants6 tfpt review "/shelveset:Constants6;REDMOND\tomat" DLR: Fixes ScopeStorage.BindSetMember - it needs to box the argument before passing it to SetValue helper. Ruby: Changes constant publishing and lookup in global DLR scope. Previously Object class didn't have a constant table. Object constants were stored directly in the global scope. This allowed to publish any value to the host and other languages just by defining a constant on Object. Object constants include all constants defined by top-level code as well as built-in constants (VERSION, TRUE, FALSE, NIL, etc.) and modules (Object, String, Time, ...). This makes it highly probable that some of these constants collide with similar constants of other languages hosted in the same script runtime. This shelveset implements a different approach. It adds a constant table to Object class that contains all constants that MRI defines on Object. To enable interop scenarios, in which e.g. IronPython loads Ruby library and looks up loaded top-level modules in the global scope, we publish those constants defined on Object whose value is a Module or Class instance. Built-in modules/classes are not published by default. The global scope is therefore initially empty (if not populated by the host or other language) and references to the top-level modules and classes are stored there as Ruby scripts execute. A definition of a module or a class on Object publishes the module/class to the global scope. Also, an assignment expression of a module/class instance to a constant on Object publishes that module/class to the global scope. In both cases the constant reference is stored in both Object constant table and in the global scope storage. To enable the reverse interop scenario, i.e. consuming values published in the global scope by the host or another language, the default implementation of Module#constant_missing doesn't just throw an exception. Instead, it looks first into a table of loaded CLR namespaces (for symbols like System, Microsoft, etc.) and then into the global scope. Only if the constant is not found there an exception is thrown. The lookup in the global scope uses reverse name mangling. First, the name is looked up as typed, then the name is converted to snake_case. It is also possible to look up and publish constants explicitly via IronRuby.globals method, which returns the global scope (of type Microsoft.Scripting.Runtime.Scope): Runtime.Globals.SetVariable("foo_bar", 1); Engine.Execute(@" IronRuby.globals.x = 2 IronRuby.globals.z = IronRuby.globals.x + FooBar "); Assert(Runtime.Globals.GetVariable<int>("z") == 3); The shelveset also adds a constant table version number and a weak list of nested modules to all Ruby modules. These are going to be used by constant caching in next check-ins. Tomas << File: Constants6.diff >>
_______________________________________________ Ironruby-core mailing list [email protected] http://rubyforge.org/mailman/listinfo/ironruby-core
