protected GenScope(Rila runtime) { Runtime = runtime; Definitions = new Dictionary <string, DLR.ParameterExpression>(); BreakTarget = DLR.Expression.Label("@break"); ContinueTarget = DLR.Expression.Label("@continue"); }
public void ExecuteBasicOperations() { var code = File.ReadAllText("TestPrograms/ETGen/basic.rila"); var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 100); }
public void BasicFunction() { var code = File.ReadAllText("TestPrograms/ETGen/basic_function.rila"); var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 10); }
public void Booleans() { var code = "not(not true and false)"; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == true); }
public void ReferenceVariableAfterScopeShouldThrow() { var code = File.ReadAllText("TestPrograms/ETGen/reference_destroyed_variable.rila"); var engine = Rila.CreateRilaEngine(); Func <dynamic> wrapper = () => engine.Execute(code); Assert.Throws <SyntaxErrorException>(wrapper); }
public void RangeOperationWithNonNumericalTypesThrows() { var code = "5..true"; var engine = Rila.CreateRilaEngine(); Func <dynamic> wrapper = () => engine.Execute(code); Assert.Throws <RuntimeBinderException>(wrapper); }
public void RangeOperationWithBadParamsThrows() { var code = "5..4"; var engine = Rila.CreateRilaEngine(); Func <dynamic> wrapper = () => engine.Execute(code); Assert.Throws <ArgumentException>(wrapper); }
public void DuplicateAliasThrows() { var code = @" use System as sys use System.Text as sys "; var engine = Rila.CreateRilaEngine(); Action action = () => engine.Execute(code); Assert.Throws <RilaRuntimeException>(action); }
public void ImportingTheSameNamespaceTwiceThrows() { var code = @" use System use System "; var engine = Rila.CreateRilaEngine(); Action action = () => engine.Execute(code); Assert.Throws <RilaRuntimeException>(action); }
public void CreateCellInstance() { var code = @" a = cell(5) a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.IsType <int>(result.Value); }
public void TypeOfWorksWithAlias() { var code = @" use System.Text as text typeof(text.StringBuilder) "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result.Name == "StringBuilder"); }
public void NewExpressionWithAlias() { var code = @" use System.Text as text a = new text.StringBuilder(5, 10) a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.IsType <StringBuilder>(result); }
public void TypeOfReturnsCorrectType() { var code = @" use System.Text typeof(StringBuilder) "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result.Name == "StringBuilder"); }
public void StaticMemberAccessWithAlias() { var code = @" use System as sys a = sys.String.Empty a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.IsType <string>(result); }
public void StaticCallWithAlias() { var code = @" use System as sys a = sys.Guid.NewGuid() a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.IsType <Guid>(result); }
public void GetIndex() { var code = @" use System a = Array.CreateInstance(typeof(Int32), 10) a[5] "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 0); }
public void NewExpressionWithoutArguments() { var code = @" use System.Text a = new StringBuilder() a.Append(""test"") a.ToString() "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == "test"); }
public void ProgramAlwaysReturnsAValue() { var code = @" a = 10 if a > 10 a = 5 "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result is null); }
public void DotExpressionSetMember() { var code = @" use System.Net o = new Cookie() o.Comment = ""test"" o.Comment "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == "test"); }
public void RangeOperationWithEqualParamsCantMoveNext() { var code = "5..5"; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result is RangeIterator <int>); var enumerator = result.GetEnumerator(); enumerator.MoveNext(); Assert.True(enumerator.Current == 5); Assert.True(enumerator.MoveNext() == false); }
public void ForLoopWithRange() { var code = @" a = 0 b = 10 for i in 0..b a = i a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 10); }
public void MultipleReturnsFunction() { var code = @" fun IsBiggerThanTen(number) if number > 10 return true else return false IsBiggerThanTen(10) "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == false); }
public void RangeOperationReturnsEnumerable() { var code = "10..21"; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result is RangeIterator <int>); var enumerator = result.GetEnumerator(); Assert.True(enumerator.Current == 0); while (enumerator.MoveNext()) { } Assert.True(enumerator.Current == 21); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("No file provided. Exiting..."); return; } try { var engine = Rila.CreateRilaEngine(); engine.ExecuteFile(args[0]); } catch (Exception e) { Console.Error.WriteLine(e.Message); } }
public void ForLoopWithIfs() { var code = @" a = 0 for i in 0..10 if i % 2 == 0 a = a + i else a = a + 1 a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 35); }
public void RangeOperationWorksWithNestedExpressions() { var code = "0..5+5"; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result is RangeIterator <int>); var enumerator = result.GetEnumerator(); Assert.True(enumerator.Current == 0); while (enumerator.MoveNext()) { } Assert.True(enumerator.Current == 10); }
public void ForLoopBreak() { var code = @" a = 0 for i in 0..10 if i == 5 break a = i a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 4); }
public void ForLoopContinue() { var code = @" a = 0 for i in 0..10 if i % 2 == 0 continue a = 9 a "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 9); }
public void NotUsingAtSignDoesntCaptureCell() { var code = @" a = cell(5) b = cell(5) signal = { @a.Value + b.Value + 1 } a.Value = 2 a.Value = 3 b.Value = 3 signal.Value "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 9); }
public void IntSignal() { var code = @" a = cell(5) b = cell(5) signal = { @a.Value + @b.Value + 1 } a.Value = 2 a.Value = 3 b.Value = 3 signal.Value "; var engine = Rila.CreateRilaEngine(); var result = engine.Execute(code); Assert.True(result == 7); }