Skip to content
Snippets Groups Projects
Commit aa686735 authored by Xun Yang's avatar Xun Yang
Browse files

char as ASCII

parent ec03526f
No related branches found
No related tags found
2 merge requests!30New new string,!20Master
......@@ -35,6 +35,13 @@ class LiteralNode(ASTNode):
self.value = False
else:
self.value = True
if self.value == "'\\n'":
self.value = ord('\n')
elif self.name == 'char' and len(self.value) == 3:
self.value = ord(self.value[1])
elif self.name == 'char':
self.value = ord(self.value)
def linkType(self):
if self.name == "java.lang.String":
......@@ -57,7 +64,8 @@ class LiteralNode(ASTNode):
# char
if self.name == 'char':
self.code += p("mov", "eax", str("dword " + self.getConstant()), " set to literal char")
# store literal char as ASCII
self.code += p("mov", "eax", str(self.getConstant()), " set to literal char")
return
# string
......@@ -92,7 +100,7 @@ class LiteralNode(ASTNode):
self.code += ";Start of populating char array\n"
# loop through string
for i in range(len(value)):
self.code += p(instruction="mov", arg1="[eax+"+str(8+i*4)+"]", arg2=str("dword '"+value[i]+"'"), comment="a["+str(i)+"]="+str(value[i]))
self.code += p(instruction="mov", arg1="[eax+"+str(8+i*4)+"]", arg2="dword " + str(ord(value[i])), comment="a["+str(i)+"]="+str(value[i]))
self.code += ";End of populating char array\n"
# 5. Restoring ecx
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment