Check if control in range(255)
This commit is contained in:
parent
2760961550
commit
e3c1672b19
17
horrlang.py
17
horrlang.py
|
@ -23,8 +23,7 @@ class InfiniteArray:
|
|||
|
||||
|
||||
class Machine:
|
||||
def __init__(self, code, read, write, user_data=None, max_cycles=None):
|
||||
self.user_data = user_data
|
||||
def __init__(self, code, read, write, max_cycles=None):
|
||||
self.read = read
|
||||
self.write = write
|
||||
self.mem = InfiniteArray([ord(char) for char in code])
|
||||
|
@ -102,14 +101,16 @@ class Machine:
|
|||
while True:
|
||||
if self.mem[self.exc_ptr] == 0:
|
||||
return
|
||||
control = chr(self.mem[self.exc_ptr])
|
||||
if debug:
|
||||
print control
|
||||
if hasattr(self, control):
|
||||
getattr(self, control)()
|
||||
if self.mem[self.exc_ptr] <= 255:
|
||||
control = chr(self.mem[self.exc_ptr])
|
||||
if debug:
|
||||
print control
|
||||
if hasattr(self, control):
|
||||
getattr(self, control)()
|
||||
self.exc_ptr += 1
|
||||
if not self.cycle():
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
Machine(sys.argv[1], sys.stdin.read, sys.stdout.write, None).run()
|
||||
Machine(sys.argv[1], sys.stdin.read, sys.stdout.write,
|
||||
int(sys.argv[2]) if len(sys.argv) >= 2 else None).run()
|
||||
|
|
Loading…
Reference in New Issue