本文整理汇总了Python中memory.Memory.push_stack方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.push_stack方法的具体用法?Python Memory.push_stack怎么用?Python Memory.push_stack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类memory.Memory
的用法示例。
在下文中一共展示了Memory.push_stack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vm
# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import push_stack [as 别名]
class Vm(object):
def __init__(self, srcfile):
self.src = srcfile
self.m = Memory(17)
self.p = Program()
def run(self):
self.parse()
i = Int(0)
while self.p.instrs[int(i)] != opcode._OP_END:
self.runInstruction(i)
i += 1
def runInstruction(self, instrIndex):
instr = self.p.instrs[int(instrIndex)]
a0, a1 = int(instrIndex)*2, (int(instrIndex)*2)+1
if instr == opcode._OP_NOP:
pass
elif instr == opcode._OP_INT:
raise NotImplementedException
elif instr == opcode._OP_MOV:
self.p.args[a0].set(int(self.p.args[a1]))
elif instr == opcode._OP_PUSH:
self.m.push_stack(self.p.args[a0])
elif instr == opcode._OP_POP:
self.p.args[a0].set(self.m.pop_stack())
elif instr == opcode._OP_PUSHF:
self.m.push_stack(self.m.FLAGS)
elif instr == opcode._OP_POPF:
self.m.FLAGS = self.m.pop_stack()
elif instr == opcode._OP_INC:
self.p.args[a0] += 1
elif instr == opcode._OP_DEC:
self.p.args[a0] -= 1
elif instr == opcode._OP_ADD:
self.p.args[a0] += int(self.p.args[a1])
elif instr == opcode._OP_SUB:
self.p.args[a0] -= int(self.p.args[a1])
elif instr == opcode._OP_MUL:
self.p.args[a0] *= int(self.p.args[a1])
elif instr == opcode._OP_DIV:
self.p.args[a0] /= int(self.p.args[a1])
elif instr == opcode._OP_MOD:
self.m.remainder = self.p.args[a0] % int(self.p.args[a1])
elif instr == opcode._OP_REM:
self.p.args[a0].set(Int(self.m.remainder))
elif instr == opcode._OP_AND:
self.p.args[a0] &= int(self.p.args[a1])
elif instr == opcode._OP_SHL:
if self.p.args[a1] > 0:
self.p.args[a0] <<= int(self.p.args[a1])
elif instr == opcode._OP_SHR:
if self.p.args[a1] > 0:
self.p.args[a0] >>= int(self.p.args[a1])
elif instr == opcode._OP_NOT:
self.p.args[a0] = ~self.p.args[a0]
elif instr == opcode._OP_OR:
self.p.args[a0] |= int(self.p.args[a1])
elif instr == opcode._OP_XOR:
self.p.args[a0] ^= int(self.p.args[a1])
elif instr == opcode._OP_CMP:
if self.p.args[a0] == int(self.p.args[a1]):
self.m.FLAGS = 0x1
elif self.p.args[a0] > int(self.p.args[a1]):
self.m.FLAGS = 0x2
else:
self.m.FLAGS = 0x0
elif instr == opcode._OP_CALL:
self.m.push_stack(int(instrIndex))
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_JMP:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_RET:
instrIndex.set(self.m.pop_stack())
elif instr == opcode._OP_JE:
if self.m.FLAGS & 0x1 != 0:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_JNE:
if self.m.FLAGS & 0x1 == 0:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_JG:
if self.m.FLAGS & 0x2 != 0:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_JGE:
if self.m.FLAGS & 0x3 != 0:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_JL:
if self.m.FLAGS & 0x3 == 0:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_JLE:
if self.m.FLAGS & 0x2 == 0:
instrIndex.set(int(self.p.args[a0])-1)
elif instr == opcode._OP_PRN:
print(self.p.args[a0])
def parse_value(self, tok, instrIndex, argIndex):
number = toValue(tok)
self.p.args[(instrIndex * 2) + argIndex] = number
return True
#.........这里部分代码省略.........