How to Make a call stack work
Jump to navigation
Jump to search
Here is a call stack in python, yayayayayay
Code
class Callstack(Linecounter):
def __init__():
this.callstack = []
def push(code, lnum):
this.callstack.push([code, lnum])
def pop():
super().linenum = this.callstack.pop()
class Linecounter():
def __init__():
this.linenum = 0
def increment(x):
this.linenum += x
cstack = new Callstack()
linecount = new Linecounter()
cstack.push("main", 0)
linecount.increment(100)
cstack.pop()[0] #linenum now is 0, and there is nothing in the callstack