Beispiel #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);

            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;
        }
Beispiel #2
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;
        }
        private object Run(Scope /*!*/ scope, bool bindGlobals)
        {
            RubyScope   localScope;
            RubyContext context = (RubyContext)LanguageContext;

            switch (_kind)
            {
            case TopScopeFactoryKind.Hosted:
                localScope = RubyTopLevelScope.CreateHostedTopLevelScope(scope, context, bindGlobals);
                break;

            case TopScopeFactoryKind.Main:
                localScope = RubyTopLevelScope.CreateTopLevelScope(scope, context, true);
                break;

            case TopScopeFactoryKind.File:
                localScope = RubyTopLevelScope.CreateTopLevelScope(scope, context, false);
                break;

            case TopScopeFactoryKind.WrappedFile:
                localScope = RubyTopLevelScope.CreateWrappedTopLevelScope(scope, context);
                break;

            default:
                throw Assert.Unreachable;
            }

            return(Target(localScope, localScope.SelfObject));
        }
        public void OverloadResolution_Block()
        {
            var t = GetType();

            var gse   = new GlobalScopeExtension(Context, new Scope(), new object(), true);
            var scope = new RubyTopLevelScope(gse, null, new SymbolDictionary());
            var proc  = new Proc(ProcKind.Proc, null, scope, new BlockDispatcher0((x, y) => null, BlockSignatureAttributes.None));

            var scopeArg    = new MetaObject(Ast.Constant(proc.LocalScope), Restrictions.Empty, proc.LocalScope);
            var contextArg  = new MetaObject(Ast.Constant(Context), Restrictions.Empty, Context);
            var instanceInt = new MetaObject(Ast.Constant(1), Restrictions.Empty, 1);
            var str         = "foo";
            var instanceStr = new MetaObject(Ast.Constant(str), Restrictions.Empty, str);
            var procArg     = new MetaObject(Ast.Constant(proc), Restrictions.Empty, proc);
            var nullArg     = new MetaObject(Ast.Constant(Ast.Constant(null)), Restrictions.Empty, null);

            var arguments = new[] {
                // 1.times
                new CallArguments(scopeArg, instanceInt, new MetaObject[0], RubyCallSignature.WithScope(0)),
                // 1.times &nil
                new CallArguments(scopeArg, instanceInt, new[] { nullArg }, RubyCallSignature.WithScopeAndBlock(0)),
                // 1.times &p
                new CallArguments(contextArg, instanceInt, new[] { procArg }, RubyCallSignature.WithBlock(0)),
                // obj.times &p
                new CallArguments(contextArg, instanceStr, new[] { procArg }, RubyCallSignature.WithBlock(0)),
            };

            var results = new[] {
                "Times2",
                "Times1",
                "Times3",
                "Times4",
            };

            for (int i = 0; i < arguments.Length; i++)
            {
                var bindingTarget = RubyMethodGroupInfo.ResolveOverload("times", new[] {
                    t.GetMethod("Times1"),
                    t.GetMethod("Times2"),
                    t.GetMethod("Times3"),
                    t.GetMethod("Times4"),
                }, arguments[i], true, false);

                Assert(bindingTarget.Success);
                Assert(bindingTarget.Method.Name == results[i]);
            }
        }
        public void OverloadResolution_Block() {
            var t = GetType();

            var gse = new RubyGlobalScope(Context, new Scope(), new object(), true);
            var scope = new RubyTopLevelScope(gse, null, new SymbolDictionary());
            var proc = new Proc(ProcKind.Proc, null, scope, new BlockDispatcher0((x, y) => null, BlockSignatureAttributes.None));

            var scopeArg = new DynamicMetaObject(Ast.Constant(proc.LocalScope), BindingRestrictions.Empty, proc.LocalScope);
            var contextArg = new DynamicMetaObject(Ast.Constant(Context), BindingRestrictions.Empty, Context);
            var instanceInt = new DynamicMetaObject(Ast.Constant(1), BindingRestrictions.Empty, 1);
            var str = "foo";
            var instanceStr = new DynamicMetaObject(Ast.Constant(str), BindingRestrictions.Empty, str);
            var procArg = new DynamicMetaObject(Ast.Constant(proc), BindingRestrictions.Empty, proc);
            var nullArg = new DynamicMetaObject(Ast.Constant(Ast.Constant(null)), BindingRestrictions.Empty, null);

            var arguments = new[] {
                // 1.times
                new CallArguments(scopeArg, instanceInt, new DynamicMetaObject[0], RubyCallSignature.WithScope(0)),
                // 1.times &nil             
                new CallArguments(scopeArg, instanceInt, new[] {  nullArg }, RubyCallSignature.WithScopeAndBlock(0)),
                // 1.times &p                            
                new CallArguments(contextArg, instanceInt, new[] {  procArg }, RubyCallSignature.WithBlock(0)),
                // obj.times &p                          
                new CallArguments(contextArg, instanceStr, new[] {  procArg }, RubyCallSignature.WithBlock(0)),
            };

            var results = new[] {
                "Times2",
                "Times1",
                "Times3",
                "Times4",
            };

            for (int i = 0; i < arguments.Length; i++) {
                var bindingTarget = RubyMethodGroupInfo.ResolveOverload("times", new[] {
                    t.GetMethod("Times1"),
                    t.GetMethod("Times2"),
                    t.GetMethod("Times3"),
                    t.GetMethod("Times4"),
                }, arguments[i], true, false);

                Assert(bindingTarget.Success);
                Assert(bindingTarget.Method.Name == results[i]);
            }
        }
