Big restructure pt.2
This commit is contained in:
+32
-19
@@ -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();
|
||||
|
||||
@@ -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."),
|
||||
|
||||
Reference in New Issue
Block a user