diff --git a/src/context.rs b/src/context.rs index c0a427f8..e80ec83b 100644 --- a/src/context.rs +++ b/src/context.rs @@ -16,9 +16,9 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; use std::rc::Rc; use crate::error::{ErrKind, Error, ErrorHandler}; -use crate::instruction::{Block, FunctionDec, FunctionKind, Instruction, TypeDec, TypeId, Var}; +use crate::instruction::{Block, FunctionDec, FunctionKind, Instruction, TypeDec, Var}; use crate::parser; -use crate::typechecker::{TypeCheck, TypeCtx}; +use crate::typechecker::{TypeCheck, TypeCtx, TypeId}; use crate::ObjectInstance; use crate::{Builtins, CheckedType, Generic}; @@ -105,7 +105,7 @@ impl Context { ctx.scope_enter(); // Add all primitive types as empty types without fields - crate::instruction::PRIMITIVE_TYPES + crate::typechecker::PRIMITIVE_TYPES .iter() .for_each(|ty_name| ctx.add_type(TypeDec::from(*ty_name)).unwrap()); diff --git a/src/generics.rs b/src/generics.rs index 7cd232dd..504a2834 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; -use crate::instruction::TypeId; +use crate::typechecker::TypeId; use crate::{log, ErrKind, Error}; use crate::{Context, TypeCtx}; @@ -99,7 +99,7 @@ pub trait Generic { #[cfg(test)] mod tests { use super::*; - use crate::instruction::TypeId; + use crate::typechecker::TypeId; macro_rules! ty { ($str:literal) => { diff --git a/src/instruction/binary_op.rs b/src/instruction/binary_op.rs index be8092d4..193223f1 100644 --- a/src/instruction/binary_op.rs +++ b/src/instruction/binary_op.rs @@ -6,9 +6,9 @@ //! That is `Add`, `Substract`, `Multiply` and `Divide`. use crate::{ - instruction::{Operator, TypeId}, + instruction::Operator, log, - typechecker::{CheckedType, TypeCtx}, + typechecker::{CheckedType, TypeCtx, TypeId}, Context, ErrKind, Error, FromObjectInstance, Generic, InstrKind, Instruction, JkFloat, JkInt, ObjectInstance, TypeCheck, Value, }; diff --git a/src/instruction/dec_arg.rs b/src/instruction/dec_arg.rs index ebd9da2f..17aa1a11 100644 --- a/src/instruction/dec_arg.rs +++ b/src/instruction/dec_arg.rs @@ -1,6 +1,6 @@ use std::fmt::{Display, Formatter, Result}; -use crate::instruction::TypeId; +use crate::typechecker::TypeId; #[derive(Clone, Debug, PartialEq)] pub struct DecArg { diff --git a/src/instruction/function_call.rs b/src/instruction/function_call.rs index 97594eac..7a42f363 100644 --- a/src/instruction/function_call.rs +++ b/src/instruction/function_call.rs @@ -2,11 +2,11 @@ //! function on execution. use crate::generics::GenericMap; -use crate::instruction::{FunctionDec, FunctionKind, TypeId, Var}; -use crate::typechecker::TypeCtx; +use crate::instruction::{FunctionDec, FunctionKind, Var}; +use crate::typechecker::{CheckedType, TypeCtx, TypeId}; use crate::{ - generics, log, typechecker::CheckedType, Context, ErrKind, Error, Generic, InstrKind, - Instruction, ObjectInstance, TypeCheck, + generics, log, Context, ErrKind, Error, Generic, InstrKind, Instruction, ObjectInstance, + TypeCheck, }; use std::rc::Rc; diff --git a/src/instruction/function_declaration.rs b/src/instruction/function_declaration.rs index 07653dd0..2a3254d5 100644 --- a/src/instruction/function_declaration.rs +++ b/src/instruction/function_declaration.rs @@ -2,8 +2,8 @@ //! a name, a list of required arguments as well as an associated code block use crate::generics::GenericMap; -use crate::instruction::{Block, DecArg, InstrKind, Instruction, TypeId}; -use crate::typechecker::{CheckedType, TypeCtx}; +use crate::instruction::{Block, DecArg, InstrKind, Instruction}; +use crate::typechecker::{CheckedType, TypeCtx, TypeId}; use crate::Generic; use crate::{log, Context, ErrKind, Error, ObjectInstance, TypeCheck}; @@ -387,7 +387,7 @@ impl From<&str> for FunctionKind { mod tests { use super::*; use crate::span; - use crate::{instruction::TypeId, jinko, parser::constructs}; + use crate::{jinko, parser::constructs, typechecker::TypeId}; #[test] fn simple_no_arg() { diff --git a/src/instruction/if_else.rs b/src/instruction/if_else.rs index de106d85..368191f9 100644 --- a/src/instruction/if_else.rs +++ b/src/instruction/if_else.rs @@ -16,8 +16,8 @@ //! ``` use crate::instance::FromObjectInstance; -use crate::instruction::{Block, InstrKind, Instruction, TypeId}; -use crate::typechecker::TypeCtx; +use crate::instruction::{Block, InstrKind, Instruction}; +use crate::typechecker::{TypeCtx, TypeId}; use crate::value::JkBool; use crate::Generic; use crate::{log, ErrKind, Error}; diff --git a/src/instruction/mod.rs b/src/instruction/mod.rs index b275bf44..8f34780e 100644 --- a/src/instruction/mod.rs +++ b/src/instruction/mod.rs @@ -22,7 +22,6 @@ mod method_call; mod operator; mod rename; mod type_declaration; -mod type_id; mod type_instantiation; mod var; mod var_assignment; @@ -42,7 +41,6 @@ pub use loop_block::{Loop, LoopKind}; pub use method_call::MethodCall; pub use operator::Operator; pub use type_declaration::TypeDec; -pub use type_id::{TypeId, PRIMITIVE_TYPES}; pub use type_instantiation::TypeInstantiation; pub use var::Var; pub use var_assignment::VarAssign; diff --git a/src/instruction/type_declaration.rs b/src/instruction/type_declaration.rs index 6613f8dd..2902b5b2 100644 --- a/src/instruction/type_declaration.rs +++ b/src/instruction/type_declaration.rs @@ -1,8 +1,8 @@ -use super::{DecArg, InstrKind, Instruction, TypeId}; +use super::{DecArg, InstrKind, Instruction}; use crate::{ log, - typechecker::{CheckedType, TypeCtx}, + typechecker::{CheckedType, TypeCtx, TypeId}, Context, Generic, ObjectInstance, TypeCheck, }; diff --git a/src/instruction/type_instantiation.rs b/src/instruction/type_instantiation.rs index 855565e5..afa3a2ca 100644 --- a/src/instruction/type_instantiation.rs +++ b/src/instruction/type_instantiation.rs @@ -1,13 +1,11 @@ //! TypeInstantiations are used when instantiating a type. The argument list is given to the //! type on execution. -use super::{ - Context, ErrKind, Error, InstrKind, Instruction, ObjectInstance, TypeDec, TypeId, VarAssign, -}; +use super::{Context, ErrKind, Error, InstrKind, Instruction, ObjectInstance, TypeDec, VarAssign}; use crate::instance::Name; use crate::typechecker::TypeCtx; use crate::Generic; -use crate::{typechecker::CheckedType, TypeCheck}; +use crate::{typechecker::CheckedType, TypeCheck, TypeId}; use std::rc::Rc; @@ -208,7 +206,8 @@ mod test { #[test] fn t_fields_number() { - use super::super::{DecArg, TypeId}; + use super::super::DecArg; + use crate::typechecker::TypeId; use crate::value::JkInt; let mut ctx = Context::new(); @@ -259,7 +258,8 @@ mod test { #[test] fn t_returned_instance() { - use super::super::{DecArg, TypeId}; + use super::super::DecArg; + use crate::typechecker::TypeId; use crate::value::{JkInt, JkString}; const TYPE_NAME: &str = "Type_Name"; diff --git a/src/instruction/var_or_empty_type.rs b/src/instruction/var_or_empty_type.rs index ba736b95..55424861 100644 --- a/src/instruction/var_or_empty_type.rs +++ b/src/instruction/var_or_empty_type.rs @@ -1,6 +1,7 @@ use crate::{ - instruction::{TypeId, TypeInstantiation, Var}, + instruction::{TypeInstantiation, Var}, CheckedType, Context, Generic, InstrKind, Instruction, ObjectInstance, TypeCheck, TypeCtx, + TypeId, }; #[derive(Clone, PartialEq)] diff --git a/src/lib.rs b/src/lib.rs index cbfb6077..a792508e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,5 +23,5 @@ pub use indent::Indent; pub use instance::{FromObjectInstance, ObjectInstance, ToObjectInstance}; pub use instruction::{InstrKind, Instruction}; pub use parser::{constructs, parse}; -pub use typechecker::{CheckedType, TypeCheck, TypeCtx}; +pub use typechecker::{CheckedType, TypeCheck, TypeCtx, TypeId}; pub use value::{JkBool, JkChar, JkConstant, JkFloat, JkInt, JkString, Value}; diff --git a/src/parser/constructs.rs b/src/parser/constructs.rs index 87a088c2..eebbb77f 100644 --- a/src/parser/constructs.rs +++ b/src/parser/constructs.rs @@ -22,10 +22,11 @@ use nom_locate::LocatedSpan; use crate::instruction::{ BinaryOp, Block, DecArg, FieldAccess, FunctionCall, FunctionDec, FunctionKind, IfElse, Incl, - Instruction, JkInst, Loop, LoopKind, MethodCall, Operator, Return, TypeDec, TypeId, - TypeInstantiation, Var, VarAssign, VarOrEmptyType, + Instruction, JkInst, Loop, LoopKind, MethodCall, Operator, Return, TypeDec, TypeInstantiation, + Var, VarAssign, VarOrEmptyType, }; use crate::parser::{ConstantConstruct, ParseResult, Token}; +use crate::typechecker::TypeId; use crate::Error; /// Parse as many instructions as possible diff --git a/src/typechecker.rs b/src/typechecker.rs index 6b29ab8f..bc56e80e 100644 --- a/src/typechecker.rs +++ b/src/typechecker.rs @@ -2,11 +2,10 @@ //! need to get its type checked multiple times, then it can implement the [`CachedTypeCheck`] //! trait on top of it. -use crate::{ - error::ErrorHandler, - instruction::{FunctionDec, TypeId}, - Error, ScopeMap, -}; +mod type_id; +pub use type_id::{TypeId, PRIMITIVE_TYPES}; + +use crate::{error::ErrorHandler, instruction::FunctionDec, Error, ScopeMap}; use colored::Colorize; use std::{ collections::HashSet, diff --git a/src/instruction/type_id.rs b/src/typechecker/type_id.rs similarity index 100% rename from src/instruction/type_id.rs rename to src/typechecker/type_id.rs diff --git a/src/value/jk_constant.rs b/src/value/jk_constant.rs index 1c32ca55..e203b226 100644 --- a/src/value/jk_constant.rs +++ b/src/value/jk_constant.rs @@ -1,5 +1,5 @@ -use crate::instruction::{InstrKind, Instruction, Operator, TypeId}; -use crate::typechecker::{CheckedType, TypeCheck, TypeCtx}; +use crate::instruction::{InstrKind, Instruction, Operator}; +use crate::typechecker::{CheckedType, TypeCheck, TypeCtx, TypeId}; use crate::{ log, Context, Error, FromObjectInstance, Generic, JkString, ObjectInstance, ToObjectInstance, Value,