Skip to content

Commit

Permalink
typechecker: create proper module and add TypeId
Browse files Browse the repository at this point in the history
  • Loading branch information
tanguysegarra committed Feb 19, 2022
1 parent f18166b commit 7a062b9
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/instruction/binary_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/instruction/dec_arg.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/instruction/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/instruction/function_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/instruction/if_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 0 additions & 2 deletions src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/instruction/type_declaration.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down
12 changes: 6 additions & 6 deletions src/instruction/type_instantiation.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/instruction/var_or_empty_type.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
5 changes: 3 additions & 2 deletions src/parser/constructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/typechecker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/value/jk_constant.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 7a062b9

Please sign in to comment.