当前位置: 首页>>代码示例>>Python>>正文


Python Memory.clear方法代码示例

本文整理汇总了Python中memory.Memory.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.clear方法的具体用法?Python Memory.clear怎么用?Python Memory.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在memory.Memory的用法示例。


在下文中一共展示了Memory.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DCPU

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import clear [as 别名]
class DCPU(object):
    HEX_OUTPUT_FORMAT = "%#06x"
    MAX_VAL = bitmask(specs.WORD_SIZE)

    def __init__(self):
        self.cycles_ran = 0
        self.registers = Memory(specs.WORD_SIZE)

        self.reset_registers()

        self.RAM = RAM(specs.WORD_SIZE, specs.MAX_RAM_ADDRESS)

        self.basic_ops = {
            specs.BasicOperations.SET: self.set,
            specs.BasicOperations.ADD: self.add,
            specs.BasicOperations.SUB: self.subtract,
            specs.BasicOperations.MUL: self.multiply,
            specs.BasicOperations.DIV: self.divide,
            specs.BasicOperations.MOD: self.modulo,
            specs.BasicOperations.SHL: self.shift_left,
            specs.BasicOperations.SHR: self.shift_right,

            specs.BasicOperations.AND:
                lambda a, b: self.boolean_operation(operator.and_, a, b),

            specs.BasicOperations.BOR:
                lambda a, b: self.boolean_operation(operator.or_, a, b),

            specs.BasicOperations.XOR:
                lambda a, b: self.boolean_operation(operator.xor, a, b),

            specs.BasicOperations.IFE:
                lambda a, b: self.if_condition(operator.eq, a, b),

            specs.BasicOperations.IFN:
                lambda a, b: self.if_condition(operator.ne, a, b),

            specs.BasicOperations.IFG:
                lambda a, b: self.if_condition(operator.gt, a, b),

            specs.BasicOperations.IFB:
                lambda a, b: self.if_condition(operator.and_, a, b),
        }

        self.non_basic_ops = {
            specs.NonBasicOperations.JSR: self.jump_and_set_return,
        }


    def cycles(num_cycles):
        '''
        Decorator used to specify the number of cycles
        taken by a function
        '''

        def cycle_decorator(fn):
            def wrapper(self, *args, **kwargs):
                self.cycles_ran += num_cycles

                return fn(self, *args, **kwargs)
            return wrapper

        return cycle_decorator

    '''
    Helper functions to access the special register values: SP, PC, 0
    '''

    @property
    def PC(self):
        return self.registers[specs.SPECIAL_REGISTER_NAMES['PC']]

    @PC.setter
    def PC(self, value):
        self.registers[specs.SPECIAL_REGISTER_NAMES['PC']] = value

    @property
    def SP(self):
        return self.registers[specs.SPECIAL_REGISTER_NAMES['SP']]

    @SP.setter
    def SP(self, value):
        self.registers[specs.SPECIAL_REGISTER_NAMES['SP']] = value

    @property
    def O(self):
        return self.registers[specs.SPECIAL_REGISTER_NAMES['O']]

    @O.setter
    def O(self, value):
        self.registers[specs.SPECIAL_REGISTER_NAMES['O']] = value

    def reset_registers(self):
        '''
        Set all registers to default values
        '''

        self.registers.clear()
        self.SP = specs.MAX_RAM_ADDRESS

#.........这里部分代码省略.........
开发者ID:jpmunz,项目名称:0x10c,代码行数:103,代码来源:dcpu.py

示例2: getList

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import clear [as 别名]
class Board:
    """
    Board definition and handling
    """
    
    
    @staticmethod
    def getList():
        """
        Return the list of boards described into the configuration file
        """
        boardDir = Config.getBoardDir()
        boardFile = os.path.join(boardDir, "board_description.cfg")
        Board.config = Config(boardFile)
        boardList = Board.config.getItems("Boards")
        return boardList
        
    def __init__(self, boardName, display):
        """
        initialize a board by loading its definition
        
        @param boardName: name of board in board description file
        @type  boardName: string
        @param display:   where to display board
        @type  display:   Windows
        """
        self.display = display
        self.deviceModuleList = []
        self.program    = None
        self.boardHelp  = None
        self.archHelp   = None
        
        self.loadDefinition(boardName)

   
    def loadDefinition(self, boardName):
        """
        load the board definition from the definition file
        
        @param boardName: name of board to look for in the description file
        @type  boardName: string
        """
        items = Board.config.getItems(boardName)
        self.deviceList = []
        for item in items:
            name = item[0]
            value = item[1]
            if name == "arch":
                self.archName = value
            elif name == "memory":
                if (value == "max"):
                    self.memorySize = -1
                else:
                    self.memorySize = int(value)
            elif name[0:6] == "device":
                device = shlex.split(value, "#")
                self.deviceList.append(device)
            elif name == "help":
                fileName = os.path.join(Config.getBoardDir(), value)
                if os.path.isfile(fileName):
                    self.boardHelp = fileName
    
    def build(self):
        """
        Build the board:
        . load its architecture: chip with registers, opcodes and so on
        . load its controller definition and initialize them
        . initialize its memory
        . attach controllers to their I/O addresses
        """
        archDir = Config.getArchDir()
        archPath = os.path.join(archDir, "arch_" + self.archName + ".py")
        self.archModule = imp.load_source(self.archName, archPath)
        self.archHelp = os.path.join(archDir, "arch_" + self.archName + ".html")
        if not os.path.isfile(self.archHelp):
            self.archHelp = None
        self.chip = self.archModule.Chip()
        if (self.memorySize == -1):
            self.memorySize = 2 ** (self.chip.getAddressSize() * 8)
        self.controller = Controller(self.display)
        self.controller.loadDeviceList()
        self.memory = Memory(self, self.memorySize)
        self.memory.addController(self.controller)
         
        for device in self.deviceList:
            self.deviceModuleList.append(self.controller.createDevice(device))
            
    def clear(self):
        """
        Clear the board: reset memory and chip (PC, SP, other registers and so on)
        """
        self.memory.clear()
        self.chip.clear()
            
    def delete(self):
        """
        Delete the board: remove attached controllers
        """
        self.controller.delete()
 
#.........这里部分代码省略.........
开发者ID:lfaipot,项目名称:board-simu,代码行数:103,代码来源:board.py


注:本文中的memory.Memory.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。