当前位置: 首页>>代码示例>>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;未经允许,请勿转载。