AST works for variable reassignment

kinda coded horribly tho lol
This commit is contained in:
SpookyDervish
2025-10-14 19:22:59 +11:00
parent 5741a48e73
commit 655e5d1d12
7 changed files with 132 additions and 39 deletions

37
main.py
View File

@@ -3,14 +3,16 @@ from plasma_parser import Parser
from compiler import Compiler
from AST import Program
import json
import time
from llvmlite import ir
from llvmlite.binding import targets
import llvmlite.binding as llvm
from ctypes import CFUNCTYPE, c_int, c_float
LEXER_DEBUG: bool = False
PARSER_DEBUG: bool = False
COMPILER_DEBUG: bool = True
RUN_CODE: bool = False
if __name__ == "__main__":
@@ -44,8 +46,37 @@ if __name__ == "__main__":
c.compile(program)
module: ir.Module = c.module
module.triple = targets.get_default_triple()
module.triple = llvm.get_default_triple()
if COMPILER_DEBUG:
with open("debug/ir.ll", "w") as f:
f.write(str(module))
f.write(str(module))
if RUN_CODE:
#llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmparser()
llvm.initialize_native_asmprinter()
try:
llvm_ir_parsed = llvm.parse_assembly(str(module))
llvm_ir_parsed.verify()
except Exception as e:
print(e)
raise
target_machine = llvm.Target.from_default_triple().create_target_machine()
engine = llvm.create_mcjit_compiler(llvm_ir_parsed, target_machine)
engine.finalize_object()
entry = engine.get_function_address("main")
cfunc = CFUNCTYPE(c_int)(entry)
st = time.time()
result = cfunc()
et = time.time()
print(f"\n\nProgram returned: {result}\n=== Executed in {round((et - st) * 1000, 6)} ms. ===")