Big restructure pt.2

This commit is contained in:
Mia
2026-02-27 02:20:45 +01:00
parent f4334e79f6
commit 4b07d93ae3
14 changed files with 305 additions and 548 deletions
+32 -19
View File
@@ -3,10 +3,11 @@ use arcstr::literal_substr;
use leaf_allocators::SyncAllocator;
use leaf_assembly::{
assembly::{Assembly, AssemblyIdentifier, Context},
values::Value,
types::{FloatT, IntT, Type},
values::{AnyConst, Value},
};
use leaf_parser::SourceCode;
use std::{collections::HashMap, sync::Arc};
use std::{collections::HashMap, sync::Arc, u32};
mod error;
mod scope;
@@ -49,23 +50,35 @@ impl<'l> CompilationContext<'l> {
.iter()
.map(|src| {
let mut scope = Scope::new(assembly, src.clone());
scope.insert(literal_substr!("void"), Value::Type(self.ctx.void_t()));
scope.insert(literal_substr!("i8"), Value::Type(self.ctx.i8_t()));
scope.insert(literal_substr!("i16"), Value::Type(self.ctx.i16_t()));
scope.insert(literal_substr!("i32"), Value::Type(self.ctx.i32_t()));
scope.insert(literal_substr!("i64"), Value::Type(self.ctx.i64_t()));
scope.insert(literal_substr!("i128"), Value::Type(self.ctx.i128_t()));
scope.insert(literal_substr!("isize"), Value::Type(self.ctx.isize_t()));
scope.insert(literal_substr!("u8"), Value::Type(self.ctx.u8_t()));
scope.insert(literal_substr!("u16"), Value::Type(self.ctx.u16_t()));
scope.insert(literal_substr!("u32"), Value::Type(self.ctx.u32_t()));
scope.insert(literal_substr!("u64"), Value::Type(self.ctx.u64_t()));
scope.insert(literal_substr!("u128"), Value::Type(self.ctx.u128_t()));
scope.insert(literal_substr!("usize"), Value::Type(self.ctx.usize_t()));
scope.insert(literal_substr!("f16"), Value::Type(self.ctx.f16_t()));
scope.insert(literal_substr!("f32"), Value::Type(self.ctx.f32_t()));
scope.insert(literal_substr!("f64"), Value::Type(self.ctx.f64_t()));
scope.insert(literal_substr!("type"), Value::Type(self.ctx.type_t()));
macro_rules! insert_types {
($($id:literal : $ty:expr,)*) => {
$(
scope.insert(
literal_substr!($id),
Value::Constant(AnyConst::Type($ty.into())),
);
)*
};
}
insert_types! {
"void": Type::Void,
"i8": Type::I8,
"i16": Type::I16,
"i32": Type::I32,
"i64": Type::I64,
"i128": Type::I128,
"isize": Type::ISIZE,
"u8": Type::U8,
"u16": Type::U16,
"u32": Type::U32,
"u64": Type::U64,
"u128": Type::U128,
"usize": Type::USIZE,
"f16": Type::F16,
"f32": Type::F32,
"f64": Type::F64,
"type": Type::Type,
}
scope
})
.collect();
+6 -4
View File
@@ -1,8 +1,8 @@
use arcstr::Substr;
use leaf_assembly::{
assembly::Assembly,
types::{Type, derivations::MakeTypeDerivations},
values::Value,
types::Type,
values::{AnyConst, Value},
};
use leaf_parser::{
SourceCode,
@@ -91,12 +91,14 @@ impl<'l> Scope<'l> {
par_ty.push(ty);
}
let fn_ty = ret_ty.make_fn(par_ty);
Ok(Value::Func(self.assembly.create_function(fn_ty)))
Ok(Value::Constant(AnyConst::Function(
self.assembly.create_function(fn_ty),
)))
}
fn assert_type(&self, val: Value<'l>) -> Result<Type<'l>, CompilationError> {
match val {
Value::Type(ty) => Ok(ty),
Value::Constant(AnyConst::Type(ty)) => Ok(ty),
_ => Err(CompilationError {
kind: Kind::NotAType,
message: format!("Value is not a type."),