Beispiel #6
0
        internal static RubyTopLevelScope/*!*/ CreateTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context) {
            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false);

            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, new RuntimeFlowControl(), rubyGlobalScope.MainObject);
            scope.SetDebugName("top-level");

            return scope;
        }
Beispiel #7
0
        internal static RubyTopLevelScope/*!*/ CreateTopLevelHostedScope(Scope/*!*/ globalScope, RubyContext/*!*/ context) {
            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, new RuntimeFlowControl(), rubyGlobalScope.MainObject);
                scope.SetDebugName("top-level-hosted");
                rubyGlobalScope.TopLocalScope = scope;
            } else {
                // If we reuse a local scope from previous execution all local variables are accessed dynamically.
                // Therefore we shouldn't have any new static local variables.
            }

            return scope;
        }
Beispiel #8
0
        private static RubyTopLevelScope/*!*/ CreateTopLevelScopeInternal(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language) {
            GlobalScopeExtension rubyGlobalScope = (GlobalScopeExtension)language.EnsureScopeExtension(globalScope);
            RubyTopLevelScope result = new RubyTopLevelScope(rubyGlobalScope, null, locals);
            result.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject);
            result.SetDebugName("top-level");

            return result;
        }
Beispiel #9
0
        public void MutableString_IndexRegex1() {
            var SJIS = RubyEncoding.GetRubyEncoding(RubyEncoding.CodePageSJIS);
            var sjis = new byte[] { 0x82, 0xA0 };
            var u12345 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 }; // \u{12345} in UTF-8
            var invalid = MutableString.CreateBinary(new byte[] { 0x80 }, RubyEncoding.UTF8);
            int i;
            MutableString a;
            RubyRegex r;
            RubyScope scope = new RubyTopLevelScope(Context);

            // incompatible encodings:
            a = MutableString.CreateBinary(sjis, SJIS);
            r = new RubyRegex(MutableString.CreateBinary(u12345, RubyEncoding.UTF8));
            AssertExceptionThrown<EncodingCompatibilityError>(() => MutableStringOps.Index(scope, a, r, 0));

            // invalid character:
            AssertExceptionThrown<ArgumentException>(() => MutableStringOps.Index(scope, invalid, r, 0));

            // returns character index:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("aαb", RubyEncoding.UTF8),
                new RubyRegex(MutableString.CreateMutable("b", SJIS)),
                0
            );
            Assert(i == 2);

            // "start at" counts chars in 1.9, returns character index
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αabbba", RubyEncoding.UTF8),
                new RubyRegex(MutableString.CreateAscii("a")),
                2
            );
            Assert(i == 5);

            // "start at" counts bytes in 1.8, returns byte index (regardless of KCODE)
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateBinary(Encoding.UTF8.GetBytes("αa"), RubyEncoding.Binary),
                new RubyRegex(MutableString.CreateAscii("a"), RubyRegexOptions.UTF8),
                2
            );
            Assert(i == 2);

            // returns byte index for k-coded strings:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αaβb", RubyEncoding.KCodeUTF8),
                new RubyRegex(MutableString.CreateMutable("a", RubyEncoding.KCodeSJIS)),
                0
            );
            Assert(i == 2);

            // returns byte index for k-coded strings:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αabbba", RubyEncoding.KCodeUTF8),
                new RubyRegex(MutableString.CreateAscii("a")),
                2
            );
            Assert(i == 2);

            // uses the current KCODE for match:
            a = MutableString.CreateBinary(new byte[] { 0x82, 0xa1, 0x82, 0xa0, 0x82, 0xa0 }, RubyEncoding.Binary);
            r = new RubyRegex(MutableString.CreateBinary(new byte[] { 0x82, 0xa0, (byte)'{', (byte)'2', (byte)'}' }, RubyEncoding.Binary));

            Context.KCode = RubyEncoding.KCodeSJIS;
            Assert((int)MutableStringOps.Index(scope, a, r, 0) == 2);

            Context.KCode = null;
            Assert(MutableStringOps.Index(scope, a, r, 0) == null);

            // invalid characters:
            a = MutableString.CreateBinary(new byte[] { 0x82, 0x82, 0xa0, 0xa0, 0x82 }, RubyEncoding.Binary); // invalid
            r = new RubyRegex(MutableString.CreateBinary(new byte[] { 0x82, 0xa0, (byte)'{', (byte)'2', (byte)'}' }, RubyEncoding.Binary)); // valid

            Context.KCode = RubyEncoding.KCodeSJIS;
            Assert(MutableStringOps.Index(scope, a, r, 0) == null);

            Context.KCode = null;
            Assert((int)MutableStringOps.Index(scope, a, r, 0) == 1);
        }
