當前位置: 首頁>>代碼示例>>Python>>正文


Python Frontend.parse_expr方法代碼示例

本文整理匯總了Python中Ophis.Frontend.parse_expr方法的典型用法代碼示例。如果您正苦於以下問題:Python Frontend.parse_expr方法的具體用法?Python Frontend.parse_expr怎麽用?Python Frontend.parse_expr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Ophis.Frontend的用法示例。


在下文中一共展示了Frontend.parse_expr方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pragmaIncbin

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def pragmaIncbin(ppt, line, result):
    "Includes a binary file"
    filename = line.expect("STRING").value
    offset = IR.ConstantExpr(0)
    size = None
    if str(line.lookahead(0)) == ",":
        line.pop()
        offset = FE.parse_expr(line)
        if str(line.lookahead(0)) == ",":
            line.pop()
            size = FE.parse_expr(line)
    line.expect("EOL")
    if type(filename) == str:
        try:
            f = file(os.path.join(FE.context_directory, filename), "rb")
            if offset.hardcoded and (size is None or size.hardcoded):
                # We know how big it will be, we can just use the values.
                # First check to make sure they're sane
                if offset.value() < 0:
                    Err.log("Offset may not be negative")
                    f.close()
                    return
                f.seek(0, 2)  # Seek to end of file
                if offset.value() > f.tell():
                    Err.log("Offset runs past end of file")
                    f.close()
                    return
                if size is not None:
                    if size.value() < 0:
                        Err.log("Length may not be negative")
                        f.close()
                        return
                    if offset.value() + size.value() > f.tell():
                        Err.log(".incbin length too long")
                        f.close()
                        return
                if size is None:
                    size = IR.ConstantExpr(-1)
                f.seek(offset.value())
                bytes = f.read(size.value())
                bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
                result.append(IR.Node(ppt, "Byte", *bytes))
            else:
                # offset or length could change based on label placement.
                # This seems like an unbelievably bad idea, but since we
                # don't have constant prop it will happen for any symbolic
                # alias. Don't use symbolic aliases when extracting tiny
                # pieces out of humongous files, I guess.
                bytes = f.read()
                bytes = [IR.ConstantExpr(ord(x)) for x in bytes]
                if size is None:
                    size = IR.SequenceExpr([IR.ConstantExpr(len(bytes)),
                                            "-",
                                            offset])
                result.append(IR.Node(ppt, "ByteRange", offset, size, *bytes))
            f.close()
        except IOError:
            Err.log("Could not read " + filename)
            return
開發者ID:ZaneDubya,項目名稱:MetroidMMC3,代碼行數:61,代碼來源:CorePragmas.py

示例2: pragmaAdvance

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def pragmaAdvance(ppt, line, result):
    "Outputs filler until reaching the target PC"
    newPC = FE.parse_expr(line)
    if str(line.lookahead(0)) == ",":
        line.pop()
        fillexpr = FE.parse_expr(line)
    else:
        fillexpr = IR.ConstantExpr(0)
    line.expect("EOL")
    result.append(IR.Node(ppt, "Advance", newPC, fillexpr))
開發者ID:ZaneDubya,項目名稱:MetroidMMC3,代碼行數:12,代碼來源:CorePragmas.py

示例3: readData

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def readData(line):
	"Read raw data from a comma-separated list"
	if line.lookahead(0).type == "STRING":
		data = [IR.ConstantExpr(ord(x)) for x in line.expect("STRING").value.translate(currentcharmap)]
	else:
		data = [FE.parse_expr(line)]
	next = line.expect(',', 'EOL').type
	while next == ',':
		if line.lookahead(0).type == "STRING":
			data.extend([IR.ConstantExpr(ord(x)) for x in line.expect("STRING").value])
		else:
			data.append(FE.parse_expr(line))
		next = line.expect(',', 'EOL').type
	return data
開發者ID:PlayBoyMan,項目名稱:happiNES-dev,代碼行數:16,代碼來源:CorePragmas.py

示例4: pragmaAlias

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def pragmaAlias(ppt, line, result):
    "Assigns an arbitrary label"
    lbl = line.expect("LABEL").value
    target = FE.parse_expr(line)
    result.append(IR.Node(ppt, "Label", lbl, target))
開發者ID:ZaneDubya,項目名稱:MetroidMMC3,代碼行數:7,代碼來源:CorePragmas.py

示例5: pragmaCheckpc

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def pragmaCheckpc(ppt, line, result):
    "Enforces that the PC has not exceeded a certain point"
    target = FE.parse_expr(line)
    line.expect("EOL")
    result.append(IR.Node(ppt, "CheckPC", target))
開發者ID:ZaneDubya,項目名稱:MetroidMMC3,代碼行數:7,代碼來源:CorePragmas.py

示例6: pragmaOrg

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def pragmaOrg(ppt, line, result):
    "Relocates the PC with no output"
    newPC = FE.parse_expr(line)
    line.expect("EOL")
    result.append(IR.Node(ppt, "SetPC", newPC))
開發者ID:ZaneDubya,項目名稱:MetroidMMC3,代碼行數:7,代碼來源:CorePragmas.py

示例7: pragmaAdvance

# 需要導入模塊: from Ophis import Frontend [as 別名]
# 或者: from Ophis.Frontend import parse_expr [as 別名]
def pragmaAdvance(ppt, line, result):
	"Outputs filler until reaching the target PC"
	newPC = FE.parse_expr(line)
	line.expect("EOL")
	result.append(IR.Node(ppt, "Advance", newPC))
開發者ID:PlayBoyMan,項目名稱:happiNES-dev,代碼行數:7,代碼來源:CorePragmas.py


注:本文中的Ophis.Frontend.parse_expr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。