Braincrash von QPython
braincrash.py
from __future__ import print_function
from sys import stdin,stdout
from brainfuck import Brainfuck
from brainfuck import op
class Braincrash(Brainfuck):
def __init__(s,OPs="><+-.,[]|&~^",size=30000):
Brainfuck.__init__(s,OPs,size)
def const(s,OPs):
Brainfuck.const(s,OPs)
s.opDic[OPs[8]]=opOr # op |
s.opDic[OPs[9]]=opAnd # op &
s.opDic[OPs[10]]=opNot # op ~
s.opDic[OPs[11]]=opXor # op ^
def run(s,limit=1000,out=stdout):
Brainfuck.run(s,"Hello, world!",limit,out)
while s.pt<len(s.mem) and s.mem[s.pt] != 0:
out.write(chr(s.mem[s.pt]))
s.pt+=1
#end class
class opOr(op):
def do(s,bf):
bf.mem[bf.pt]|=bf.mem[bf.pt+1]
bf.pt+=1
bf.pc+=1
#end class
class opAnd(op):
def do(s,bf):
bf.mem[bf.pt]&=bf.mem[bf.pt+1]
bf.pt+=1
bf.pc+=1
#end class
class opNot(op):
offset = int("1"*8,2)
def do(s,bf):
bf.mem[bf.pt]^=s.offset
bf.pc+=1
#end class
class opXor(op):
def do(s,bf):
bf.mem[bf.pt]^=bf.mem[bf.pt+1]
bf.pt+=1
bf.pc+=1
#end class