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); }
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); }
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); }
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); }
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>); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }