Example #1
0
def dupe_each_n_fn(srs):
    a=srs.pop()
    tmp = []
    while srs.stack:
        b = srs.pop()
        tmp+=[b for i in range(a)]
    srs.stack=deque(tmp[::-1])
Example #2
0
def dupe_each_n_fn(srs):
    a=srs.pop()
    tmp = []
    while srs.stack:
        b = srs.pop()
        tmp = [copy(b)[1] for _ in range(a)] + tmp
    srs.stack=deque(tmp)
Example #3
0
def dupe_each_fn(srs):
    tmp=[]
    while len(srs.stack)>0:
        a=srs.pop()
        tmp.append(a)
        tmp.append(copy(a))
    srs.stack=deque(tmp[::-1])
Example #4
0
 def __init__(self, init_stack=None, debug_mode=False):
     self.stack = deque(init_stack if init_stack is not None else [])
     self.debug_mode = debug_mode
     self.code = ''
     self.fn_table = SeriouslyCommands.fn_table
     self.preserve = False
     self.pop_counter = 0
Example #5
0
def dupe_each_fn(srs):
    tmp=[]
    while len(srs.stack)>0:
        a=srs.pop()
        a,b = copy(a)
        tmp.append(a)
        tmp.append(b)
    srs.stack=deque(tmp[::-1])
Example #6
0
 def __init__(self, init_stack=None, debug_mode=False):
     self.stack = deque(init_stack if init_stack is not None else [])
     self.debug_mode = debug_mode
     self.code = ''
     self.fn_table = SeriouslyCommands.fn_table
     self.preserve = False
     self.pop_counter = 0
     self.inputs = []
Example #7
0
def ins_bot_fn(srs):
    a=srs.pop()
    b=srs.pop()
    srs.stack=deque(srs.stack[:-a]+[b]+srs.stack[-a:])
Example #8
0
def ins_top_fn(srs):
    a=srs.pop()
    b=srs.pop()
    srs.stack=deque(srs.stack[:a]+[b]+srs.stack[a:])
Example #9
0
def to_list_fn(srs):
    srs.stack = deque([as_list(srs.stack)])
Example #10
0
 def eval(self, code):
     if self.debug_mode:
         print(code)
     i = 0
     if all(x not in remove_lists_and_strings(code)
            for x in (',', chr_cp437(0xCA), chr_cp437(0x09),
                      chr_cp437(0x15))):
         for line in sys.stdin.read().splitlines():
             self.push(literal_eval(line))
             self.inputs.append(literal_eval(line))
     self.code = code
     while i < len(code):
         old_stack = self.stack.copy()
         try:
             c = code[i]
             if c == '"':
                 s = ""
                 i += 1
                 while i < len(code) and code[i] != '"':
                     s += code[i]
                     i += 1
                 self.push(s)
             elif c == "'":
                 i += 1
                 self.push(code[i])
             elif c == ':':
                 v = ""
                 i += 1
                 while i < len(code) and code[i] in '0123456789.ij+-':
                     v += code[i]
                     i += 1
                 i -= 1
                 val = 0
                 v = v.replace('i', 'j')
                 if self.debug_mode:
                     print(v)
                 try:
                     val = literal_eval(v)
                     if self.debug_mode:
                         print(val)
                 except:
                     while not val and v:
                         v = v[:-1]
                         i -= 1
                         try:
                             val = literal_eval(v)
                             break
                         except:
                             continue
                     if self.debug_mode:
                         print("Failed to eval numeric")
                 val = val if anytype(val, int, float, complex) else 0
                 self.push(val)
             elif c == 'W':
                 inner = ''
                 i += 1
                 while i < len(code) and code[i] != 'W':
                     inner += code[i]
                     i += 1
                 if self.debug_mode:
                     print("while loop code: {}".format(inner))
                 while self.peek():
                     self.eval(inner)
             elif c == '[':
                 l = ''
                 i += 1
                 nest = 1
                 while i < len(code):
                     if code[i] == '[':
                         nest += 1
                     elif code[i] == ']':
                         nest -= 1
                         if nest == 0:
                             break
                     l += code[i]
                     i += 1
                 self.push(literal_eval('[{}]'.format(l)))
                 if self.debug_mode:
                     print("list: [{}]".format(l))
                     print(self.stack)
             elif c == '⌠':
                 fn = ''
                 i += 1
                 nest = 1
                 while i < len(code):
                     if code[i] == '⌠':
                         nest += 1
                     elif code[i] == '⌡':
                         nest -= 1
                         if nest == 0:
                             break
                     fn += code[i]
                     i += 1
                 self.push(SeriouslyCommands.SeriousFunction(fn))
                 if self.debug_mode:
                     print("fn: {}".format(fn))
                     print(self.stack)
             elif c == '`':
                 i += 1
                 self.push(SeriouslyCommands.SeriousFunction(code[i]))
             elif ord(c) in range(48, 58):
                 self.push(int(c))
             elif ord_cp437(c) == 0x0B:
                 i += 1
                 self.push(SeriouslyCommands.SeriousFunction(code[i]))
                 self.fn_table.get(ord_cp437('M'))(self)
             elif ord_cp437(c) == 0x0C:
                 i += 1
                 a, b = self.pop(), self.pop()
                 if not isinstance(a, collections.Iterable):
                     a = [
                         a for _ in
                         (b if isinstance(b, collections.Iterable) else [1])
                     ]
                 if not isinstance(b, collections.Iterable):
                     b = [b for _ in a]
                 self.push(b)
                 self.push(a)
                 self.fn_table.get(ord_cp437('Z'))(self)
                 self.push(SeriouslyCommands.SeriousFunction('i' + code[i]))
                 self.fn_table.get(ord_cp437('M'))(self)
             elif ord_cp437(c) == 0x14:
                 i += 1
                 cmd = code[i]
                 a = self.pop()
                 for _ in range(a):
                     self.eval(cmd)
             elif ord_cp437(c) == 0x0E:
                 cmd1, cmd2 = code[i + 1], code[i + 2]
                 temp_stack = self.stack.copy()
                 self.eval(cmd1)
                 res1 = self.stack.copy()
                 self.stack = temp_stack
                 self.eval(cmd2)
                 res2 = self.stack.copy()
                 self.stack = deque()
                 self.push([
                     res1 if len(res1) > 1 else res1[0],
                     res2 if len(res2) > 1 else res2[0]
                 ])
                 i += 2
             else:
                 if self.debug_mode:
                     print("{:2X}".format(ord_cp437(c)))
                 self.fn_table.get(ord_cp437(c), lambda x: x)(self)
                 if self.debug_mode:
                     print(self.stack)
         except SystemExit:
             exit()
         except KeyboardInterrupt:  # pragma: no cover
             exit()
         except:
             if self.debug_mode:
                 traceback.print_exc()
             self.stack = old_stack
         finally:
             i += 1
     return as_list(self.stack)[::-1]
Example #11
0
def ins_bot_fn(srs):
    a=srs.pop()
    b=srs.pop()
    srs.stack=deque(srs.stack[:-a]+[b]+srs.stack[-a:])
Example #12
0
def ins_top_fn(srs):
    a=srs.pop()
    b=srs.pop()
    srs.stack=deque(srs.stack[:a]+[b]+srs.stack[a:])
Example #13
0
def to_list_fn(srs):
    srs.stack = deque([as_list(srs.stack)])