Exemplo n.º 1
0
    def run(self):
        while self.pc < len(self.code.code):
            op = self.next_instruction()

            arg = 0
            if compile.isjump(op):
                arg = self.read_arg4()
            elif compile.hasarg(op):
                arg = self.read_smallarg()

            if self.debug:
                print '(%d) pc:%d op: %d (%s) args %d' % (self.debug_level, self.pc, op, disass.opcode2name[op], arg)
                print disass.disassemble(self.code, '(%d)' % self.debug_level, pc = self.pc)

            if op == compile.INT_LITERAL:
                self.op_int_literal(arg)
            elif op == compile.SET_LOCAL:
                # TODO something is strange
                t = self.stack.pop()
                self.op_implicit_self()
                self.stack.append(t)
                self.op_assignment(arg)
            elif op == compile.PRIMITIVE_METHOD_CALL:
                self.op_primitive_method_call(arg)
            elif op == compile.POP:
                self.stack.pop()
            elif op == compile.GET_LOCAL:
                self.op_implicit_self()
                self.op_method_lookup(arg)
                self.op_method_call(0)
            elif op == compile.JUMP_IF_FALSE:
                self.op_jump_if_false(arg)
            elif op == compile.JUMP:
                self.op_jump(arg)
            elif op == compile.MAKE_OBJECT:
                self.op_make_object(arg)
            elif op == compile.MAKE_OBJECT_CALL:
                self.op_make_object_call(arg)
            elif op == compile.ASSIGNMENT_APPEND_PARENT:
                self.op_assignment_append_parrent(arg)
            elif op == compile.METHOD_LOOKUP:
                self.op_method_lookup(arg)
            elif op == compile.METHOD_CALL:
                self.op_method_call(arg)
            elif op == compile.DUP:
                self.op_dup()
            elif op == compile.ASSIGNMENT:
                self.op_assignment(arg)
            elif op == compile.MAKE_FUNCTION:
                self.op_make_function(arg)
            elif op == compile.IMPLICIT_SELF:
                self.op_implicit_self()
            else:
                raise NotImplementedError(compile.opcode_names[op])
        return self.context
Exemplo n.º 2
0
 def dis(self, pc=-1):
     from disass import disassemble
     disassemble(self, pc=pc)