diff --git a/GenPy.fu b/GenPy.fu index 84c6a1c3..0aa95cb4 100644 --- a/GenPy.fu +++ b/GenPy.fu @@ -318,6 +318,9 @@ public class GenPy : GenPySwift Include("collections"); WriteCollectionTypeAnnotation("collections.deque", klass); break; + case FuId.PriorityQueueClass: + WriteCollectionTypeAnnotation("list", klass); + break; case FuId.HashSetClass: case FuId.SortedSetClass: WriteCollectionTypeAnnotation("set", klass); @@ -483,6 +486,7 @@ public class GenPy : GenPySwift case FuId.ListCount: case FuId.QueueCount: case FuId.StackCount: + case FuId.PriorityQueueCount: case FuId.HashSetCount: case FuId.SortedSetCount: case FuId.DictionaryCount: @@ -708,6 +712,9 @@ public class GenPy : GenPySwift Include("collections"); Write("collections.deque()"); break; + case FuId.PriorityQueueClass: + Write("[]"); + break; case FuId.HashSetClass: case FuId.SortedSetClass: Write("set()"); @@ -961,8 +968,20 @@ public class GenPy : GenPySwift WriteListAppend(obj, args); break; case FuId.QueuePeek: + case FuId.PriorityQueuePeek: WritePostfix(obj, "[0]"); break; + case FuId.PriorityQueueClear: + WritePostfix(obj, ".clear()"); + break; + case FuId.PriorityQueueEnqueue: + Include("heapq"); + WriteCall("heapq.heappush", obj, args[0]); + break; + case FuId.PriorityQueueDequeue: + Include("heapq"); + WriteCall("heapq.heappop", obj); + break; case FuId.DictionaryAdd: WriteDictionaryAdd(obj, args); break; diff --git a/libfut.cpp b/libfut.cpp index 88bda501..dd830f7f 100644 --- a/libfut.cpp +++ b/libfut.cpp @@ -23587,6 +23587,9 @@ void GenPy::writeTypeAnnotation(const FuType * type, bool nullable) include("collections"); writeCollectionTypeAnnotation("collections.deque", klass); break; + case FuId::priorityQueueClass: + writeCollectionTypeAnnotation("list", klass); + break; case FuId::hashSetClass: case FuId::sortedSetClass: writeCollectionTypeAnnotation("set", klass); @@ -23755,6 +23758,7 @@ void GenPy::visitSymbolReference(const FuSymbolReference * expr, FuPriority pare case FuId::listCount: case FuId::queueCount: case FuId::stackCount: + case FuId::priorityQueueCount: case FuId::hashSetCount: case FuId::sortedSetCount: case FuId::dictionaryCount: @@ -23978,6 +23982,9 @@ void GenPy::writeNew(const FuReadWriteClassType * klass, FuPriority parent) include("collections"); write("collections.deque()"); break; + case FuId::priorityQueueClass: + write("[]"); + break; case FuId::hashSetClass: case FuId::sortedSetClass: write("set()"); @@ -24234,8 +24241,20 @@ void GenPy::writeCallExpr(const FuExpr * obj, const FuMethod * method, const std writeListAppend(obj, args); break; case FuId::queuePeek: + case FuId::priorityQueuePeek: writePostfix(obj, "[0]"); break; + case FuId::priorityQueueClear: + writePostfix(obj, ".clear()"); + break; + case FuId::priorityQueueEnqueue: + include("heapq"); + writeCall("heapq.heappush", obj, (*args)[0].get()); + break; + case FuId::priorityQueueDequeue: + include("heapq"); + writeCall("heapq.heappop", obj); + break; case FuId::dictionaryAdd: writeDictionaryAdd(obj, args); break; diff --git a/libfut.cs b/libfut.cs index 0e8d3673..e8c6f15a 100644 --- a/libfut.cs +++ b/libfut.cs @@ -24441,6 +24441,9 @@ void WriteTypeAnnotation(FuType type, bool nullable = false) Include("collections"); WriteCollectionTypeAnnotation("collections.deque", klass); break; + case FuId.PriorityQueueClass: + WriteCollectionTypeAnnotation("list", klass); + break; case FuId.HashSetClass: case FuId.SortedSetClass: WriteCollectionTypeAnnotation("set", klass); @@ -24606,6 +24609,7 @@ internal override void VisitSymbolReference(FuSymbolReference expr, FuPriority p case FuId.ListCount: case FuId.QueueCount: case FuId.StackCount: + case FuId.PriorityQueueCount: case FuId.HashSetCount: case FuId.SortedSetCount: case FuId.DictionaryCount: @@ -24826,6 +24830,9 @@ protected override void WriteNew(FuReadWriteClassType klass, FuPriority parent) Include("collections"); Write("collections.deque()"); break; + case FuId.PriorityQueueClass: + Write("[]"); + break; case FuId.HashSetClass: case FuId.SortedSetClass: Write("set()"); @@ -25079,8 +25086,20 @@ protected override void WriteCallExpr(FuExpr obj, FuMethod method, List WriteListAppend(obj, args); break; case FuId.QueuePeek: + case FuId.PriorityQueuePeek: WritePostfix(obj, "[0]"); break; + case FuId.PriorityQueueClear: + WritePostfix(obj, ".clear()"); + break; + case FuId.PriorityQueueEnqueue: + Include("heapq"); + WriteCall("heapq.heappush", obj, args[0]); + break; + case FuId.PriorityQueueDequeue: + Include("heapq"); + WriteCall("heapq.heappop", obj); + break; case FuId.DictionaryAdd: WriteDictionaryAdd(obj, args); break; diff --git a/libfut.js b/libfut.js index 07c0082d..9fc5d85a 100644 --- a/libfut.js +++ b/libfut.js @@ -25091,6 +25091,9 @@ export class GenPy extends GenPySwift this.include("collections"); this.#writeCollectionTypeAnnotation("collections.deque", klass); break; + case FuId.PRIORITY_QUEUE_CLASS: + this.#writeCollectionTypeAnnotation("list", klass); + break; case FuId.HASH_SET_CLASS: case FuId.SORTED_SET_CLASS: this.#writeCollectionTypeAnnotation("set", klass); @@ -25260,6 +25263,7 @@ export class GenPy extends GenPySwift case FuId.LIST_COUNT: case FuId.QUEUE_COUNT: case FuId.STACK_COUNT: + case FuId.PRIORITY_QUEUE_COUNT: case FuId.HASH_SET_COUNT: case FuId.SORTED_SET_COUNT: case FuId.DICTIONARY_COUNT: @@ -25488,6 +25492,9 @@ export class GenPy extends GenPySwift this.include("collections"); this.write("collections.deque()"); break; + case FuId.PRIORITY_QUEUE_CLASS: + this.write("[]"); + break; case FuId.HASH_SET_CLASS: case FuId.SORTED_SET_CLASS: this.write("set()"); @@ -25742,8 +25749,20 @@ export class GenPy extends GenPySwift this.writeListAppend(obj, args); break; case FuId.QUEUE_PEEK: + case FuId.PRIORITY_QUEUE_PEEK: this.writePostfix(obj, "[0]"); break; + case FuId.PRIORITY_QUEUE_CLEAR: + this.writePostfix(obj, ".clear()"); + break; + case FuId.PRIORITY_QUEUE_ENQUEUE: + this.include("heapq"); + this.writeCall("heapq.heappush", obj, args[0]); + break; + case FuId.PRIORITY_QUEUE_DEQUEUE: + this.include("heapq"); + this.writeCall("heapq.heappop", obj); + break; case FuId.DICTIONARY_ADD: this.writeDictionaryAdd(obj, args); break; diff --git a/test/PriorityQueue.fu b/test/PriorityQueue.fu index e4c1ef42..a712b9bf 100644 --- a/test/PriorityQueue.fu +++ b/test/PriorityQueue.fu @@ -2,7 +2,7 @@ public static class Test { public static bool Run() { - PriorityQueue() q; //FAIL: d js py swift ts TODO; c, cl + PriorityQueue() q; //FAIL: d js swift ts TODO; c, cl q.Enqueue(42); q.Clear(); q.Enqueue(15);