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 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 QWORD [rsp + {var_pos}], {new_value}\n\t")
lines.append(f"mov {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: 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 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 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: 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.") 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: 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("; ~~~ Auto generated by the GroundPY compiler for Linux x86_64 targets. ~~~\n\n")
f.write("section .data\n") if len(self.constants) > 0:
for name, const in self.constants.items(): f.write("section .data\n")
value = const["value"] for name, const in self.constants.items():
f.write(name + ": ") value = const["value"]
value_type = type(value) f.write(name + ": ")
if value_type == str: value_type = type(value)
if not const["no_string"]: if value_type == str:
value = value.replace("\"", "\", 34, \"") if not const["no_string"]:
value = value.replace("\r", "\", 13, \"") value = value.replace("\"", "\", 34, \"")
value = value.replace("\n", "\", 10, \"") value = value.replace("\r", "\", 13, \"")
value = value.replace("\a", "\", 7, \"") value = value.replace("\n", "\", 10, \"")
value = value.replace("\a", "\", 7, \"")
final = f'db "' + value + "\", 0" final = f'db "' + value + "\", 0"
final = final.replace(", \"\", ", ", ") final = final.replace(", \"\", ", ", ")
f.write(final) f.write(final)
else: else:
f.write(value) f.write(value)
elif value_type == float or value_type == int: elif value_type == float or value_type == int:
f.write(f"dq {float(value)}") f.write(f"dq {float(value)}")
f.write("\n") f.write("\n")
f.write("section .bss\n") if len(self.buffers) > 0:
for buf, size in self.buffers.items(): f.write("section .bss\n")
f.write(f"{buf} resb {size}\n") for buf, size in self.buffers.items():
f.write(f"{buf} resb {size}\n")
f.write("section .text\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