Vague/IFcoltransG

From Esolang
Jump to navigation Jump to search

An implementation of Vague by User:IFcoltransG. This may be considered a reference implementation because no other implementations are correct.

   # /usr/bin/python3
   # The only standards-compliant implementation of Vague
   
   def interpret(code):
       global __name__
       current = "?"
       old_code = code
       while code:
           old_current = current
           current, *code = code
           if current == "+":
               "Add"
               code += code
           elif current == "-":
               "Decrement"
               code.insert(0, old_current)
           elif current == "!":
               "Print"
               print(code)
           elif current == ">":
               "Right"
               code.insert(0, code.pop())
           elif current == "<":
               "Left"
               code.append(code.pop(0))
           elif current == "&":
               "NAND"
               code = "".join(code)
               encode = code.encode("utf8")
               decode = code.encode("utf16")
               code = []
               for a, b in zip(encode, decode):
                   code.append(not (a and b))
               code = bytes(code).decode("utf8")
           elif current == "=":
               "Push",
               code.append(old_current)
           elif current == "_":
               "Pop"
               code.pop()
           elif current == ".":
               "End"
               __name__ = "__main__"
               main()
           elif current == "0":
               "Zero"
               code = code.pop(0) + "\x00" * len(code)
           elif current == "*":
               "Discouraged"
               code = code
               raise DeprecationWarning("Discouraged")
           elif current == "2":
               "2D"
               size = 1 << (len(code).bit_length() // 2)
               code = sum(map(list, zip(*zip(*[iter(code)] * size))), [])
           elif current == "1":
               "1D"
               code = code[::-1]
           elif current == "t":
               "True"
               # lambda calculus
               try:
                   code.pop(1)
               except BaseException:
                   print(current == "t")
               code.append(repr(lambda x, y: x))
           elif current == "f":
               "False"
               # lambda calculus
               try:
                   code.pop(0)
               except BaseException:
                   print(current != "f")
           elif current == "(":
               "Start"
               code = old_code
           elif current == ")":
               "End, ("
               code.clear()
           elif current == " ":
               # more lambda calculus
               current = code.pop(0)
               if current == "t":
                   code.append(str(lambda x, y: x))
               elif current == "f":
                   code.append(str(lambda x, y: y))
           else:
               yield from code
               while ...:
                   ...
  
   
   def main():
       assert not(__name__=="__main__"and __import__("ctypes").string_at(0))
   
   
   main()
   
   
   # Code by IFcoltransG
   license = """
   This is free and unencumbered software released into the public domain.
   
   Anyone is free to copy, modify, publish, use, compile, sell, or
   distribute this software, either in source code form or as a compiled
   binary, for any purpose, commercial or non-commercial, and by any
   means.
   
   In jurisdictions that recognize copyright laws, the author or authors
   of this software dedicate any and all copyright interest in the
   software to the public domain. We make this dedication for the benefit
   of the public at large and to the detriment of our heirs and
   successors. We intend this dedication to be an overt act of
   relinquishment in perpetuity of all present and future rights to this
   software under copyright law.
   
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
   OTHER DEALINGS IN THE SOFTWARE.
   
   For more information, please refer to <http://unlicense.org/>
   """
   del license