Exemple #1
0
        public void MaxStackSizeNoThrow()
        {
            var nothing = new LambdaCompiler.Nothing();
            var binder  = new Binder <LambdaCompiler.Nothing> {
                MaxStackSize = 21
            };

            LambdaCompiler.BindFunctions(binder);
            var lambda = LambdaCompiler.Compile(nothing, binder, @"
var(@recursions, 0)
var(@my-func, function({
  set(@recursions,+(recursions,1))
  if(lt(recursions,20),{
    my-func()
  })
}))
my-func()
");

            // Should NOT throw!
            lambda();

            // Verifying instance is NOT deeply bound!
            Assert.AreEqual(false, binder.DeeplyBound);
        }
Exemple #2
0
        public void MaxStackSizeThrows()
        {
            var nothing = new LambdaCompiler.Nothing();
            var binder  = new Binder <LambdaCompiler.Nothing>();

            binder.MaxStackSize = 19;
            LambdaCompiler.BindFunctions(binder);
            var lambda = LambdaCompiler.Compile(nothing, binder, @"
var(@recursions, 0)
var(@my-func, function({
  set(@recursions,+(recursions,1))
  if(lt(recursions,20),{
    my-func()
  })
}))
my-func()
");
            // SHOULD throw!
            var success = false;

            try {
                lambda();
            } catch {
                success = true;
            }
            Assert.AreEqual(true, success);
        }
Exemple #3
0
        public async Task InlineFloatingPointInScientificNotationWithNegativeExponentSymbol()
        {
            var code      = "5767e-2";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();
            var result    = await function(ctx, binder);

            Assert.AreEqual(57.67, result);
        }
Exemple #4
0
        public void InlineIntegerSymbol()
        {
            var code      = "57";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();
            var result    = function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #5
0
        public async Task Body()
        {
            var code      = "{57}";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();
            var result    = await function(ctx, binder);

            Assert.IsTrue(result is FunctionAsync <LambdaCompiler.Nothing>);
        }
Exemple #6
0
        public void InlineFloatingPointInScientificNotationSymbol()
        {
            var code      = "57.67e2";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();
            var result    = function(ctx, binder);

            Assert.AreEqual(5767.0, result);
        }
Exemple #7
0
        public async Task InlineStringSymbol()
        {
            var code      = @"""57""";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();
            var result    = await function(ctx, binder);

            Assert.AreEqual("57", result);
        }
Exemple #8
0
        public void ModuloMultipleIntegerNumbers()
        {
            var code      = "%(13, 10, 2)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["%"] = Functions <LambdaCompiler.Nothing> .Modulo;
            var result = function(ctx, binder);

            Assert.AreEqual(1, result);
        }
Exemple #9
0
        public void SymbolicallyReferencedConstantString()
        {
            var code      = "foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["foo"] = "bar";
            var result = function(ctx, binder);

            Assert.AreEqual("bar", result);
        }
Exemple #10
0
        public async Task SubtractTwoIntegers()
        {
            var code      = "-(67, 10)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["-"] = Functions <LambdaCompiler.Nothing> .Subtract;
            var result = await function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #11
0
        public void SubtractMultipleIntegers()
        {
            var code      = "-(77, 10, 5, 5)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["-"] = Functions <LambdaCompiler.Nothing> .Subtract;
            var result = function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #12
0
        public void ConcatenateStrings()
        {
            var code      = @"+(""hello"", "" "", ""worl"",""d"")";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["+"] = Functions <LambdaCompiler.Nothing> .Add;
            var result = function(ctx, binder);

            Assert.AreEqual("hello world", result);
        }
Exemple #13
0
        public void AddMultipleFloatingPointValues()
        {
            var code      = "+(7.0, 30.0, 5.47, 15.10)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["+"] = Functions <LambdaCompiler.Nothing> .Add;
            var result = function(ctx, binder);

            Assert.AreEqual(57.57, result);
        }
Exemple #14
0
        public void AddMultipleIntegers()
        {
            var code      = "+(7, 30, 5, 15)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["+"] = Functions <LambdaCompiler.Nothing> .Add;
            var result = function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #15
0
        public void DivideMultipleFloatingPointNumbers()
        {
            var code      = "/(100.1, 5, 2)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["/"] = Functions <LambdaCompiler.Nothing> .Divide;
            var result = function(ctx, binder);

            Assert.AreEqual(10.01, result);
        }
Exemple #16
0
        public void MultiplyMultipleIntegers()
        {
            var code      = "*(5, 7, 2)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["*"] = Functions <LambdaCompiler.Nothing> .Multiply;
            var result = function(ctx, binder);

            Assert.AreEqual(70, result);
        }
Exemple #17
0
        public async Task ModuloTwoIntegerNumbers()
        {
            var code      = "%(7, 5)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["%"] = Functions <LambdaCompiler.Nothing> .Modulo;
            var result = await function(ctx, binder);

            Assert.AreEqual(2, result);
        }
Exemple #18
0
        public async Task DivideTwoFloatingPointNumbers()
        {
            var code      = "/(24.8, 8)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["/"] = Functions <LambdaCompiler.Nothing> .Divide;
            var result = await function(ctx, binder);

            Assert.AreEqual(3.1, result);
        }
Exemple #19
0
        public async Task MultiplyTwoIntegers()
        {
            var code      = "*(5, 7)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["*"] = Functions <LambdaCompiler.Nothing> .Multiply;
            var result = await function(ctx, binder);

            Assert.AreEqual(35, result);
        }
Exemple #20
0
        public async Task AddTwoIntegers()
        {
            var code      = "+(10, 57)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["+"] = Functions <LambdaCompiler.Nothing> .Add;
            var result = await function(ctx, binder);

            Assert.AreEqual(67, result);
        }
Exemple #21
0
        public async Task LiterallyReferencingSymbolName()
        {
            var code      = "@foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["foo"] = 57;
            var result = await function(ctx, binder);

            Assert.AreEqual("foo", result);
        }
Exemple #22
0
        public async Task SymbolicallyReferencedConstantInteger()
        {
            var code      = "foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["foo"] = 57;
            var result = await function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #23
0
        public async Task SymbolicallyReferencedComplexType()
        {
            var code      = "foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["foo"] = new LambdaCompiler.Nothing();
            var result = await function(ctx, binder);

            Assert.IsTrue(result is LambdaCompiler.Nothing);
        }
Exemple #24
0
        public void VariableAssignedToIntegerValue()
        {
            var code      = @"
var(@foo, 57)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["var"] = Functions <LambdaCompiler.Nothing> .Var;
            var result = function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #25
0
        public async Task VariableAssignedToFloatingPointValue()
        {
            var code      = @"
var(@foo, 57.67)";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["var"] = Functions <LambdaCompiler.Nothing> .Var;
            var result = await function(ctx, binder);

            Assert.AreEqual(57.67, result);
        }
Exemple #26
0
        public void SymbolicallyReferencedFunctionInvocationReturningComplexType()
        {
            var code      = "foo()";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["foo"] = new Function <LambdaCompiler.Nothing>((ctx2, binder2, arguments) => {
                return(new LambdaCompiler.Nothing());
            });
            var result = function(ctx, binder);

            Assert.IsTrue(result is LambdaCompiler.Nothing);
        }
Exemple #27
0
        public async Task VariableDeclarationWithoutInitialAssignment()
        {
            var code      = @"
var(@foo)
foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["var"] = Functions <LambdaCompiler.Nothing> .Var;
            var result = await function(ctx, binder);

            Assert.IsNull(result);
        }
Exemple #28
0
        public async Task VariableDeReferenced()
        {
            var code      = @"
var(@foo, 57)
foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["var"] = Functions <LambdaCompiler.Nothing> .Var;
            var result = await function(ctx, binder);

            Assert.AreEqual(57, result);
        }
Exemple #29
0
        public async Task VariableAssignedToStringLiteralValue()
        {
            var code      = @"
var(@foo, ""bar"")
foo";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["var"] = Functions <LambdaCompiler.Nothing> .Var;
            var result = await function(ctx, binder);

            Assert.AreEqual("bar", result);
        }
Exemple #30
0
        public async Task SymbolicallyReferencedFunctionInvocationReturningInteger()
        {
            var code      = "foo()";
            var tokenizer = new Tokenizer(new LizzieTokenizer());
            var function  = Compiler.Compile <LambdaCompiler.Nothing>(tokenizer, code);
            var ctx       = new LambdaCompiler.Nothing();
            var binder    = new Binder <LambdaCompiler.Nothing>();

            binder["foo"] = new FunctionAsync <LambdaCompiler.Nothing>((ctx2, binder2, arguments) =>
            {
                return(Task.FromResult((object)57));
            });
            var result = await function(ctx, binder);

            Assert.AreEqual(57, result);
        }