feat: JIT (WIP)

This commit is contained in:
2025-06-14 16:53:45 +08:00
parent 49255948ff
commit 7b6db44207
4 changed files with 96 additions and 39 deletions

View File

@@ -5,7 +5,7 @@ use inkwell::context::Context;
use inkwell::execution_engine::ExecutionEngine;
use inkwell::module::Module;
use inkwell::types::{FloatType, FunctionType, IntType, PointerType, StructType};
use inkwell::values::{BasicValueEnum, FunctionValue};
use inkwell::values::{BasicValueEnum, FloatValue, FunctionValue, IntValue};
use crate::env::VmEnv;
use crate::eval::Engine;
@@ -176,20 +176,28 @@ impl<'ctx> Helpers<'ctx> {
}
}
pub fn const_int(&self, int: i64) -> IntValue<'ctx> {
self.int_type.const_int(int as _, false)
}
pub fn new_int(&self, int: i64) -> BasicValueEnum<'ctx> {
self.value_type
.const_named_struct(&[
self.int_type.const_int(ValueTag::Int as _, false).into(),
self.int_type.const_int(int as _, false).into(),
self.const_int(int).into()
])
.into()
}
pub fn const_float(&self, float: f64) -> FloatValue<'ctx> {
self.float_type.const_float(float)
}
pub fn new_float(&self, float: f64) -> BasicValueEnum<'ctx> {
self.value_type
.const_named_struct(&[
self.int_type.const_int(ValueTag::Float as _, false).into(),
self.float_type.const_float(float).into(),
self.const_float(float).into()
])
.into()
}