示例#1
0
        public void Can_Have_Block_Inside_Function()
        {
            var syms = new Symbols();

            syms.DefineVariable("a");
            syms.Global.DefineFunction(SymbolTestsHelper.ToFunction("add", 2, new string[] { "a", "b" }, LTypes.Object));

            // func
            var sf = new SymbolsFunction("add", syms.Global);

            syms.Push(sf, true);

            // block in func
            var sb = new SymbolsNested("block", sf);

            syms.Push(sb, true);

            // put variable c in block in function
            syms.DefineVariable("c");

            Assert.IsFalse(syms.Global.Contains("c"));
            Assert.IsFalse(sf.Contains("c"));
            Assert.IsTrue(sb.Contains("c"));
            Assert.IsTrue(syms.Contains("c"));
            Assert.IsTrue(syms.Current.Contains("c"));
        }
示例#2
0
        private ISymbols GetNested()
        {
            var symg = new SymbolsGlobal();

            symg.DefineVariable("a");
            symg.DefineVariable("c");
            symg.DefineFunction(SymbolTestsHelper.ToFunction("add", 2, new string[] { "a", "b" }, LTypes.Object));

            var symn = new SymbolsFunction("add", symg);

            symn.DefineVariable("a");
            symn.DefineVariable("b");
            return(symn);
        }
示例#3
0
        public void Can_Get_Function_Symbol()
        {
            var syms = new SymbolsGlobal();

            syms.DefineFunction(SymbolTestsHelper.ToFunction("add", 2, new string[] { "a", "b" }, LTypes.Object));
            var sym = syms.GetSymbol <SymbolFunction>("add");

            Assert.AreEqual(sym.Name, "add");
            Assert.AreEqual(sym.DataType.TypeVal, LTypes.Function.TypeVal);
            Assert.AreEqual(sym.Category, "func");
            Assert.AreEqual(sym.Meta.TotalArgs, 2);
            Assert.AreEqual(sym.Meta.Arguments[0].Name, "a");
            Assert.AreEqual(sym.Meta.Arguments[1].Name, "b");
            Assert.AreEqual(sym.Meta.ReturnType, LTypes.Object);
        }
示例#4
0
        public void Can_Define_Vars()
        {
            var syms = new Symbols();

            syms.DefineVariable("a");
            syms.DefineVariable("c");
            syms.Global.DefineFunction(SymbolTestsHelper.ToFunction("add", 2, new string[] { "a", "b" }, LTypes.Object));
            syms.Push(new SymbolsFunction("add"), true);
            syms.DefineVariable("d");

            Assert.IsFalse(syms.Global.Contains("d"));
            Assert.IsTrue(syms.Current.Contains("d"));
            Assert.IsTrue(syms.Contains("d"));
            Assert.IsTrue(syms.Global.Contains("a"));
            Assert.IsTrue(syms.Contains("a"));
        }