def pop(self): if self.sp == 0: bail("stack underflow") self.sp -= 1 result = self.stack[self.sp] #self.stack[self.sp] = 0 # XXX return result
def set_reg(self, r, v): for i in unrolling_reg_range: if r == i: setattr(self, "r%s" % i, v) break else: bail("unknown register %s" % r)
def main(argv): if len(argv) < 2: bail("bad usage") hndl = open_file_as_stream(argv[1]) prog = parse.parse(hndl.readall()) hndl.close() args = [ int(x) for x in argv[2:] ] prog.run(args) return 0
def parse_instr(s): """ Parses a simple OP [ARG1 [, ... ,ARGN]] """ words = s.split(" ") opcode = words[0] args_raw = string.join(words[1:], "").split(",") if len(words) > 1 else [] f, nargs = OPTAB.get(opcode, (None, -1)) if nargs == -1: bail("unknown opcode: '%s'" % opcode) # check number of args is good num_args = len(args_raw) if len(args_raw) != nargs: bail("wrong arg count: %s" % opcode) args = [ parse_operand(x) for x in args_raw ] # Note that you cant reflect on functions in rpython, so we # have to pass the name of the opcode in aswell as the function # itself. Ideally we would have done: f.function_name, however, # this is not RPython return Instr(f, opcode, args)
def parse_instr(s): """ Parses a simple OP [ARG1 [, ... ,ARGN]] """ words = s.split(" ") opcode = words[0] args_raw = string.join(words[1:], "").split(",") if len(words) > 1 else [] f, nargs = OPTAB.get(opcode, (None, -1)) if nargs == -1: bail("unknown opcode: '%s'" % opcode) # check number of args is good num_args = len(args_raw) if len(args_raw) != nargs: bail("wrong arg count: %s" % opcode) args = [parse_operand(x) for x in args_raw] # Note that you cant reflect on functions in rpython, so we # have to pass the name of the opcode in aswell as the function # itself. Ideally we would have done: f.function_name, however, # this is not RPython return Instr(f, opcode, args)
def get_label(self, x): label = self._get_label(x) if label == -1: bail("undefined label: %s" % x) return label
def get_reg(self, x): for i in unrolling_reg_range: if x == i: return getattr(self, "r%s" % i) bail("unknown register %s" % x)
def pick(self, x): index = self.sp - x - 1 if not (0 <= index < self.sp): bail("stack underflow") return self.stack[index]
def push(self, x): if self.sp >= STACKSIZE: bail("stack overflow") self.stack[self.sp] = x self.sp += 1