Beispiel #10
0
        internal static RubyTopLevelScope/*!*/ CreateHostedTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context, bool bindGlobals) {
            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, true, bindGlobals);

            // Reuse existing top-level scope if available:
            RubyTopLevelScope scope = rubyGlobalScope.TopLocalScope;
            if (scope == null) {
                scope = new RubyTopLevelScope(
                    rubyGlobalScope, null, bindGlobals ? rubyGlobalScope.MainSingleton : null, rubyGlobalScope.MainObject
                );

                scope.SetDebugName(bindGlobals ? "top-level-bound" : "top-level");
                rubyGlobalScope.SetTopLocalScope(scope);
            } else {
                // If we reuse a local scope from previous execution all local variables are accessed dynamically.
                // Therefore we shouldn't have any new static local variables.
            }

            return scope;
        }
Beispiel #11
0
 // top scope:
 protected RubyScope(LanguageContext/*!*/ language, IAttributesCollection/*!*/ frame)
     : base(null, language, null) {
     _frame = frame;
     _top = (RubyTopLevelScope)this;
 }
Beispiel #12
0
        public static RubyTopLevelScope/*!*/ CreateWrappedTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language,
            out object self, out RuntimeFlowControl/*!*/ rfc) {

            RubyContext context = (RubyContext)language;

            RubyModule module = context.CreateModule(null, null, null, null, null, null, null);
            object mainObject = new Object();
            RubyClass mainSingleton = context.CreateMainSingleton(mainObject, new[] { module });

            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false);
            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, locals);
            scope.Initialize(new RuntimeFlowControl(), RubyMethodAttributes.PrivateInstance, rubyGlobalScope.MainObject);
            scope.SetDebugName("top-level-wrapped");
            scope.SelfObject = mainObject;
            scope.SetModule(module);

            self = scope.SelfObject;
            rfc = scope.RuntimeFlowControl;
            return scope;
        }
Beispiel #13
0
        public static RubyTopLevelScope/*!*/ CreateTopLevelScope(LocalsDictionary/*!*/ locals, Scope/*!*/ globalScope, LanguageContext/*!*/ language,
            out object self, out RuntimeFlowControl/*!*/ rfc) {

            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-level");

            self = scope.SelfObject;
            rfc = scope.RuntimeFlowControl;
            return scope;
        }
Beispiel #14
0
 // other scopes:
 protected RubyScope(RubyScope /*!*/ parent, IAttributesCollection /*!*/ frame)
     : base(null, parent.Top.LanguageContext, parent)
 {
     _frame = frame;
     _top   = parent.Top;
 }
Beispiel #15
0
 // top scope:
 protected RubyScope(LanguageContext /*!*/ language, IAttributesCollection /*!*/ frame)
     : base(null, language, null)
 {
     _frame = frame;
     _top   = (RubyTopLevelScope)this;
 }
Beispiel #16
0
        public void MutableString_IndexRegex1()
        {
            var u12345 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 }; // \u{12345} in UTF-8
            var invalid = MutableString.CreateBinary(new byte[] { 0x80 }, RubyEncoding.UTF8);
            int i;
            RubyScope scope = new RubyTopLevelScope(Context);

            // "start at" counts chars in 1.9, returns character index
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("αabbba", RubyEncoding.UTF8),
                new RubyRegex(MutableString.CreateAscii("a")),
                2
            );
            Assert(i == 5);

            #if FEATURE_ENCODING
            MutableString a;
            RubyRegex r;

            var SJIS = RubyEncoding.GetRubyEncoding(RubyEncoding.CodePageSJIS);
            var sjis = new byte[] { 0x82, 0xA0 };

            // incompatible encodings:
            a = MutableString.CreateBinary(sjis, SJIS);
            r = new RubyRegex(MutableString.CreateBinary(u12345, RubyEncoding.UTF8));
            AssertExceptionThrown<EncodingCompatibilityError>(() => MutableStringOps.Index(scope, a, r, 0));

            // invalid character:
            AssertExceptionThrown<InvalidByteSequenceError>(() => MutableStringOps.Index(scope, invalid, r, 0));

            // returns character index:
            i = (int)MutableStringOps.Index(
                scope,
                MutableString.CreateMutable("aαb", RubyEncoding.UTF8),
                new RubyRegex(MutableString.CreateMutable("b", SJIS)),
                0
            );
            Assert(i == 2);
            #endif
        }
Beispiel #17
0
 internal RubyTopLevelScope/*!*/ SetTopLocalScope(RubyTopLevelScope/*!*/ scope) {
     return Interlocked.CompareExchange(ref _topLocalScope, scope, null);
 }
Beispiel #18
0
        internal static RubyTopLevelScope/*!*/ CreateWrappedTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context) {
            RubyModule module = context.CreateModule(null, null, null, null, null, null, null);
            object mainObject = new Object();
            RubyClass mainSingleton = context.CreateMainSingleton(mainObject, new[] { module });

            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false);
            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, module, new RuntimeFlowControl(), mainObject);
            scope.SetDebugName("top-level-wrapped");

            return scope;
        }
Beispiel #19
0
 // other scopes:
 protected RubyScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame)
     : base(null, parent.Top.LanguageContext, parent) {
     _frame = frame;
     _top = parent.Top;
 }
Beispiel #20
0
 // other scopes:
 protected RubyScope(RubyScope/*!*/ parent, IAttributesCollection/*!*/ frame) {
     Assert.NotNull(parent, frame);
     _frame = frame;
     _parent = parent;
     _top = parent.Top;
 }
