fixing a couple bugs

This commit is contained in:
SpookyDervish
2025-09-14 05:37:47 +10:00
parent f561a849c2
commit 0e37cccd7a
4 changed files with 32 additions and 30 deletions

View File

@@ -189,7 +189,7 @@ class X86_64Generator(Generator):
elif type(new_value) == str: # we're changing a variable to the value of a register
#lines.append(f"mov QWORD [rsp + {var_pos}], {new_value}\n\t")
lines.append(f"mov {var_pos}, {new_value}\n\t")
scope.table[var_name]["type"] = IntNode
#scope.table[var_name]["type"] = IntNode
else:
@@ -227,7 +227,8 @@ class X86_64Generator(Generator):
elif type(new_value) == str: # we're changing a variable to the value of a register
lines.append(f"mov QWORD [rsp + {var_pos}], {new_value}\n\t")
scope.table[var_name]["type"] = IntNode
#scope.table[var_name]["type"] = IntNode
if scope.table[var_name]["type"] != old_var_type:
warning(self.code, f"Changing the type of \"{var_name}\" at runtime is considered bad practice.")
@@ -697,30 +698,32 @@ class X86_64Generator(Generator):
with open(self.output_path + ".asm", "w") as f:
f.write("; ~~~ Auto generated by the GroundPY compiler for Linux x86_64 targets. ~~~\n\n")
f.write("section .data\n")
for name, const in self.constants.items():
value = const["value"]
f.write(name + ": ")
value_type = type(value)
if value_type == str:
if not const["no_string"]:
value = value.replace("\"", "\", 34, \"")
value = value.replace("\r", "\", 13, \"")
value = value.replace("\n", "\", 10, \"")
value = value.replace("\a", "\", 7, \"")
if len(self.constants) > 0:
f.write("section .data\n")
for name, const in self.constants.items():
value = const["value"]
f.write(name + ": ")
value_type = type(value)
if value_type == str:
if not const["no_string"]:
value = value.replace("\"", "\", 34, \"")
value = value.replace("\r", "\", 13, \"")
value = value.replace("\n", "\", 10, \"")
value = value.replace("\a", "\", 7, \"")
final = f'db "' + value + "\", 0"
final = final.replace(", \"\", ", ", ")
f.write(final)
else:
f.write(value)
elif value_type == float or value_type == int:
f.write(f"dq {float(value)}")
f.write("\n")
final = f'db "' + value + "\", 0"
final = final.replace(", \"\", ", ", ")
f.write(final)
else:
f.write(value)
elif value_type == float or value_type == int:
f.write(f"dq {float(value)}")
f.write("\n")
f.write("section .bss\n")
for buf, size in self.buffers.items():
f.write(f"{buf} resb {size}\n")
if len(self.buffers) > 0:
f.write("section .bss\n")
for buf, size in self.buffers.items():
f.write(f"{buf} resb {size}\n")
f.write("section .text\n")

BIN
out

Binary file not shown.

5
out.asm Normal file
View File

@@ -0,0 +1,5 @@
; ~~~ Auto generated by the GroundPY compiler for Linux x86_64 targets. ~~~
section .text
global _start
_start:

View File

@@ -1,6 +0,0 @@
@loop
stdout "/\r"
stdout "-\r"
stdout "\\r"
stdout "|\r"
jump %loop