diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index 2af6349..ea153e4 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -512,11 +512,6 @@ impl mir::Expression { } } -pub enum IndexKind { - Array(u32), - Struct(u32), -} - impl IndexedVariableReference { fn get_stack_value(&self, scope: &mut Scope, load_after_gep: bool) -> Option { match &self.kind { diff --git a/reid/src/mir/typeinference.rs b/reid/src/mir/typeinference.rs index 4c6e25f..1436c4b 100644 --- a/reid/src/mir/typeinference.rs +++ b/reid/src/mir/typeinference.rs @@ -13,9 +13,8 @@ use super::{ typecheck::ErrorKind, typerefs::{ScopeTypeRefs, TypeRef, TypeRefs}, types::{pick_return, ReturnType}, - Block, ExprKind, Expression, FunctionDefinition, FunctionDefinitionKind, IfExpression, - IndexedVariableReference, IndexedVariableReferenceKind, Module, NamedVariableRef, ReturnKind, - StmtKind, TypeDefinitionKind, + Block, ExprKind, Expression, FunctionDefinition, FunctionDefinitionKind, IfExpression, Module, + ReturnKind, StmtKind, TypeKind::*, VagueType::*, }; @@ -148,61 +147,6 @@ impl Block { } } -impl IndexedVariableReference { - fn find_hint<'s>( - &self, - state: &PassState, - hints: &'s ScopeTypeRefs, - ) -> Result)>, ErrorKind> { - match &self.kind { - IndexedVariableReferenceKind::Named(NamedVariableRef(_, name, _)) => { - Ok(hints.find_var(&name)) - } - IndexedVariableReferenceKind::ArrayIndex(inner, _) => { - if let Some((mutable, inner_ref)) = inner.find_hint(state, hints)? { - // Check that the resolved type is at least an array, no - // need for further resolution. - let inner_ty = inner_ref.resolve_weak().unwrap(); - match inner_ty { - Array(type_kind, _) => Ok(hints - .from_type(&type_kind) - .clone() - .map(|t_ref| (mutable, t_ref))), - _ => Err(ErrorKind::TriedIndexingNonArray(inner_ty.clone())), - } - } else { - Ok(None) - } - } - IndexedVariableReferenceKind::StructIndex(inner, field_name) => { - if let Some((mutable, inner_ref)) = inner.find_hint(state, hints)? { - // Check that the resolved type is at least an array, no - // need for further resolution. - let inner_ty = inner_ref.resolve_weak().unwrap(); - match &inner_ty { - CustomType(struct_name) => match state.scope.types.get(&struct_name) { - Some(kind) => match kind { - TypeDefinitionKind::Struct(struct_ty) => Ok(hints - .from_type( - &struct_ty - .get_field_ty(field_name) - .cloned() - .ok_or(ErrorKind::NoSuchField(self.get_name()))?, - ) - .map(|v| (mutable, v))), - }, - None => Err(ErrorKind::TriedAccessingNonStruct(inner_ty.clone())), - }, - _ => Err(ErrorKind::TriedAccessingNonStruct(inner_ty)), - } - } else { - Ok(None) - } - } - } - } -} - impl Expression { fn infer_types<'s>( &mut self, diff --git a/reid/src/mir/types.rs b/reid/src/mir/types.rs index 5d640bc..d989652 100644 --- a/reid/src/mir/types.rs +++ b/reid/src/mir/types.rs @@ -1,5 +1,5 @@ use super::{ - typecheck::{Collapsable, ErrorKind}, + typecheck::ErrorKind, typerefs::{ScopeTypeRefs, TypeRef, TypeRefs}, VagueType as Vague, *, };