Beispiel #21
0
 // top scope:
 protected RubyScope(IAttributesCollection/*!*/ frame) {
     Assert.NotNull(frame);
     _frame = frame;
     _top = (RubyTopLevelScope)this;
     _parent = null;
 }
Beispiel #22
0
 public static object MethodMissing(RubyScope /*!*/ scope, BlockParam block, Scope /*!*/ self, [NotNull] RubySymbol /*!*/ symbol, params object[] /*!*/ args)
 {
     return(RubyTopLevelScope.ScopeMethodMissing(scope.RubyContext, self, block, null, symbol, args));
 }
Beispiel #23
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;
        }
Beispiel #24
0
 // top scope:
 protected RubyScope(RuntimeFlowControl/*!*/ runtimeFlowControl, object selfObject) {
     _top = (RubyTopLevelScope)this;
     _parent = null;
     _selfObject = selfObject;
     _runtimeFlowControl = runtimeFlowControl;
     _methodAttributes = RubyMethodAttributes.PrivateInstance;
 }
Beispiel #25
0
        internal static RubyTopLevelScope/*!*/ CreateTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context, bool isMain) {
            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false, false);

            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, null, rubyGlobalScope.MainObject);
            if (isMain) {
                scope.SetDebugName("top-main");
                context.ObjectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope));
                if (context.RubyOptions.RequirePaths != null) {
                    foreach (var path in context.RubyOptions.RequirePaths) {
                        context.Loader.LoadFile(globalScope, rubyGlobalScope.MainObject, MutableString.Create(path, RubyEncoding.UTF8), LoadFlags.Require);
                    }
                }
            } else {
                scope.SetDebugName("top-required");
            }

            return scope;
        }
Beispiel #26
0
 // other scopes:
 protected RubyScope(RubyScope/*!*/ parent, RuntimeFlowControl/*!*/ runtimeFlowControl, object selfObject) {
     Assert.NotNull(parent);
     _parent = parent;
     _top = parent.Top;
     _selfObject = selfObject;
     _runtimeFlowControl = runtimeFlowControl;
     _methodAttributes = RubyMethodAttributes.PrivateInstance;
 }
Beispiel #27
0
        internal static RubyTopLevelScope/*!*/ CreateWrappedTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context) {
            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false, false);
            
            RubyModule module = context.CreateModule(null, null, null, null, null, null, null, ModuleRestrictions.None);
            RubyObject mainObject = new RubyObject(context.ObjectClass);
            context.CreateMainSingleton(mainObject, new[] { module });

            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, module, null, mainObject);
            scope.SetDebugName("top-level-wrapped");

            return scope;
        }
Beispiel #28
0
        internal static RubyTopLevelScope/*!*/ CreateMainTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context) {
            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false);

            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, new RuntimeFlowControl(), rubyGlobalScope.MainObject);
            scope.SetDebugName("top-main");
            context.ObjectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope));

            return scope;
        }
Beispiel #29
0
 internal RubyTopLevelScope /*!*/ SetTopLocalScope(RubyTopLevelScope /*!*/ scope)
 {
     return(Interlocked.CompareExchange(ref _topLocalScope, scope, null));
 }
Beispiel #30
0
        internal static RubyTopLevelScope/*!*/ CreateTopLevelScope(Scope/*!*/ globalScope, RubyContext/*!*/ context, bool isMain) {
            RubyGlobalScope rubyGlobalScope = context.InitializeGlobalScope(globalScope, false, false);

            RubyTopLevelScope scope = new RubyTopLevelScope(rubyGlobalScope, null, null, rubyGlobalScope.MainObject);
            if (isMain) {
                scope.SetDebugName("top-main");
                context.ObjectClass.SetConstant("TOPLEVEL_BINDING", new Binding(scope));
            } else {
                scope.SetDebugName("top-required");
            }

            return scope;
        }