-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7faea7
commit 7e28c8a
Showing
7 changed files
with
244 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from collections import deque | ||
from aheui._compat import PYR | ||
|
||
|
||
assert not PYR, 'RPython must use linkedlist' | ||
|
||
|
||
class Stack(list): | ||
__slots__ = () | ||
|
||
def push(self, value): | ||
self.append(value) | ||
|
||
def dup(self): | ||
self.append(self[-1]) | ||
|
||
def swap(self): | ||
self[-1], self[-2] = self[-2], self[-1] | ||
|
||
def add(self): | ||
top = self.pop() | ||
self[-1] += top | ||
|
||
def sub(self): | ||
top = self.pop() | ||
self[-1] -= top | ||
|
||
def mul(self): | ||
top = self.pop() | ||
self[-1] *= top | ||
|
||
def div(self): | ||
top = self.pop() | ||
self[-1] /= top | ||
|
||
def mod(self): | ||
top = self.pop() | ||
self[-1] %= top | ||
|
||
def cmp(self): | ||
top = self.pop() | ||
self[-1] = self[-1] >= top | ||
|
||
|
||
class Queue(deque): | ||
__slots__ = () | ||
|
||
def push(self, value): | ||
self.appendleft(value) | ||
|
||
def dup(self): | ||
self.appendleft(self[0]) | ||
|
||
def swap(self): | ||
self[-1], self[-2] = self[-2], self[-1] | ||
|
||
def add(self): | ||
top = self.pop() | ||
self.appendleft(self.pop() + top) | ||
|
||
def sub(self): | ||
top = self.pop() | ||
self.appendleft(self.pop() - top) | ||
|
||
def mul(self): | ||
top = self.pop() | ||
self.appendleft(self.pop() * top) | ||
|
||
def div(self): | ||
top = self.pop() | ||
self.appendleft(self.pop() / top) | ||
|
||
def mod(self): | ||
top = self.pop() | ||
self.appendleft(self.pop() % top) | ||
|
||
def cmp(self): | ||
top = self.pop() | ||
self.appendleft(self.pop() >= top) | ||
|
||
|
||
Port = Stack |
Oops, something went wrong.