This commit is contained in:
LunarAkai 2025-08-05 22:02:39 +02:00
commit d7795e52f9
10 changed files with 276 additions and 31 deletions

View file

@ -0,0 +1,29 @@
use std::collections::HashMap;
use inkwell::{builder::Builder, context::Context, module::Module, values::{FunctionValue, PointerValue}};
use crate::code_generation::Function;
pub struct Compiler<'a, 'ctx> {
pub context: &'ctx Context,
pub builder: &'a Builder<'ctx>,
pub module: &'a Module<'ctx>,
pub function: &'a Function,
variables: HashMap<String, PointerValue<'ctx>>,
fn_value_opt: Option<FunctionValue<'ctx>>
}
impl<'a, 'ctx> Compiler<'a, 'ctx> {
/// Gets a defined function given its name.
#[inline]
fn get_function(&self, name: &str) -> Option<FunctionValue<'ctx>> {
self.module.get_function(name)
}
/// Returns the `FunctionValue` representing the function being compiled.
#[inline]
fn fn_value(&self) -> FunctionValue<'ctx> {
self.fn_value_opt.unwrap()
}
}