正文
:
return
self.stack.pop()
@property
def
top
(self)
:
return
self.stack[
-1
]
我们通过 dispatch 方法,来判断当前从指令列表中取得的片段是指令还是数据:
def dispatch(self, opcode):
dispatch_map = {
"%": self.mod,
"*": self.mul,
"+": self.plus,
"-": self.minus,
"/": self.div,
"==": self.eq,
"cast_int": self.cast_int,
"cast_str": self.cast_str,
"drop": self.drop,
"dup": self.dup,
"exit": self.exit,
"if": self.if_stmt,
"jmp": self.jmp,
"over": self.over,
"print": self.print,
"println": self.println,
"read": self.read,
"stack": self.dump_stack,
"swap"