Skip to content

Instantly share code, notes, and snippets.

@PyMaster22
Last active February 22, 2022 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PyMaster22/5f88962a238027e2381149c513ca7dac to your computer and use it in GitHub Desktop.
Save PyMaster22/5f88962a238027e2381149c513ca7dac to your computer and use it in GitHub Desktop.
Underload in python
def underload(code,stack=[],out="",emulator=0):
depth=0
tmp=""
for cmd in code:
try:
if(depth==0):
if(cmd=="~"):
tmp1=stack[-1]
tmp2=stack[-2]
stack[-1]=tmp2
stack[-2]=tmp1
if(cmd==":"):stack.append(stack[-1])
if(cmd=="!"):stack.pop()
if(cmd=="*"):
tmp1=stack.pop()
tmp2=stack.pop()
stack.append(tmp2+tmp1)
if(cmd=="^"):
#This should double the recursion limit. If anyone can make a better version I'd like to see it.
if(stack[-1][-1]=="^"):
stack,out=underload(stack.pop()[:-1],stack,out,1)
stack,out=underload(stack.pop(),stack,out,1)
else:stack,out=underload(stack.pop(),stack,out,1)
if(cmd=="a"):stack.append("("+stack.pop()+")")
if(cmd=="S"):out+=stack.pop()
if(depth>0):tmp+=cmd
if(cmd=="("):depth+=1
if(cmd==")"):
depth-=1
if(depth==0):
stack.append(tmp[:-1])
tmp=""
if(depth<0):raise Exception("UNDERLOAD: Depth has gone below 0")
except KeyboardInterrupt:
break
if(emulator==1):
return(stack,out)
else:
return(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment