本文整理汇总了Python中interpreter.Interpreter.preprocess方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.preprocess方法的具体用法?Python Interpreter.preprocess怎么用?Python Interpreter.preprocess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.preprocess方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import preprocess [as 别名]
class VM:
"""This class encapsulates all the VM processing."""
def __init__(self):
self.setUpLogging()
# Program counter: position of the next instruction to execute.
self.PC = 0
self.endAddress = 0
# Structure of the stores used in the vm.
self.variables = {}
self.code = []
self.rulesCode = []
self.macrosCode = []
self.preprocessCode = []
self.trie = SystemTrie()
# Current code section in execution (a macro, a rule, ...).
self.currentCodeSection = self.code
# Execution state of the vm.
self.status = VM_STATUS.HALTED
# Transfer stage (chunker, interchunk or postchunk).
self.transferStage = None
# Chunker mode to process in shallow mode or advanced transfer.
self.chunkerMode = None
# Input will be divided in words with their patterns information.
self.words = []
self.superblanks = []
self.lastSuperblank = -1
self.currentWords = []
self.nextPattern = 0
# Components used by the vm.
self.tokenizer = None
self.callStack = CallStack(self)
self.stack = SystemStack()
self.loader = None
self.interpreter = Interpreter(self)
# Components used only in debug mode.
self.debugger = None
self.debugMode = False
self.input = sys.stdin
# We use 'buffer' to get a stream of bytes, not str, because we want to
# encode it using utf-8 (just for safety).
self.output = sys.stdout.buffer
def setUpLogging(self):
"""Set at least an error through stderr logger"""
self.formatStr = "%(levelname)s: %(filename)s[%(lineno)d]:\t%(message)s"
self.logger = logging.getLogger("vm")
errorHandler = logging.StreamHandler(sys.stderr)
errorHandler.setFormatter(logging.Formatter(self.formatStr))
errorHandler.setLevel(logging.ERROR)
self.logger.addHandler(errorHandler)
def setDebugMode(self):
"""Set the debug mode, creating a debugger an setting it up as a proxy."""
self.debugMode = True
self.debugger = Debugger(self, self.interpreter)
# Set the debugger as a proxy.
self.interpreter = self.debugger
# Create a logging handler for debugging messages.
debugHandler = logging.StreamHandler(sys.stdout)
debugHandler.setFormatter(logging.Formatter(self.formatStr))
debugHandler.setLevel(logging.DEBUG)
self.logger.addHandler(debugHandler)
def setLoader(self, header, t1xFile):
"""Set the loader to use depending on the header of the code file."""
if "assembly" in header:
self.loader = AssemblyLoader(self, t1xFile)
else:
return False
return True
def setTransferStage(self, transferHeader):
"""Set the transfer stage to process by the vm."""
if "transfer" in transferHeader:
self.transferStage = TRANSFER_STAGE.CHUNKER
self.tokenizer = TransferWordTokenizer()
# Set chunker mode, by default 'lu'.
if "chunk" in transferHeader:
self.chunkerMode = CHUNKER_MODE.CHUNK
else:
self.chunkerMode = CHUNKER_MODE.LU
elif "interchunk" in transferHeader:
self.transferStage = TRANSFER_STAGE.INTERCHUNK
self.tokenizer = ChunkWordTokenizer()
elif "postchunk" in transferHeader:
#.........这里部分代码省略.........