mirror of
https://github.com/michaelcmartin/Ophis.git
synced 2025-08-08 12:25:04 +00:00
Fix both incomplete and overaggressive use of the charmap
This commit is contained in:
@@ -122,7 +122,7 @@ def pragmaCharmap(ppt, line, result):
|
|||||||
if str(line.lookahead(0)) == "EOL":
|
if str(line.lookahead(0)) == "EOL":
|
||||||
currentcharmap = basecharmap
|
currentcharmap = basecharmap
|
||||||
else:
|
else:
|
||||||
bytes = readData(line)
|
bytes = readRawData(line)
|
||||||
try:
|
try:
|
||||||
base = bytes[0].data
|
base = bytes[0].data
|
||||||
newsubstr = "".join([chr(x.data) for x in bytes[1:]])
|
newsubstr = "".join([chr(x.data) for x in bytes[1:]])
|
||||||
@@ -254,8 +254,26 @@ def pragmaCbmfloat(ppt, line, result):
|
|||||||
result.append(IR.Node(ppt, "Byte", *bytes))
|
result.append(IR.Node(ppt, "Byte", *bytes))
|
||||||
|
|
||||||
|
|
||||||
def readData(line):
|
def readRawData(line):
|
||||||
"Read raw data from a comma-separated list"
|
"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]
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def readData(line):
|
||||||
|
"Read charmap-translated data from a comma-separated list"
|
||||||
if line.lookahead(0).type == "STRING":
|
if line.lookahead(0).type == "STRING":
|
||||||
data = [IR.ConstantExpr(ord(x))
|
data = [IR.ConstantExpr(ord(x))
|
||||||
for x in line.expect("STRING").value.translate(currentcharmap)]
|
for x in line.expect("STRING").value.translate(currentcharmap)]
|
||||||
@@ -265,7 +283,7 @@ def readData(line):
|
|||||||
while next == ',':
|
while next == ',':
|
||||||
if line.lookahead(0).type == "STRING":
|
if line.lookahead(0).type == "STRING":
|
||||||
data.extend([IR.ConstantExpr(ord(x))
|
data.extend([IR.ConstantExpr(ord(x))
|
||||||
for x in line.expect("STRING").value])
|
for x in line.expect("STRING").value.translate(currentcharmap)])
|
||||||
else:
|
else:
|
||||||
data.append(FE.parse_expr(line))
|
data.append(FE.parse_expr(line))
|
||||||
next = line.expect(',', 'EOL').type
|
next = line.expect(',', 'EOL').type
|
||||||
@@ -332,5 +350,5 @@ def pragmaInvoke(ppt, line, result):
|
|||||||
if line.lookahead(0).type == "EOL":
|
if line.lookahead(0).type == "EOL":
|
||||||
args = []
|
args = []
|
||||||
else:
|
else:
|
||||||
args = readData(line)
|
args = readRawData(line)
|
||||||
result.append(IR.Node(ppt, "MacroInvoke", macro, *args))
|
result.append(IR.Node(ppt, "MacroInvoke", macro, *args))
|
||||||
|
@@ -401,6 +401,10 @@ def test_subfiles():
|
|||||||
'.charmap\n'
|
'.charmap\n'
|
||||||
'.byte "hELLO, wORLD!",10\n',
|
'.byte "hELLO, wORLD!",10\n',
|
||||||
b"Hello, World!\nhELLO, wORLD!\n")
|
b"Hello, World!\nhELLO, wORLD!\n")
|
||||||
|
test_string(".charmap (multi-arg)",
|
||||||
|
'.charmap \'A, "abcdefghijklmnopqrstuvwxyz"\n'
|
||||||
|
'.charmap \'a, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\n'
|
||||||
|
'.byte "hELLO, ", "wORLD!",10\n', b"Hello, World!\n")
|
||||||
test_string(".charmap (out of range)",
|
test_string(".charmap (out of range)",
|
||||||
'.charmap 250, "ABCDEFGHIJKLM"\n.byte 250,251',
|
'.charmap 250, "ABCDEFGHIJKLM"\n.byte 250,251',
|
||||||
b'')
|
b'')
|
||||||
|
Reference in New Issue
Block a user