llvm-context: lazy handling of function arguments and immutable data (#282)

- Lazily load function arguments so that they can be passed as pointers.
- Lazily call the immutable store function to avoid storing zero sized
immutable data.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
xermicus
2025-04-14 15:54:59 +02:00
committed by GitHub
parent ad3315346c
commit 431b5a2ce5
18 changed files with 268 additions and 177 deletions
@@ -121,7 +121,7 @@ where
.insert_constant(identifier.inner.clone(), constant);
}
value.to_llvm()
value.access(context)?
}
None => r#type.const_zero().as_basic_value_enum(),
}
@@ -175,7 +175,8 @@ where
.collect::<Vec<inkwell::types::BasicTypeEnum<'ctx>>>()
.as_slice(),
);
if expression.value.get_type() != llvm_type.as_basic_type_enum() {
let value = expression.access(context)?;
if value.get_type() != llvm_type.as_basic_type_enum() {
anyhow::bail!(
"{} Assignment to {:?} received an invalid number of arguments",
location,
@@ -183,7 +184,7 @@ where
);
}
let pointer = context.build_alloca(llvm_type, "bindings_pointer");
context.build_store(pointer, expression.to_llvm())?;
context.build_store(pointer, value)?;
for (index, binding) in self.bindings.into_iter().enumerate() {
let pointer = context.build_gep(