-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhisk.py
53 lines (37 loc) · 1.04 KB
/
whisk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
A OISC emulation using the Subleq operation.
Tom Findlay ([email protected])
Feb. 2021
"""
class whisk:
def __init__(self, memory=30000):
self.memory = [0]*memory
def subleq(self,addr):
if addr < 0:
return None
A = self.memory[addr]
B = self.memory[addr+1]
C = self.memory[addr+2]
if B == -1:
print(chr(self.memory[A]), end="")
return addr+3
else:
sub = self.memory[B] - self.memory[A]
self.memory[B] = sub
if sub <= 0:
return C
return addr+3
def run(self, code):
code = code.split()
code = [int(i) for i in code]
self.memory[0:len(code)] = code
pc = 0
while pc != None:
pc = self.subleq(pc)
return True
if __name__ == "__main__":
f = open("output.slq", "r")
code = f.read()
f.close()
w = whisk()
w.run(code)