Vague/OliveIsAWord

From Esolang
Jump to navigation Jump to search

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

#!/user/bin/python
"""
The only implementation of Vague.
Note that this implementation of Vague (the only one) has implementation
defined by modules `stack` and `unsafe`, which may or may not be installed
"""

VERSION = '1.0.0'

def main():
    """Vague."""
    from sys import argv, exit
    if (argc := len(argv)) != 2:
        print(f'Error: expected 1 argument, found {argc - 1}', file=sys.stderr)
        print(f'Usage: {argv[0]} FILEPATH', file=sys.stderr)
        exit(-8)
    with open(argv[1]) as f:
        execute(f.read())

def execute(program):
    """Runs."""
    import stack, unsafe
    for c in program:
        if c == '+': print('Add')
        if c == '-': print('Decrement')
        if c == '!': print('Print')
        if c == '>': print('Right')
        if c == '<': print('Left')
        if c == '&': print('NAND')
        if c == '=': print('Push')
        if c == '_': print('Pop')
        if c == '.': print('End')
        if c == '0': print('Zero')
        if c == '*':
            # Safety: None
            with unsafe('ERROR: discourage overflow'):
                stack.DISCOURAGED
        if c == '2': print('2D')
        if c == '1': print('1D')
        if c == 't': print('True')
        if c == 'f':
            stack += false
        if c == '(': print('Start')
        if c == ')': print('End (')














""" """
g=globals()
import contextlib as c,sys,random as r
class s:
 g['false']=False
 def g(g,_):return g
 __iadd__,__getattr__=g,g
class d:
 def find_module(*_):return d()
 def load_module(_,f):sys.modules[f]=s()if len(f)%2 else u
@c.contextmanager
def u(u):
 try:
  for e in r.sample(list(g.keys()),len(g)//2):g[e]=g.copy()
 except:print(u)
 finally:yield
sys.meta_path.insert(0,d())
if __name__=='__main__':main()