Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions compiler/astoir_hir/src/nodes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The nodes inside of the AstoIR HIR.

use compiler_typing::{references::TypeReference, storage::{BOOLEAN_TYPE, STATIC_STR}, structs::RawStructTypeContainer, transmutation::array::can_transmute_inner, tree::Type};
use compiler_typing::{raw::RawType, references::TypeReference, storage::{BOOLEAN_TYPE, STATIC_STR}, structs::RawStructTypeContainer, transmutation::array::can_transmute_inner, tree::Type};
use compiler_utils::Position;
use diagnostics::{DiagnosticSpanOrigin, builders::{make_diff_type, make_diff_type_val}, diagnostic::{Diagnostic, Span, SpanKind, SpanPosition}, unsure_panic};
use lexer::toks::{comp::ComparingOperator, math::MathOperator};
Expand Down Expand Up @@ -200,12 +200,7 @@ impl HIRNode {
}

HIRNodeKind::UnwrapCondition { .. } => {
let t = match context.type_storage.types.get_index(BOOLEAN_TYPE) {
Some(v) => v,
None => return None
};

return Some(Type::Generic(t, vec![], vec![]))
return Some(Type::Generic(RawType::Boolean, vec![], vec![]))
},

HIRNodeKind::UnwrapValue { original: _, new_type, unsafe_unwrap: _ } => {
Expand All @@ -228,7 +223,7 @@ impl HIRNode {
None => return None
};

return Some(Type::Generic(ind, vec![], vec![]))
return Some(Type::Generic(RawType::Boolean, vec![], vec![]))
},

HIRNodeKind::ArrayVariableInitializerValue { vals } => return Some(Type::Array(vals.len(), Box::new(vals[0].get_node_type(context, curr_ctx).unwrap()))),
Expand All @@ -243,12 +238,7 @@ impl HIRNode {
},

HIRNodeKind::BooleanOperator { .. } | HIRNodeKind::BooleanCondition { .. } => {
let t = match context.type_storage.types.get_index(BOOLEAN_TYPE) {
Some(v) => v,
None => return None
};

return Some(Type::Generic(t, vec![], vec![]))
return Some(Type::Generic(RawType::Boolean, vec![], vec![]))
},

HIRNodeKind::StructVariableInitializerValue { t, fields: _ } => {
Expand Down
9 changes: 2 additions & 7 deletions compiler/astoir_hir_lowering/src/bools.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ast::tree::{ASTTreeNode, ASTTreeNodeKind};
use astoir_hir::{ctx::{HIRBranchedContext, HIRContext}, nodes::{HIRNode, HIRNodeKind}};
use compiler_typing::{storage::BOOLEAN_TYPE, tree::Type};
use compiler_typing::{raw::RawType, storage::BOOLEAN_TYPE, tree::Type};
use diagnostics::{DiagnosticResult};

use crate::values::lower_ast_value;
Expand Down Expand Up @@ -30,12 +30,7 @@ pub fn lower_ast_operator_condition(context: &mut HIRContext, curr_ctx: &mut HIR
pub fn lower_ast_condition(context: &mut HIRContext, curr_ctx: &mut HIRBranchedContext, node: Box<ASTTreeNode>) -> DiagnosticResult<Box<HIRNode>> {
let hir_value = lower_ast_value(context, curr_ctx, node.clone())?;

let bool_type = match context.type_storage.types.get_index(BOOLEAN_TYPE) {
Some(v) => v,
None => panic!("bool type not found")
};

let val = hir_value.use_as(context, curr_ctx, Type::Generic(bool_type, vec![], vec![]), &*node, None)?;
let val = hir_value.use_as(context, curr_ctx, Type::Generic(RawType::Boolean, vec![], vec![]), &*node, None)?;

return Ok(Box::new(val));
}
6 changes: 3 additions & 3 deletions compiler/astoir_hir_lowering/src/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use diagnostics::{DiagnosticResult, builders::make_cannot_find_type};
pub fn lower_ast_literal(context: &HIRContext, node: Box<ASTTreeNode>) -> DiagnosticResult<Box<HIRNode>> {
match node.kind {
ASTTreeNodeKind::IntegerLit { val, hash } => {
let lit_type = match context.type_storage.types.get_index(hash) {
Some(v) => v,
None => return Err(make_cannot_find_type(&*node, &hash).into())
let lit_type = match context.type_storage.get_type(hash) {
Ok(v) => v,
Err(_) => return Err(make_cannot_find_type(&*node, &hash).into())
};

return Ok(Box::new(HIRNode::new(HIRNodeKind::IntegerLiteral { value: val, int_type: Type::Generic(lit_type, vec![], vec![]) }, &node.start, &node.end)))
Expand Down
6 changes: 3 additions & 3 deletions compiler/astoir_hir_lowering/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ pub fn lower_ast_type<K: DiagnosticSpanOrigin>(context: &mut HIRContext, t: ASTT
t_params.push(Box::new(lower_ast_type(context, *type_param, origin)?));
}

let res = Type::Generic(context.type_storage.types.hash_to_ind[&hash], t_params, size_params);
let res = Type::Generic(t.clone(), t_params, size_params);

if t.is_sized() {
let lower = lower_sized_base_type(context, &res, origin)?;

if context.type_storage.type_to_ind.contains_key(&lower) {
return Ok(Type::Generic(context.type_storage.type_to_ind[&lower], vec![], vec![]));
return Ok(Type::Generic(t, vec![], vec![]));
} else {
let ind = match context.type_storage.append_with_hash(hash, lower) {
Ok(v) => v,
Err(_) => panic!("Generic lowering type cannot be found on type_to_hash")
};

return Ok(Type::Generic(ind, vec![], vec![]))
return Ok(Type::Generic(context.type_storage.types.vals[ind].clone(), vec![], vec![]))
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/astoir_mir_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn lower_hir_generic(ctx: &MIRLoweringContext, t: &Type, generic: &RawType)
pub fn lower_hir_type(ctx: &MIRLoweringContext, t: Type) -> DiagnosticResult<Type> {
match &t {
Type::Generic(a, _, _) => {
return lower_hir_generic(ctx, &t, &ctx.hir_ctx.type_storage.types.vals[*a])
return lower_hir_generic(ctx, &t, a)
},

Type::Array(a, b) => return Ok(Type::Array(*a, Box::new(lower_hir_type(ctx, *b.clone())?))),
Expand Down
6 changes: 3 additions & 3 deletions compiler/compiler_typing/src/transmutation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ impl Type {
return false;
}

return storage.types.vals[*raw_type].can_transmute(sizes.clone(), &storage.types.vals[*raw_type2], sizes2.clone())
return raw_type.can_transmute(sizes.clone(), raw_type2, sizes2.clone())
},

(Self::GenericLowered(base), Self::Generic(rawtype, type_params, sizes)) => {
if !type_params.is_empty() {
return false;
}

return base.can_transmute(vec![], &storage.types.vals[*rawtype], sizes.clone())
return base.can_transmute(vec![], rawtype, sizes.clone())
},

(Self::Generic(rawtype, type_params, sizes), Self::GenericLowered(base)) => {
if !type_params.is_empty() {
return false;
}

return base.can_transmute(vec![], &storage.types.vals[*rawtype], sizes.clone())
return base.can_transmute(vec![], rawtype, sizes.clone())
}

(Self::GenericLowered(base), Self::GenericLowered(base2)) => {
Expand Down
12 changes: 6 additions & 6 deletions compiler/compiler_typing/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{RawTypeReference, SizedType, StructuredType, TypedFunction, raw::Raw
/// The node-based typing system of Quickfall. Allows for very specific types.
pub enum Type {
/// A generic type node. Represents a classic type.
/// 0: The raw type index
/// 0: The raw type
/// 1: The type parameters
/// 2: The size specifiers
Generic(RawTypeReference, Vec<Box<Type>>, Vec<usize>), // Potential lowering to base-sized
Generic(RawType, Vec<Box<Type>>, Vec<usize>), // Potential lowering to base-sized

/// A generic type node but lowered. Represents a concrete type.
GenericLowered(RawType),
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Type {
match self {
Self::GenericLowered(a) => return a.clone(),
Self::Generic(a, _, _) => {
return storage.types.vals[*a].clone();
return a.clone();
},

_ => panic!("Cannot obtain generic {:#?}", self)
Expand Down Expand Up @@ -165,7 +165,7 @@ impl Type {

pub fn get_generic(&self, storage: &TypeStorage) -> RawType {
if let Type::Generic(raw, _, _) = self {
return storage.types.get_ind(*raw).clone();
return raw.clone();
};

if let Type::GenericLowered(raw) = self {
Expand All @@ -181,7 +181,7 @@ impl Type {
Type::Array(a, b) => Type::Array(*a, Box::new(b.faulty_lowering_generic(storage))),
Type::Pointer(a, b) => Type::Pointer(*a, Box::new(b.faulty_lowering_generic(storage))),
Type::Reference(t) => Type::Reference(Box::new(t.faulty_lowering_generic(storage))),
Type::Generic(id, _, _) => Type::GenericLowered(storage.types.vals[*id].clone()),
Type::Generic(t, _, _) => Type::GenericLowered(t.clone()),
Type::GenericLowered(_) => self.clone()
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ impl SizedType for Type {
Self::Array(size, inner) => inner.clone().get_size(t, compacted_size, storage) * *size,
Self::Pointer(_, _) => get_pointer_size(),
Self::Reference(_) => get_pointer_size(),
Self::Generic(e, _, _) => storage.types.vals[*e].get_size(t, compacted_size, storage),
Self::Generic(e, _, _) => e.get_size(t, compacted_size, storage),
Self::GenericLowered(e) => e.get_size(t, compacted_size, storage)
}
}
Expand Down