public void fold_foreachi_rangeIsFixed() { // fun swapIfNotSorted(T_0[],Int32):T_0[] where T_0: <> // 6 32 1 0 4 5 //sorted = fold([0..count(input)], input, swapIfNotSorted)"; var graph = new GraphBuilder(); graph.SetVar("input", 0); var tOfCount = graph.InitializeVarNode(); //count graph.SetCall(new ITicNodeState[] { StateArray.Of(tOfCount), StatePrimitive.I32 }, new[] { 0, 1 }); graph.SetIntConst(2, StatePrimitive.U8); //range graph.SetCall(new ITicNodeState[] { StatePrimitive.I32, StatePrimitive.I32, StateArray.Of(StatePrimitive.I32) }, new [] { 2, 1, 3 }); graph.SetVar("input", 4); var tOfSwap = graph.InitializeVarNode(isComparable: true); graph.SetVarType("swapIfNotSorted", StateFun.Of(new ITicNodeState[] { StateArray.Of(tOfSwap), StatePrimitive.I32 }, StateArray.Of(tOfSwap))); graph.SetVar("swapIfNotSorted", 5); graph.SetfoldCall(3, 4, 5, 6); graph.SetDef("sorted", 6); var result = graph.Solve(); var generic = result.AssertAndGetSingleGeneric(null, null, true); result.AssertNamed(StateArray.Of(generic), "sorted", "input"); }
public static void SetRangeCall(this GraphBuilder graph, int fromId, int toId, int resId) { var generic = graph.InitializeVarNode(anc: StatePrimitive.I48); //range graph.SetCall(new ITicNodeState[] { generic, generic, StateArray.Of(generic) }, new[] { fromId, toId, resId }); }
public void MapWithLambda() { var result = TestHelper.Solve("y = a.map(fun(i:int)=i+1)"); result.AssertNoGenerics(); result.AssertNamed(StateArray.Of(StatePrimitive.I32), "y"); result.AssertNamed(StateArray.Of(StatePrimitive.I32), "a"); }
public static void SetArrGetCall(this GraphBuilder builder, int arrArgId, int indexArgId, int resId) { var varNode = builder.InitializeVarNode(); builder.SetCall( new ITicNodeState [] { StateArray.Of(varNode), StatePrimitive.I32, varNode }, new [] { arrArgId, indexArgId, resId }); }
public void ConcatSolveGenerics() { var result = TestHelper.Solve("y = x.concat(x)"); var generic = result.AssertAndGetSingleGeneric(null, null); result.AssertNamed(StateArray.Of(generic), "y","x"); }
public static void SetSizeOfArrayCall(this GraphBuilder graph, int argId, int resId) { var tOfCount = graph.InitializeVarNode(); //count graph.SetCall(new ITicNodeState[] { StateArray.Of(tOfCount), StatePrimitive.I32 }, new[] { argId, resId }); }
public void fold_for() { // fun swapIfNotSorted(T_0[],Int32):T_0[] where T_0: <> // 5 21 0 3 4 //sorted = fold([0..5], input, swapIfNotSorted)"; var graph = new GraphBuilder(); graph.SetIntConst(0, StatePrimitive.U8); graph.SetIntConst(1, StatePrimitive.U8); graph.SetCall(new ITicNodeState[] { StatePrimitive.I32, StatePrimitive.I32, StateArray.Of(StatePrimitive.I32) }, new[] { 1, 0, 2 }); graph.SetVar("input", 3); var tOfSwap = graph.InitializeVarNode(isComparable: true); graph.SetVarType("swapIfNotSorted", StateFun.Of(new ITicNodeState[] { StateArray.Of(tOfSwap), StatePrimitive.I32 }, StateArray.Of(tOfSwap))); graph.SetVar("swapIfNotSorted", 4); graph.SetfoldCall(2, 3, 4, 5); graph.SetDef("sorted", 5); var result = graph.Solve(); var generic = result.AssertAndGetSingleGeneric(null, null, true); result.AssertNamed(StateArray.Of(generic), "sorted", "input"); }
public void CompareSameArrays_GenericTypeSolvedWell() { var result = TestHelper.SolveAndGetResults("y = [1.0] == [1.0]"); var equalGenericType = result.GenericFunctionTypes.Where(g => g != null).Single(); Assert.AreEqual(equalGenericType.Length, 1); var state = equalGenericType[0]; TestHelper.AssertAreSame(StateArray.Of(StatePrimitive.Real), state); }
public void InitArrayWithVar() { var result = TestHelper.Solve("y = [x,2,3]"); var generic = result.AssertAndGetSingleGeneric(StatePrimitive.U8, StatePrimitive.Real); result.AssertNamed(StateArray.Of(generic), "y"); result.AssertAreGenerics(generic, "x"); }
public void GetLastCommonAncestorOrNull_ConcreteFunTypeAndConstrainsArray_ReturnsAny() { var fun = StateFun.Of(StatePrimitive.I32, StatePrimitive.I64); var array = StateArray.Of(CreateConstrainsNode()); Assert.AreEqual(StatePrimitive.Any, fun.GetLastCommonAncestorOrNull(array)); Assert.AreEqual(StatePrimitive.Any, array.GetLastCommonAncestorOrNull(fun)); }
public static void SetConcatCall(this GraphBuilder builder, int firstId, int secondId, int resultId) { var varNode = builder.InitializeVarNode(); builder.SetCall(new ITicNodeState[] { StateArray.Of(varNode), StateArray.Of(varNode), StateArray.Of(varNode) }, new [] { firstId, secondId, resultId }); }
public static void SetMap(this GraphBuilder builder, int arrId, int funId, int resultId) { var inNode = builder.InitializeVarNode(); var outNode = builder.InitializeVarNode(); builder.SetCall(new ITicNodeState[] { StateArray.Of(inNode), StateFun.Of( returnType: outNode, argType: inNode), StateArray.Of(outNode) }, new [] { arrId, funId, resultId }); }
public static void SetfoldCall(this GraphBuilder graph, int arrId, int funId, int returnId) { var generic = graph.InitializeVarNode(); graph.SetCall(new ITicNodeState[] { StateArray.Of(generic), StateFun.Of(new[] { generic, generic }, generic), generic }, new[] { arrId, funId, returnId }); }
public static void SetFoldCall(this GraphBuilder graph, int arrId, int funId, int returnId) { var inT = graph.InitializeVarNode(); var outT = graph.InitializeVarNode(); graph.SetCall(new ITicNodeState[] { StateArray.Of(inT), StateFun.Of(new[] { outT, inT }, outT), outT }, new[] { arrId, funId, returnId }); }
public static void SetGetFirst(this GraphBuilder builder, int arrId, int funId, int resultId) { var inNode = builder.InitializeVarNode(); if (inNode != null) { builder.SetCall(new ITicNodeState[] { StateArray.Of(inNode), StateFun.Of(returnType: StatePrimitive.Bool, argType: inNode), inNode }, new[] { arrId, funId, resultId }); } }
public static void SetfoldCall(this GraphBuilder graph, int arrId, int defId, int funId, int resId) { var tRes = graph.InitializeVarNode(); var tArg = graph.InitializeVarNode(); //fold call fold( T[], G, (G,T)->G )->G graph.SetCall(new ITicNodeState[] { StateArray.Of(tArg), tRes, StateFun.Of(new ITicNodeState[] { tRes, tArg }, tRes), tRes }, new[] { arrId, defId, funId, resId }); }
public void Array_referencesItself() { // 1 0 //x = reverse(x) var graph = new GraphBuilder(); graph.SetVar("x", 0); graph.SetReverse(0, 1); graph.SetDef("x", 1); var result = graph.Solve(); var res = result.AssertAndGetSingleGeneric(null, null); result.AssertNamed(StateArray.Of(res), "x"); }
public void SortOneTimeUserFunction() { // fun swapIfNotSorted(T_0[],Int32):T_0[] where T_0: <> // 6 32 1 0 4 5 //sortOneTime(input) = fold([0..count(input)], input, swapIfNotSorted)"; //Exit: 16.Tvar input: Empty //Exit:19.IntConst 0:int //Exit:21.VAR input //Exit:20.Call count(21, 20) //Exit: 18.Call range(19, 20, 18) //Exit: 22.VAR input //Exit:23.VAR swapIfNotSorted //Exit:17.Call fold(18, 22, 23, 17) var graph = new GraphBuilder(); graph.SetVar("input", 0); var fundef = graph.SetFunDef("sortOneTime", 6, null, "input"); graph.SetSizeOfArrayCall(0, 1); //count graph.SetIntConst(2, StatePrimitive.U8); graph.SetRangeCall(2, 1, 3); //range graph.SetVar("input", 4); var tOfSwap = graph.InitializeVarNode(isComparable: true); graph.SetVarType("swapIfNotSorted", StateFun.Of(new ITicNodeState[] { SolvingStates.StateArray.Of(tOfSwap), StatePrimitive.I32 }, SolvingStates.StateArray.Of(tOfSwap))); graph.SetVar("swapIfNotSorted", 5); graph.SetfoldCall(3, 4, 5, 6); var result = graph.Solve(); var generic = result.AssertAndGetSingleGeneric(null, null, true); result.AssertNamed(SolvingStates.StateArray.Of(generic), "input"); var expectedType = StateFun.Of(StateArray.Of(generic.GetNonReference()), StateArray.Of(generic)); //todo //Assert.AreEqual(expectedType, result.GetVariableNode("sortOneTime").State.ToString()); result.AssertNamed( StateFun.Of(StateArray.Of(generic.GetNonReference()), StateArray.Of(generic)), "sortOneTime"); }
public void Anything_WithConcreteFunAndUpcast() { // 2 0 1 //a:int[]; y = Any(a, isNan) var graph = new GraphBuilder(); graph.SetVarType("a", StateArray.Of(StatePrimitive.I32)); graph.SetVar("a", 0); graph.SetVarType("isNan", StateFun.Of(StatePrimitive.Real, StatePrimitive.Bool)); graph.SetVar("isNan", 1); graph.SetIsAny(0, 1, 2); graph.SetDef("y", 2); var result = graph.Solve(); result.AssertNoGenerics(); }
public void ImpossibleArgType_Throws() { // 1 0 //x:Any[]; y = NoNans(x) var graph = new GraphBuilder(); graph.SetVarType("x", StateArray.Of(StatePrimitive.Any)); graph.SetVar("x", 0); TestHelper.AssertThrowsTicError(() => { graph.SetCall(new ITicNodeState[] { StateArray.Of(StatePrimitive.Real), StatePrimitive.Bool }, new[] { 0, 1 }); graph.SetDef("y", 1); graph.Solve(); Assert.Fail(); }); }
public void Count() { // 1 0 //y = count('abc') var graph = new GraphBuilder(); graph.SetArrayConst(0, StatePrimitive.Char); graph.SetCall(new ITicNodeState[] { StateArray.Of(StatePrimitive.Any), StatePrimitive.I32 }, new [] { 0, 1 }); graph.SetDef("y", 1); var res = graph.Solve(); res.AssertNoGenerics(); res.AssertNamed(StatePrimitive.I32, "y"); }
public void Impossible_ConcreteArgAndDef_throws() { // 1 0 //x:real[]; y:int = sum(x) var graph = new GraphBuilder(); graph.SetVarType("x", StateArray.Of(StatePrimitive.Real)); graph.SetVar("x", 0); graph.SetSumCall(0, 1); graph.SetVarType("y", StatePrimitive.I32); TestHelper.AssertThrowsTicError(() => { graph.SetDef("y", 1); graph.Solve(); }); }
public void ConcreteCall() { // 1 0 //y = NoNans(x) var graph = new GraphBuilder(); graph.SetVar("x", 0); graph.SetCall(new ITicNodeState[] { StateArray.Of(StatePrimitive.Real), StatePrimitive.Bool }, new [] { 0, 1 }); graph.SetDef("y", 1); var result = graph.Solve(); result.AssertNoGenerics(); result.AssertNamed(StateArray.Of(StatePrimitive.Real), "x"); result.AssertNamed(StatePrimitive.Bool, "y"); }
public void ConcreteArg() { // 2 0 //x:int[]; y = sum(x) var graph = new GraphBuilder(); graph.SetVarType("x", StateArray.Of(StatePrimitive.I32)); graph.SetVar("x", 0); graph.SetSumCall(0, 1); graph.SetDef("y", 1); var result = graph.Solve(); result.AssertNoGenerics(); result.AssertNamedEqualToArrayOf(StatePrimitive.I32, "x"); result.AssertNamed(StatePrimitive.I32, "y"); }
public void ConcreteFun() { // 2 0 1 //y = First(a, isNan) var graph = new GraphBuilder(); graph.SetVar("a", 0); graph.SetVarType("isNan", StateFun.Of(StatePrimitive.Real, StatePrimitive.Bool)); graph.SetVar("isNan", 1); graph.SetGetFirst(0, 1, 2); graph.SetDef("y", 2); var result = graph.Solve(); result.AssertNoGenerics(); result.AssertNamed(StateArray.Of(StatePrimitive.Real), "a"); }
public void Concat_RightConcreteArg() { // 2 0 1 //b:int[]; y = concat(a,b) var graph = new GraphBuilder(); graph.SetVarType("b", StateArray.Of(StatePrimitive.I32)); graph.SetVar("a", 0); graph.SetVar("b", 1); graph.SetConcatCall(0, 1, 2); graph.SetDef("y", 2); var result = graph.Solve(); result.AssertNoGenerics(); result.AssertNamedEqualToArrayOf(StatePrimitive.I32, "y", "a", "b"); }
public void TwoDimention_InitConcrete() { // 4 3 0 1 2 // y = [[1i,2i,3i]] var graph = new GraphBuilder(); graph.SetConst(0, StatePrimitive.I32); graph.SetConst(1, StatePrimitive.I32); graph.SetConst(2, StatePrimitive.I32); graph.SetStrictArrayInit(3, 0, 1, 2); graph.SetStrictArrayInit(4, 3); graph.SetDef("y", 4); var result = graph.Solve(); result.AssertNoGenerics(); result.AssertNamed(StateArray.Of(StateArray.Of(StatePrimitive.I32)), "y"); }
public void ArrayInitWithSpecifiedArrayTypeAndDowncast_fails() { // 3 0 1 2 // y:byte[] = [1i,2i,3i] var graph = new GraphBuilder(); graph.SetVarType("y", StateArray.Of(StatePrimitive.U8)); graph.SetConst(0, StatePrimitive.I32); graph.SetConst(1, StatePrimitive.I32); graph.SetConst(2, StatePrimitive.I32); graph.SetStrictArrayInit(3, 0, 1, 2); TestHelper.AssertThrowsTicError(() => { graph.SetDef("y", 3); graph.Solve(); }); }
public void ArrayInitWithSpecifiedArrayType() { // 3 0 1 2 // y:int[] = [1i,2i,3i] var graph = new GraphBuilder(); graph.SetVarType("y", StateArray.Of(StatePrimitive.I32)); graph.SetConst(0, StatePrimitive.I32); graph.SetConst(1, StatePrimitive.I32); graph.SetConst(2, StatePrimitive.I32); graph.SetStrictArrayInit(3, 0, 1, 2); graph.SetDef("y", 3); var result = graph.Solve(); result.AssertNoGenerics(); result.AssertNamedEqualToArrayOf(StatePrimitive.I32, "y"); }
public void OneDimention_ImpossibleConcreteArgAndDef() { // 2 0,1 //x:int[]; y:i16 = get(x,0) var graph = new GraphBuilder(); graph.SetVarType("x", StateArray.Of(StatePrimitive.I32)); graph.SetVar("x", 0); graph.SetConst(1, StatePrimitive.I32); graph.SetArrGetCall(0, 1, 2); TestHelper.AssertThrowsTicError(() => { graph.SetVarType("y", StatePrimitive.I16); graph.SetDef("y", 2); graph.Solve(); }); }