public IInterpreter InitializingWithGetter() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { DebugThrowOnError = true } .SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.Create("Point") .With(PropertyBuilder.CreateAutoGetter(env.Options, "x", NameFactory.Nat8NameReference())) .With(FunctionBuilder.CreateInitConstructor(Block.CreateStatement( Assignment.CreateStatement(NameReference.CreateThised("x"), Nat8Literal.Create("5")) )))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("p", null, ExpressionFactory.StackConstructor(NameReference.Create("Point"))), Return.Create(NameReference.Create(NameReference.Create("p"), "x")) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)5, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter DereferenceOnIfCondition() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { DebugThrowOnError = true, AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("ptr", NameFactory.PointerNameReference(NameFactory.BoolNameReference()), ExpressionFactory.HeapConstructor(NameFactory.BoolNameReference(), FunctionArgument.Create(BoolLiteral.CreateTrue()))), Return.Create(IfBranch.CreateIf(NameReference.Create("ptr"), new[] { Int64Literal.Create("2") }, IfBranch.CreateElse(new[] { Int64Literal.Create("5") }))), }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter InstanceCallStaticDispatch() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; Extension ext = root_ns.AddNode(Extension.Create()); ext.AddBuilder(FunctionBuilder.Create("paf", NameFactory.Nat8NameReference(), Block.CreateStatement( Return.Create(ExpressionFactory.Mul("x", "x")))) .Parameters(FunctionParameter.Create("x", NameFactory.ReferenceNameReference(NameFactory.Nat8NameReference()), EntityModifier.This))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("i", null, Nat8Literal.Create("5")), Return.Create(FunctionCall.Create(NameReference.Create("i", "paf"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)25, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter DateDayOfWeek() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.NatNameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("d", null, ExpressionFactory.StackConstructor(NameFactory.DateNameReference(), // it is Friday Int16Literal.Create("2017"), Nat8Literal.Create("12"), Nat8Literal.Create("29"))), VariableDeclaration.CreateStatement("i", null, FunctionCall.ConvCall(NameReference.Create("d", NameFactory.DateDayOfWeekProperty), NameFactory.NatNameReference())), Return.Create(NameReference.Create("i")) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(5UL, result.RetValue.PlainValue); } return(interpreter); }
public void Create(params string[] lines) { _textView = CreateTextView(lines); _textView.Caret.MoveTo(new SnapshotPoint(_textView.TextSnapshot, 0)); _textBuffer = _textView.TextBuffer; _factory = new MockRepository(MockBehavior.Strict); _editOpts = _factory.Create <IEditorOperations>(); _vimHost = _factory.Create <IVimHost>(); _vimHost.Setup(x => x.IsDirty(It.IsAny <ITextBuffer>())).Returns(false); _operations = _factory.Create <ICommonOperations>(); _operations.SetupGet(x => x.EditorOperations).Returns(_editOpts.Object); _statusUtil = _factory.Create <IStatusUtil>(); _fileSystem = _factory.Create <IFileSystem>(MockBehavior.Strict); _foldManager = _factory.Create <IFoldManager>(MockBehavior.Strict); _vimData = new VimData(); _vim = MockObjectFactory.CreateVim(RegisterMap, host: _vimHost.Object, vimData: _vimData, factory: _factory); var localSettings = new LocalSettings(Vim.GlobalSettings); var vimTextBuffer = MockObjectFactory.CreateVimTextBuffer( _textBuffer, vim: _vim.Object, localSettings: localSettings, factory: _factory); var vimBufferData = CreateVimBufferData( vimTextBuffer.Object, _textView, statusUtil: _statusUtil.Object); var vimBuffer = CreateVimBuffer(vimBufferData); _interpreter = new Interpreter.Interpreter( vimBuffer, _operations.Object, _foldManager.Object, _fileSystem.Object, _factory.Create <IBufferTrackingService>().Object); }
public IInterpreter RealDividingByZeroWithoutNaNs() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true, DiscardingAnyExpressionDuringTests = true } .SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("a", null, Real64Literal.Create(5.0)), VariableDeclaration.CreateStatement("b", null, Real64Literal.Create(0.0)), ExpressionFactory.Readout(ExpressionFactory.Divide("a", "b")), Return.Create(Nat8Literal.Create("2")) ))); ExecValue result = interpreter.TestRun(env); Assert.IsTrue(result.IsThrow); } return(interpreter); }
public IInterpreter ResultTypeInference() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; IExpression lambda = FunctionBuilder.CreateLambda(null, Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("2")) })).Build(); root_ns.AddBuilder(FunctionBuilder.Create("main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { // f = () => x VariableDeclaration.CreateStatement("f", null, lambda), // return f() Return.Create(FunctionCall.Create(NameReference.Create("f"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter ChannelDeadLockOnReceive() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("ch", null, ExpressionFactory.HeapConstructor(NameFactory.ChannelNameReference(NameFactory.Int64NameReference()))), ExpressionFactory.Readout(FunctionCall.Create(NameReference.Create("ch", NameFactory.ChannelReceive))), Return.Create(Int64Literal.Create("0")) }))); int task_id = Task.WaitAny(Task.Delay(TimeSpan.FromSeconds(Interpreter.Interpreter.TimeoutSeconds)), interpreter.TestRunAsync(env)); Assert.AreEqual(0, task_id); } return(interpreter); }
public IInterpreter StringToInt() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true, AllowInvalidMainResult = true } .SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("s", null, StringLiteral.Create("2")), VariableDeclaration.CreateStatement("i", NameFactory.Int64NameReference(), ExpressionFactory.GetOptionValue( FunctionCall.Create(NameReference.Create(NameFactory.Int64NameReference(), NameFactory.ParseFunctionName), NameReference.Create("s")) )), Return.Create(NameReference.Create("i")) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter NoMutability() { var env = Environment.Create(new Options() { DebugThrowOnError = true } .SetMutability(MutabilityModeOption.OnlyAssignability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("a", NameFactory.Nat8NameReference(TypeMutability.ForceMutable), Nat8Literal.Create("2"), env.Options.ReassignableModifier()), VariableDeclaration.CreateStatement("b", NameFactory.Nat8NameReference(TypeMutability.ForceConst), Nat8Literal.Create("13")), Assignment.CreateStatement(NameReference.Create("a"), NameReference.Create("b")), Return.Create(NameReference.Create("a")) ))); var interpreter = new Interpreter.Interpreter(); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)13, result.RetValue.PlainValue); return(interpreter); }
public IInterpreter GenericTypeAliasing() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.Create(NameDefinition.Create("Point", "V", VarianceMode.None)) .With(Alias.Create("VType", NameReference.Create("V"), EntityModifier.Public))); VariableDeclaration decl = VariableDeclaration.CreateStatement("x", NameReference.Create("p", "VType"), Undef.Create(), env.Options.ReassignableModifier()); root_ns.AddBuilder(FunctionBuilder.Create("main", NameFactory.Nat8NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("p", null, ExpressionFactory.StackConstructor(NameReference.Create("Point", NameFactory.Nat8NameReference()))), decl, Assignment.CreateStatement(NameReference.Create("x"), Nat8Literal.Create("5")), Return.Create(NameReference.Create("x")) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)5, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter OldSchoolSwapPointers() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true, AllowDereference = true } .SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create("swap", "T", VarianceMode.None, NameFactory.UnitNameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("t", NameReference.Create("T"), NameReference.Create("a")), Assignment.CreateStatement(Dereference.Create(NameReference.Create("a")), NameReference.Create("b")), Assignment.CreateStatement(Dereference.Create(NameReference.Create("b")), NameReference.Create("t")) )) .Constraints(ConstraintBuilder.Create("T") .SetModifier(env.Options.ReassignableModifier())) .Parameters(FunctionParameter.Create("a", NameFactory.ReferenceNameReference("T")), FunctionParameter.Create("b", NameFactory.ReferenceNameReference("T")))); VariableDeclaration decl_a = VariableDeclaration.CreateStatement("a", null, ExpressionFactory.HeapConstructor(env.Options.ReassignableTypeMutability(), NameFactory.Nat8NameReference(), Nat8Literal.Create("2"))); FunctionCall swap_call = FunctionCall.Create("swap", AddressOf.CreateReference(NameReference.Create("a")), AddressOf.CreateReference(NameReference.Create("b"))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement( decl_a, VariableDeclaration.CreateStatement("b", null, ExpressionFactory.HeapConstructor(env.Options.ReassignableTypeMutability(), NameFactory.Nat8NameReference(), Nat8Literal.Create("17"))), VariableDeclaration.CreateStatement("c", null, NameReference.Create("a")), swap_call, // here `c` still points to value of original `a` Return.Create(ExpressionFactory.Sub("a", "c")) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)15, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter FileExists() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true, AllowInvalidMainResult = true } .SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("e", null, FunctionCall.Create(NameReference.Create(NameFactory.FileNameReference(), NameFactory.FileExists), StringLiteral.Create(randomTextFilePath))), IfBranch.CreateIf(NameReference.Create("e"), new[] { Return.Create(Int64Literal.Create("2")) }, IfBranch.CreateElse(new[] { Return.Create(Int64Literal.Create("-5")) })) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter RawMethods() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { Return.Create(FunctionCall.Create(NameReference.Create(Int64Literal.Create("1"), NameFactory.AddOperator), FunctionArgument.Create(Int64Literal.Create("1")))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter RealNotANumber() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { // at this point Skila adheres to the standard but maybe should raise an exception for every NaN // and this way remove them from the language (similarly to null pointers) // https://stackoverflow.com/questions/5394424/causes-for-nan-in-c-application-that-do-no-raise-a-floating-point-exception // https://stackoverflow.com/questions/2941611/can-i-make-gcc-tell-me-when-a-calculation-results-in-nan-or-inf-at-runtime var env = Environment.Create(new Options() { DebugThrowOnError = true, AllowRealMagic = true }.SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("a", null, Real64Literal.Create(double.NaN)), VariableDeclaration.CreateStatement("b", null, Real64Literal.Create(double.NaN)), Return.Create(ExpressionFactory.Ternary(ExpressionFactory.IsEqual("a", "b"), Nat8Literal.Create("15"), Nat8Literal.Create("2"))) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)2, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter Indexer() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true, DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; IEnumerable <FunctionParameter> property_parameters = new[] { FunctionParameter.Create("idx", NameFactory.Int64NameReference()) }; NameReference property_typename = NameFactory.Int64NameReference(); var point_type = root_ns.AddBuilder(TypeBuilder.Create("Point") .SetModifier(EntityModifier.Mutable) .With(Property.CreateIndexer(env.Options, property_typename, new[] { VariableDeclaration.CreateStatement("x", NameFactory.Int64NameReference(), Int64Literal.Create("1"), env.Options.ReassignableModifier()) }, new[] { Property.CreateIndexerGetter(property_typename, property_parameters, Block.CreateStatement(IfBranch.CreateIf(ExpressionFactory.IsEqual(NameReference.Create("idx"), Int64Literal.Create("17")), new[] { Return.Create(NameReference.CreateThised("x")) }, IfBranch.CreateElse(new[] { Return.Create(Int64Literal.Create("300")) })))) }, new[] { Property.CreateIndexerSetter(property_typename, property_parameters, Block.CreateStatement(IfBranch.CreateIf(ExpressionFactory.IsEqual(NameReference.Create("idx"), Int64Literal.Create("17")), new[] { Assignment.CreateStatement(NameReference.CreateThised("x"), NameReference.Create(NameFactory.PropertySetterValueParameter)) }))) } ))); var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { // p = Point() // p.x is initialized with 1 VariableDeclaration.CreateStatement("p", null, ExpressionFactory.StackConstructor(NameReference.Create("Point"))), // p[17] = 1+p[17] Assignment.CreateStatement(FunctionCall.Indexer(NameReference.Create("p"), FunctionArgument.Create(Int64Literal.Create("17"))), FunctionCall.Create(NameReference.Create(Int64Literal.Create("1"), NameFactory.AddOperator), FunctionArgument.Create(FunctionCall.Indexer(NameReference.Create("p"), FunctionArgument.Create(Int64Literal.Create("17")))))), // return p[17] Return.Create(FunctionCall.Indexer(NameReference.Create("p"), FunctionArgument.Create(Int64Literal.Create("17")))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter TypeIntersection() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { AllowInvalidMainResult = true, DebugThrowOnError = true, AllowProtocols = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.CreateInterface("IGetPos") .With(FunctionBuilder.CreateDeclaration("getSome", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()))); root_ns.AddBuilder(TypeBuilder.CreateInterface("IGetNeg") .With(FunctionBuilder.CreateDeclaration("getMore", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()))); root_ns.AddBuilder(TypeBuilder.Create("GetAll") .Parents("IGetPos", "IGetNeg") .With(FunctionBuilder.Create("getSome", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("3")) })) .SetModifier(EntityModifier.Override) ) .With(FunctionBuilder.Create("getMore", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("-1")) })) .SetModifier(EntityModifier.Override) )); NameReferenceIntersection intersection = NameReferenceIntersection.Create( NameFactory.PointerNameReference(NameReference.Create("IGetNeg")), NameFactory.PointerNameReference(NameReference.Create("IGetPos"))); var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("a", intersection, Undef.Create(), env.Options.ReassignableModifier()), VariableDeclaration.CreateStatement("b", intersection, Undef.Create(), env.Options.ReassignableModifier()), Assignment.CreateStatement(NameReference.Create("a"), ExpressionFactory.HeapConstructor("GetAll")), Assignment.CreateStatement(NameReference.Create("b"), ExpressionFactory.HeapConstructor("GetAll")), VariableDeclaration.CreateStatement("x", null, FunctionCall.Create(NameReference.Create("a", "getSome"))), VariableDeclaration.CreateStatement("y", null, FunctionCall.Create(NameReference.Create("b", "getMore"))), Return.Create(ExpressionFactory.Add(NameReference.Create("x"), NameReference.Create("y"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter OptionalNoLimitsVariadicFunction() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create("provider", NameFactory.ChunkNameReference(NameFactory.Int64NameReference()), Block.CreateStatement( VariableDeclaration.CreateStatement("x", null, ExpressionFactory.StackConstructor(NameFactory.ChunkNameReference(NameFactory.Int64NameReference()), FunctionArgument.Create(NatLiteral.Create("2")))), Assignment.CreateStatement(FunctionCall.Indexer(NameReference.Create("x"), FunctionArgument.Create(NatLiteral.Create("0"))), Int64Literal.Create("-6")), Assignment.CreateStatement(FunctionCall.Indexer(NameReference.Create("x"), FunctionArgument.Create(NatLiteral.Create("1"))), Int64Literal.Create("8")), Return.Create(NameReference.Create("x")) ))); root_ns.AddBuilder(FunctionBuilder.Create( "sum", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { // let i0 = n.at(0) VariableDeclaration.CreateStatement("i0", null, FunctionCall.Create(NameReference.Create("n", NameFactory.PropertyIndexerName), FunctionArgument.Create(NatLiteral.Create("0")))), // let i1 = n.at(1) VariableDeclaration.CreateStatement("i1", null, FunctionCall.Create(NameReference.Create("n", NameFactory.PropertyIndexerName), FunctionArgument.Create(NatLiteral.Create("1")))), // return i0+i1 Return.Create(ExpressionFactory.Add("i0", "i1")) })) .Parameters(FunctionParameter.Create("n", NameFactory.Int64NameReference(), Variadic.Create(), FunctionCall.Create(NameReference.Create("provider")), isNameRequired: false))); var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { Return.Create(FunctionCall.Create(NameReference.Create("sum"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter CallingTraitMethodViaInterface() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true, AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.CreateInterface("ISay") .With(FunctionBuilder.CreateDeclaration("say", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()))); root_ns.AddBuilder(TypeBuilder.Create("Say") .With(FunctionBuilder.Create("say", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("7")) })) .SetModifier(EntityModifier.Override)) .Parents("ISay")); root_ns.AddBuilder(TypeBuilder.Create("Greeter", "T")); root_ns.AddBuilder(TypeBuilder.Create("Greeter", "X") .Constraints(ConstraintBuilder.Create("X").Inherits("ISay")) .SetModifier(EntityModifier.Trait) .Parents("ISay") .With(FunctionBuilder.Create("say", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement( Return.Create(Int64Literal.Create("2")) )).SetModifier(EntityModifier.Override))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement( // crucial point, we store our object as interface *ISay VariableDeclaration.CreateStatement("g", NameFactory.PointerNameReference("ISay"), ExpressionFactory.HeapConstructor(NameReference.Create("Greeter", NameReference.Create("Say")))), // we call method "say" implemented in trait Return.Create(FunctionCall.Create(NameReference.Create("g", "say"))) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public void CanPlayArpeggiatedDefault() { var builder = new ScoreBuilder.ScoreBuilder(new FileStream(EtudeNo1ScoreFilePath, FileMode.Open, FileAccess.Read)); var score = builder.Build(); var interpreter = new Interpreter.Interpreter(); interpreter.SetScore(score, EtudeNo1ScoreFilePath); interpreter.SeekMeasure(21); var playedPitches = new List <byte>(); interpreter.Output += (IPianoEvent e) => { if (e is NotePress press) { playedPitches.Add(press.Pitch); } }; playedPitches.Should().BeEmpty(); interpreter.Input(new NotePress() { Pitch = "D6".ToPitch(), Velocity = 100 }); playedPitches.Should().BeEquivalentTo(new byte[] { "C4".ToPitch() }); interpreter.Input(new NotePress() { Pitch = "E6".ToPitch(), Velocity = 100 }); playedPitches.Should().BeEquivalentTo(new byte[] { "C4".ToPitch(), "E4".ToPitch() }); interpreter.Input(new NotePress() { Pitch = "F6".ToPitch(), Velocity = 100 }); playedPitches.Should().BeEquivalentTo(new byte[] { "C4".ToPitch(), "E4".ToPitch(), "G4".ToPitch() }); interpreter.Input(new NotePress() { Pitch = "G6".ToPitch(), Velocity = 100 }); playedPitches.Should().BeEquivalentTo(new byte[] { "C4".ToPitch(), "E4".ToPitch(), "G4".ToPitch(), "C5".ToPitch() }); }
public IInterpreter InitializationWithOptionalAssignment() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { DebugThrowOnError = true, DiscardingAnyExpressionDuringTests = true, }.SetMutability(mutability)); var root_ns = env.Root; // this test is a bit tougher than regular opt.assignment, because variables will be // initialized for the first time with this assigment root_ns.AddBuilder(FunctionBuilder.Create("main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement( VariableDeclaration.CreateStatement("acc", null, Nat8Literal.Create("0"), env.Options.ReassignableModifier()), VariableDeclaration.CreateStatement("x", null, ExpressionFactory.OptionOf(NameFactory.Nat8NameReference(), Nat8Literal.Create("3"))), VariableDeclaration.CreateStatement("z", null, ExpressionFactory.OptionOf(NameFactory.Nat8NameReference(), Nat8Literal.Create("5"))), VariableDeclaration.CreateStatement("a", NameFactory.Nat8NameReference(), null, env.Options.ReassignableModifier()), VariableDeclaration.CreateStatement("b", NameFactory.Nat8NameReference(), null, env.Options.ReassignableModifier()), IfBranch.CreateIf(ExpressionFactory.OptionalAssignment( new[] { NameReference.Create("a"), NameReference.Create("b") }, new[] { NameReference.Create("x"), NameReference.Create("z") }), new[] { // assign tracker should recognize the variable is initialized ExpressionFactory.IncBy("acc", NameReference.Create("a")), }, // making else branch a dead one IfBranch.CreateElse(ExpressionFactory.GenericThrow())), // assign tracker should recognize the variable is initialized (because `else` branch of above `if` is dead) ExpressionFactory.IncBy("acc", NameReference.Create("b")), Return.Create(NameReference.Create("acc")) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)8, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter InheritingEnums() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { AllowInvalidMainResult = true, DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.CreateEnum("Weekend") .With(EnumCaseBuilder.Create("Sat", "Sun")) .SetModifier(EntityModifier.Base)); root_ns.AddBuilder(TypeBuilder.CreateEnum("First") .With(EnumCaseBuilder.Create("Mon")) .Parents("Weekend")); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.NatNameReference(), Block.CreateStatement(new IExpression[] { // let a Weekend = First.Sat VariableDeclaration.CreateStatement("a", NameReference.Create("Weekend"), // please note we only refer to "Sat" through "First", the type is still "Weekend" NameReference.Create("First", "Sat")), // var b First = Weekend.Sun VariableDeclaration.CreateStatement("b", NameReference.Create("First"), NameReference.Create("Weekend", "Sun"), env.Options.ReassignableModifier()), // b = First.Mon Assignment.CreateStatement(NameReference.Create("b"), NameReference.Create("First", "Mon")), // let x = a to Nat; // 0 VariableDeclaration.CreateStatement("x", null, FunctionCall.ConvCall(NameReference.Create("a"), NameFactory.NatNameReference())), // let y = b to Nat; // 2 VariableDeclaration.CreateStatement("y", null, FunctionCall.ConvCall(NameReference.Create("b"), NameFactory.NatNameReference())), // return x + y Return.Create(ExpressionFactory.Add(NameReference.Create("x"), NameReference.Create("y"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2UL, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter VirtualCall() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { AllowInvalidMainResult = true, DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.Create("MyBase") .SetModifier(EntityModifier.Base) .With(FunctionBuilder.Create( "bar", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("33")) })) .SetModifier(EntityModifier.Base))); TypeDefinition type_impl = root_ns.AddBuilder(TypeBuilder.Create("SomeChild") .With(FunctionBuilder.Create("bar", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("2")) })) .SetModifier(EntityModifier.Override | EntityModifier.UnchainBase)) .Parents(NameReference.Create("MyBase"))); var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("i", NameFactory.PointerNameReference(NameReference.Create("MyBase")), ExpressionFactory.HeapConstructor(NameReference.Create("SomeChild"))), Return.Create(FunctionCall.Create(NameReference.Create("i", "bar"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter OverridingMethodWithIndexerGetter() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true, DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.CreateInterface("IProvider") .With(FunctionBuilder.CreateDeclaration(NameFactory.PropertyIndexerName, ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference())))); root_ns.AddBuilder(TypeBuilder.Create("Middle") .Parents("IProvider") .SetModifier(EntityModifier.Base) .With(FunctionBuilder.Create(NameFactory.PropertyIndexerName, ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(Return.Create(Int64Literal.Create("500")))) .SetModifier(EntityModifier.Override | EntityModifier.UnchainBase) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), ExpressionReadMode.CannotBeRead)))); root_ns.AddBuilder(TypeBuilder.Create("Last") .Parents("Middle") .SetModifier(EntityModifier.Base) .With(PropertyBuilder.CreateIndexer(env.Options, NameFactory.Int64NameReference()) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), ExpressionReadMode.CannotBeRead)) .With(PropertyMemberBuilder.CreateIndexerGetter(Block.CreateStatement(Return.Create(Int64Literal.Create("2")))) .Modifier(EntityModifier.Override | EntityModifier.UnchainBase)))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("p", NameFactory.PointerNameReference("IProvider"), ExpressionFactory.HeapConstructor("Last")), Return.Create(FunctionCall.Create(NameReference.Create("p", NameFactory.PropertyIndexerName), FunctionArgument.Create(Int64Literal.Create("18")))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter NoExtrasWithCopyConstructor() { // nothing is written in stone, but for now let's treat assignment in declaration as assignment // not copy constructor (as in C++) var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.Create("Point") .SetModifier(EntityModifier.Mutable) .With(FunctionBuilder.CreateInitConstructor(Block.CreateStatement())) // copy-constructor .With(FunctionBuilder.CreateInitConstructor(Block.CreateStatement( Assignment.CreateStatement(NameReference.CreateThised("x"), Nat8Literal.Create("66")) )).Parameters(FunctionParameter.Create("p", NameFactory.ReferenceNameReference("Point"), ExpressionReadMode.CannotBeRead))) .With(PropertyBuilder.Create(env.Options, "x", () => NameFactory.Nat8NameReference()) .With(VariableDeclaration.CreateStatement("f", NameFactory.Nat8NameReference(), null, env.Options.ReassignableModifier())) .WithGetter(Block.CreateStatement(Return.Create(NameReference.CreateThised("f")))) .WithSetter(Block.CreateStatement(Assignment.CreateStatement(NameReference.CreateThised("f"), ExpressionFactory.Mul(NameFactory.PropertySetterValueReference(), Nat8Literal.Create("2"))))))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("p", null, ConstructorCall.StackConstructor(NameReference.Create("Point")) .Init("x", Nat8Literal.Create("7")) .Build()), // bit-copy of the object, there is no calling copy-constructor here VariableDeclaration.CreateStatement("r", null, NameReference.Create("p")), Return.Create(NameReference.Create(NameReference.Create("r"), "x")) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual((byte)14, result.RetValue.PlainValue); } return(interpreter); }
public void CanPlaySequenceOfThreeNotes() { var builder = new ScoreBuilder.ScoreBuilder(new FileStream(EtudeNo1ScoreFilePath, FileMode.Open, FileAccess.Read)); var score = builder.Build(); var outputs = new List <IPianoEvent>(); var interpreter = new Interpreter.Interpreter(); interpreter.SetScore(score, EtudeNo1ScoreFilePath); interpreter.SeekMeasure(1); interpreter.Output += (IPianoEvent e) => { outputs.Add(e); }; var notePress1 = new NotePress() { Pitch = "C5".ToPitch(), Velocity = 65 }; var notePress2 = new NotePress() { Pitch = "D5".ToPitch(), Velocity = 65 }; var notePress3 = new NotePress() { Pitch = "E5".ToPitch(), Velocity = 65 }; interpreter.Input(notePress1); outputs.Should().Contain(new NotePress() { Pitch = "C4".ToPitch(), Velocity = notePress1.Velocity }); interpreter.Input(notePress2); outputs.Should().Contain(new NotePress() { Pitch = "D4".ToPitch(), Velocity = notePress2.Velocity }); interpreter.Input(notePress3); outputs.Should().Contain(new NotePress() { Pitch = "E4".ToPitch(), Velocity = notePress3.Velocity }); }
public IInterpreter CheckingHostTraitRuntimeType() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { DebugThrowOnError = true, AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.CreateInterface("ISay") .With(FunctionBuilder.CreateDeclaration("say", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()))); root_ns.AddBuilder(TypeBuilder.Create("NoSay")); root_ns.AddBuilder(TypeBuilder.Create("Greeter", "T")); root_ns.AddBuilder(TypeBuilder.Create("Greeter", "X") .Constraints(ConstraintBuilder.Create("X").Inherits("ISay")) .SetModifier(EntityModifier.Trait) .Parents("ISay") .With(FunctionBuilder.Create("say", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement( Return.Create(Int64Literal.Create("2")) )).SetModifier(EntityModifier.Override))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement( // just plain host, no trait is used VariableDeclaration.CreateStatement("g", NameFactory.PointerNameReference(NameFactory.IObjectNameReference()), ExpressionFactory.HeapConstructor(NameReference.Create("Greeter", NameReference.Create("NoSay")))), // we should have fail-test here Return.Create(ExpressionFactory.Ternary(IsType.Create(NameReference.Create("g"), NameReference.Create("ISay")), Int64Literal.Create("99"), Int64Literal.Create("2"))) ))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IInterpreter HasConstraintWithValue() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { AllowInvalidMainResult = true, AllowProtocols = true, DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; FunctionDefinition func_constraint = FunctionBuilder.CreateDeclaration("getMe", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()); root_ns.AddBuilder(FunctionBuilder.Create("proxy", TemplateParametersBuffer.Create().Add("T").Values, ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(FunctionCall.Create(NameReference.Create("t", "getMe"))) })) .Constraints(ConstraintBuilder.Create("T").Has(func_constraint)) .Parameters(FunctionParameter.Create("t", NameReference.Create("T")))); TypeDefinition type_impl = root_ns.AddBuilder(TypeBuilder.Create("Y") .With(FunctionBuilder.Create("getMe", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new[] { Return.Create(Int64Literal.Create("2")) })))); FunctionCall call = FunctionCall.Create(NameReference.Create("proxy"), FunctionArgument.Create(NameReference.Create("y"))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("y", null, ExpressionFactory.StackConstructor(NameReference.Create("Y"))), Return.Create(call) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public void CanPlayPedals() { var builder = new ScoreBuilder.ScoreBuilder(new FileStream(EtudeNo1ScoreFilePath, FileMode.Open, FileAccess.Read)); var score = builder.Build(); var interpreter = new Interpreter.Interpreter(); interpreter.SetScore(score, EtudeNo1ScoreFilePath); interpreter.SeekMeasure(0); var pedalChanges = new List <PedalChange>(); interpreter.Output += (IPianoEvent e) => { if (e is PedalChange pedal) { pedalChanges.Add(pedal); } }; pedalChanges.Should().BeEmpty(); var sustainPedalChange = new PedalChange() { Pedal = PedalKind.Sustain, Position = 28 }; var sostenutoPedalChange = new PedalChange() { Pedal = PedalKind.Sostenuto, Position = 28 }; var unaCordaPedalChange = new PedalChange() { Pedal = PedalKind.UnaCorda, Position = 28 }; interpreter.Input(sustainPedalChange); pedalChanges.Should().BeEquivalentTo(new PedalChange[] { sustainPedalChange }); interpreter.Input(sostenutoPedalChange); pedalChanges.Should().BeEquivalentTo(new PedalChange[] { sustainPedalChange, sostenutoPedalChange }); interpreter.Input(unaCordaPedalChange); pedalChanges.Should().BeEquivalentTo(new PedalChange[] { sustainPedalChange, unaCordaPedalChange }); }
public IInterpreter DirectRefCountings() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { DebugThrowOnError = true, AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; var inc_def = root_ns.AddBuilder(FunctionBuilder.Create( "inc", ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { // let temp *Int = n; // n is argument VariableDeclaration.CreateStatement("temp", NameFactory.PointerNameReference(NameFactory.Int64NameReference()), NameReference.Create("n")), // return temp + 1; Return.Create(FunctionCall.Create(NameReference.Create(NameReference.Create("temp"), NameFactory.AddOperator), FunctionArgument.Create(Int64Literal.Create("1")))) })) .Parameters(FunctionParameter.Create("n", NameFactory.PointerNameReference(NameFactory.Int64NameReference())))); var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { // let p_int *Int = new *1; VariableDeclaration.CreateStatement("p_int", NameFactory.PointerNameReference(NameFactory.Int64NameReference()), ExpressionFactory.HeapConstructor(NameFactory.Int64NameReference(), FunctionArgument.Create(Int64Literal.Create("1")))), // let proxy *Int = p_int; VariableDeclaration.CreateStatement("proxy", NameFactory.PointerNameReference(NameFactory.Int64NameReference()), NameReference.Create("p_int")), // return inc(proxy); Return.Create(FunctionCall.Create(NameReference.Create("inc"), FunctionArgument.Create(NameReference.Create("proxy")))), }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public CommandModeTest() { _textView = CreateTextView(); _textBuffer = _textView.TextBuffer; _vimBuffer = CreateVimBuffer(CreateVimBufferData(_textView)); var factory = new MockRepository(MockBehavior.Strict); var commonOperations = CommonOperationsFactory.GetCommonOperations(_vimBuffer.VimBufferData); var interpreter = new Interpreter.Interpreter( _vimBuffer, commonOperations, factory.Create<IFoldManager>().Object, factory.Create<IFileSystem>().Object, factory.Create<IBufferTrackingService>().Object); _modeRaw = new CommandMode(_vimBuffer, commonOperations, interpreter); _mode = _modeRaw; }
static void Main(string[] args) { var interpreter = new Interpreter.Interpreter("quantumplation", "MGBDesign", "DesignValues", "50cf7a7ebcf0093e25bf27a2fe3d010e6e45b5bc"); //var context = new WarpGateContext { Distance = 10 }; //var c = context.Get(interpreter); //Console.WriteLine(string.Join("\n", // $"Constants:", // $"- {nameof(c.BaseLinkTime)}: {c.BaseLinkTime}", // $"- {nameof(c.BaseLoadingTime)}: {c.BaseLoadingTime}", // $"- {nameof(c.BasePayloadTime)}: {c.BaseRange}", // $"- {nameof(c.LinkTime)}: {c.LinkTime}", // $"- {nameof(c.PayloadTime)}: {c.PayloadTime}", // $"- {nameof(c.Range)}: {c.Range}" //)); Console.ReadLine(); }
/// <summary> /// Creates and inits an interpreter instance. /// </summary> /// <param name="program">A brainfuck program</param> /// <returns>the inited interpreter instance</returns> private Interpreter.Interpreter initInterpreter(string program) { Interpreter.Interpreter interpreter = new Interpreter.Interpreter(SharedDefinies.FLAG_WO_GUI | SharedDefinies.FLAG_STOP_ON_ERROR); interpreter.Init("", program, DisplayMode.NO_DISPLAY); return interpreter; }
private ITemplateType EvalMacro(ITemplateType source) { if (source == null) return StringType.Empty(); string obj; if (!source.TryConvert(out obj)) { _errors.ErrorMacrosOnlyAcceptStrings(source.UnderlyingType, string.Empty); return StringType.Empty(); } var i = new Interpreter.Interpreter(obj, Cache); var result = i.Apply(_state); _errors.AddRange(result.Errors); return StringType.New(result.Output); }
public void Create(params string[] lines) { _textView = CreateTextView(lines); _textView.Caret.MoveTo(new SnapshotPoint(_textView.TextSnapshot, 0)); _textBuffer = _textView.TextBuffer; _factory = new MockRepository(MockBehavior.Strict); _editOpts = _factory.Create<IEditorOperations>(); _vimHost = _factory.Create<IVimHost>(); _vimHost.Setup(x => x.IsDirty(It.IsAny<ITextBuffer>())).Returns(false); _operations = _factory.Create<ICommonOperations>(); _operations.SetupGet(x => x.EditorOperations).Returns(_editOpts.Object); _statusUtil = _factory.Create<IStatusUtil>(); _fileSystem = _factory.Create<IFileSystem>(MockBehavior.Strict); _foldManager = _factory.Create<IFoldManager>(MockBehavior.Strict); _vimData = new VimData(); _vim = MockObjectFactory.CreateVim(RegisterMap, host: _vimHost.Object, vimData: _vimData, factory: _factory); var localSettings = new LocalSettings(Vim.GlobalSettings); var vimTextBuffer = MockObjectFactory.CreateVimTextBuffer( _textBuffer, vim: _vim.Object, localSettings: localSettings, factory: _factory); var vimBufferData = CreateVimBufferData( vimTextBuffer.Object, _textView, statusUtil: _statusUtil.Object); var vimBuffer = CreateVimBuffer(vimBufferData); _interpreter = new Interpreter.Interpreter( vimBuffer, _operations.Object, _foldManager.Object, _fileSystem.Object, _factory.Create<IBufferTrackingService>().Object); }