aboutsummaryrefslogtreecommitdiff
path: root/src/types
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-11-21 14:52:50 +0100
committerMel <einebeere@gmail.com>2021-11-21 14:52:50 +0100
commitabaa72af8a1be00f3f84d7771a7994bfbbccf719 (patch)
treeb47edcef38cf7bdebae99428510b9fc8857f41bd /src/types
parent395d086f0dce355ccdcf3da149c309826c539b48 (diff)
downloadrabbithole-abaa72af8a1be00f3f84d7771a7994bfbbccf719.tar.zst
rabbithole-abaa72af8a1be00f3f84d7771a7994bfbbccf719.zip
Rename all Variants to Kinds
Diffstat (limited to 'src/types')
-rw-r--r--src/types/bag.rs40
-rw-r--r--src/types/mod.rs6
2 files changed, 22 insertions, 24 deletions
diff --git a/src/types/bag.rs b/src/types/bag.rs
index 30202fd..1b2d891 100644
--- a/src/types/bag.rs
+++ b/src/types/bag.rs
@@ -1,6 +1,6 @@
use std::{cell::RefCell, collections::HashMap};
-use super::{RefValueMap, Type, TypeVariant};
+use super::{RefValueMap, Type, TypeKind};
#[derive(Clone)]
pub struct TypeBag {
@@ -21,22 +21,20 @@ impl TypeBag {
}
}
- pub fn create_type(&self, variant: TypeVariant) -> Type {
- let global_associated_values_for_type = match variant {
- TypeVariant::Fn { .. } => &self.global_associated_values.fn_values,
- TypeVariant::Array(_) => &self.global_associated_values.array_values,
- TypeVariant::Tuple(_) => &self.global_associated_values.tuple_values,
- TypeVariant::Data { .. } => &self.global_associated_values.data_values,
- TypeVariant::Str
- | TypeVariant::Int
- | TypeVariant::Float
- | TypeVariant::Bool
- | TypeVariant::Void => panic!("There should only be one type {:?}.", variant),
- TypeVariant::Face(_) | TypeVariant::Var(_) => todo!("Implement abstract types."),
+ pub fn create_type(&self, kind: TypeKind) -> Type {
+ let global_associated_values_for_type = match kind {
+ TypeKind::Fn { .. } => &self.global_associated_values.fn_values,
+ TypeKind::Array(_) => &self.global_associated_values.array_values,
+ TypeKind::Tuple(_) => &self.global_associated_values.tuple_values,
+ TypeKind::Data { .. } => &self.global_associated_values.data_values,
+ TypeKind::Str | TypeKind::Int | TypeKind::Float | TypeKind::Bool | TypeKind::Void => {
+ panic!("There should only be one type {:?}.", kind)
+ }
+ TypeKind::Face(_) | TypeKind::Var(_) => todo!("Implement abstract types."),
};
Type {
- variant: Box::new(variant),
+ kind: Box::new(kind),
global_associated_values: global_associated_values_for_type,
}
}
@@ -106,17 +104,17 @@ struct AtomicTypes {
impl AtomicTypes {
fn new(values: &'static GlobalAssociatedValues) -> Self {
AtomicTypes {
- str_type: Self::create_single_type(TypeVariant::Str, &values.str_values),
- int_type: Self::create_single_type(TypeVariant::Int, &values.int_values),
- float_type: Self::create_single_type(TypeVariant::Float, &values.float_values),
- bool_type: Self::create_single_type(TypeVariant::Bool, &values.bool_values),
- void_type: Self::create_single_type(TypeVariant::Void, &values.void_values),
+ str_type: Self::create_single_type(TypeKind::Str, &values.str_values),
+ int_type: Self::create_single_type(TypeKind::Int, &values.int_values),
+ float_type: Self::create_single_type(TypeKind::Float, &values.float_values),
+ bool_type: Self::create_single_type(TypeKind::Bool, &values.bool_values),
+ void_type: Self::create_single_type(TypeKind::Void, &values.void_values),
}
}
- fn create_single_type(variant: TypeVariant, values: &'static RefValueMap) -> Type {
+ fn create_single_type(kind: TypeKind, values: &'static RefValueMap) -> Type {
Type {
- variant: Box::new(variant),
+ kind: Box::new(kind),
global_associated_values: values,
}
}
diff --git a/src/types/mod.rs b/src/types/mod.rs
index f3257eb..ecea578 100644
--- a/src/types/mod.rs
+++ b/src/types/mod.rs
@@ -8,12 +8,12 @@ use crate::parse::ast::nodes::Identifier;
#[derive(Debug, Clone)]
pub struct Type {
- variant: Box<TypeVariant>,
+ kind: Box<TypeKind>,
global_associated_values: &'static RefValueMap,
}
#[derive(Debug, Clone)]
-pub enum TypeVariant {
+pub enum TypeKind {
// Concrete types
Str,
Int,
@@ -39,4 +39,4 @@ pub enum TypeVariant {
type TypeMap = HashMap<Identifier, Type>;
-type RefValueMap = RefCell<ValueMap>; \ No newline at end of file
+type RefValueMap = RefCell<ValueMap>;