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


Python Core.call_READ方法代码示例

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


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

示例1: __init__

# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import call_READ [as 别名]
class Machine:
    def __init__(self, tapesize):
        self.SRC = []               # Source program file
        self.LOOKUP = []            # Initial lookup table instance
        self.CORE = Core()          # Initial machine Core instance
        self.TAPE = self.CORE.TAPE  # Initial Tape instance
        self.TAPE.SIZE = tapesize   # Tape size is number of frames on tape.
        self.RUN = True             # Machine run state

        # Initialize each TAPE.FRAME value at zero.
        for frame in range(self.TAPE.SIZE):
            self.TAPE.FRAMES.append(0);

            
#----------------------------------------------------------------------
# Runtime
    
    # Machine.run initializes a tape and program runtime.
    # It either loads a program from file, or starts a repl instance.

    def run(self):

        # A program source file was provided.
        if len(sys.argv) > 1:
            self.SRC.append(self.load_tape_file())
            self.program_execute(self.SRC[0][sys.argv[1]])

        # No source file provided, run repl interpretter.
        else:
            while self.RUN:

                # Get repl input, assign PROMPT information.
                # User input gets assigned to the 'command' variable.

                self.SRC.append(input('frame ' + str(self.TAPE.FP) + ' :'))
                command = self.SRC[len(self.SRC)-1]
                
                # Exit on input of 'q'

                if command is 'q':
                    print('exiting...')
                    exit(0)
                
                # Call program_step, provides 'command' as argument.
                
                else:
                    self.program_step(command)

#----------------------------------------------------------------------
# Interpretter implementation

    def program_step(self, line):
        i = 0
        
        # Amount to skip ahead (i) in line
        skip = 0 

        line = line.split(' ')
        line_length = len(line)

        while i < line_length:
                
            # INC increment tape ( + )

            if line[i] is self.CORE.instructions[0]:
                self.CORE.call_INC()

            # DEC decrement tape ( - )

            elif line[i] is self.CORE.instructions[1]:
                self.CORE.call_DEC()            

            # WRITE to current frame ( .w )            

            elif line[i] == self.CORE.instructions[2]:
                if line_length > 1:
                    self.CORE.call_WRITE(line)
                else:
                    print('WARNING: Missing a value to write after ( .w )')
 
            # READ a frame's value ( .r )  
            # Read from current Frame Pointer, or specified index
            # Usage: .r [blank] or .r [index] or .r [namespace]

            elif line[i] == self.CORE.instructions[3]:
                if line_length > 1:
                    arg = line[i+1]
                    self.CORE.call_READ(arg)

                # No specific read argument was provided, so read the current frame.
                else:
                    value = self.TAPE.FRAMES[self.TAPE.FP]
                    print(value)

            # SEGMENT instruction ( .s )
            # Create a new named segment, or un-named segment.
            # Usage: .s .n [mysegment], or just the ( .s ) command.
 
            elif line[i] == '.s':

#.........这里部分代码省略.........
开发者ID:bFraley,项目名称:avtm,代码行数:103,代码来源:machine.py


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