From 2742112b097ad55c0ac3eeb5d9e97e5b0a22639e Mon Sep 17 00:00:00 2001 From: Mark <> Date: Tue, 16 Apr 2024 13:38:50 +0200 Subject: [PATCH] `Type` no longer implements `MersType` --- mers/Cargo.toml | 4 +- .../examples/00_parse_compile_check_run.rs | 2 +- mers_lib/examples/02_own_variable.rs | 4 +- mers_lib/src/data/bool.rs | 2 +- mers_lib/src/data/byte.rs | 2 +- mers_lib/src/data/float.rs | 2 +- mers_lib/src/data/function.rs | 4 +- mers_lib/src/data/int.rs | 2 +- mers_lib/src/data/mod.rs | 54 ++++++++----------- mers_lib/src/data/object.rs | 2 +- mers_lib/src/data/reference.rs | 2 +- mers_lib/src/data/string.rs | 2 +- mers_lib/src/data/tuple.rs | 4 +- mers_lib/src/parsing/types.rs | 22 ++++---- mers_lib/src/program/configs/mod.rs | 8 +-- mers_lib/src/program/configs/util.rs | 2 +- mers_lib/src/program/configs/with_base.rs | 4 +- .../program/configs/with_command_running.rs | 28 +++++----- mers_lib/src/program/configs/with_get.rs | 6 +-- mers_lib/src/program/configs/with_iters.rs | 6 +-- mers_lib/src/program/configs/with_list.rs | 12 ++--- mers_lib/src/program/configs/with_math.rs | 2 +- .../program/configs/with_multithreading.rs | 10 ++-- mers_lib/src/program/configs/with_string.rs | 8 +-- mers_lib/src/program/run/as_type.rs | 2 +- mers_lib/src/program/run/assign_to.rs | 2 +- mers_lib/src/program/run/chain.rs | 4 +- mers_lib/src/program/run/custom_type.rs | 10 ++-- mers_lib/src/program/run/if.rs | 8 +-- mers_lib/src/program/run/mod.rs | 6 +-- mers_lib/src/program/run/object.rs | 4 +- mers_lib/src/program/run/try.rs | 2 +- mers_lib/src/program/run/tuple.rs | 4 +- 33 files changed, 109 insertions(+), 127 deletions(-) diff --git a/mers/Cargo.toml b/mers/Cargo.toml index 99a9f70..e427930 100644 --- a/mers/Cargo.toml +++ b/mers/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/Dummi26/mers" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -mers_lib = "0.8.1" -# mers_lib = { path = "../mers_lib" } +# mers_lib = "0.8.1" +mers_lib = { path = "../mers_lib" } clap = { version = "4.3.19", features = ["derive"] } colored = "2.1.0" diff --git a/mers_lib/examples/00_parse_compile_check_run.rs b/mers_lib/examples/00_parse_compile_check_run.rs index 7a55dd0..15d3f48 100644 --- a/mers_lib/examples/00_parse_compile_check_run.rs +++ b/mers_lib/examples/00_parse_compile_check_run.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use mers_lib::{ - data::{Data, MersType, Type}, + data::{Data, Type}, errors::CheckError, prelude_compile::{parse, Config, Source}, program::parsed::CompInfo, diff --git a/mers_lib/examples/02_own_variable.rs b/mers_lib/examples/02_own_variable.rs index b7eb9bc..8ba4e02 100644 --- a/mers_lib/examples/02_own_variable.rs +++ b/mers_lib/examples/02_own_variable.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use mers_lib::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::CheckError, prelude_compile::{parse, Config, Source}, program::parsed::CompInfo, @@ -34,7 +34,7 @@ fn run(src: String) -> Result<(), CheckError> { |arg| { // If the input is a string, the output is a string. // Otherwise, the function is used incorrectly. - if arg.is_included_in(&data::string::StringT) { + if arg.is_included_in_single(&data::string::StringT) { Ok(Type::new(data::string::StringT)) } else { // Wrong argument type. The code won't compile and this is the error message shown to the user. diff --git a/mers_lib/src/data/bool.rs b/mers_lib/src/data/bool.rs index 7323085..65e5184 100755 --- a/mers_lib/src/data/bool.rs +++ b/mers_lib/src/data/bool.rs @@ -36,7 +36,7 @@ impl MersType for BoolT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { diff --git a/mers_lib/src/data/byte.rs b/mers_lib/src/data/byte.rs index 5c8cc4b..213ea4a 100644 --- a/mers_lib/src/data/byte.rs +++ b/mers_lib/src/data/byte.rs @@ -36,7 +36,7 @@ impl MersType for ByteT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { diff --git a/mers_lib/src/data/float.rs b/mers_lib/src/data/float.rs index 42a4bf9..3b1a8e4 100755 --- a/mers_lib/src/data/float.rs +++ b/mers_lib/src/data/float.rs @@ -36,7 +36,7 @@ impl MersType for FloatT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { diff --git a/mers_lib/src/data/function.rs b/mers_lib/src/data/function.rs index 09bd76e..b699e68 100755 --- a/mers_lib/src/data/function.rs +++ b/mers_lib/src/data/function.rs @@ -121,7 +121,7 @@ impl MersType for FunctionT { if t.0.len() > 1 { return None; } else if let Some(t) = t.0.first() { - out.add(Arc::new(t.clone())) + out.add_all(&t); } } else { return None; @@ -153,7 +153,7 @@ impl MersType for FunctionT { false } } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { if let Some(target) = target.as_any().downcast_ref::() { if let Err(s) = &target.0 { s.iter() diff --git a/mers_lib/src/data/int.rs b/mers_lib/src/data/int.rs index 1163873..e1008a2 100755 --- a/mers_lib/src/data/int.rs +++ b/mers_lib/src/data/int.rs @@ -36,7 +36,7 @@ impl MersType for IntT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { diff --git a/mers_lib/src/data/mod.rs b/mers_lib/src/data/mod.rs index c804eb0..16ab49b 100755 --- a/mers_lib/src/data/mod.rs +++ b/mers_lib/src/data/mod.rs @@ -50,17 +50,7 @@ pub trait MersType: Any + Debug + Display + Send + Sync { /// this *must* return false. fn is_same_type_as(&self, other: &dyn MersType) -> bool; /// This doesn't handle the case where target is Type (is_included_in handles it) - fn is_included_in_single(&self, target: &dyn MersType) -> bool; - fn is_included_in(&self, target: &dyn MersType) -> bool { - if let Some(target) = target.as_any().downcast_ref::() { - target - .types - .iter() - .any(|t| self.is_included_in_single(t.as_ref())) - } else { - self.is_included_in_single(target) - } - } + fn is_included_in(&self, target: &dyn MersType) -> bool; /// Returns all types that can result from the use of this type. /// Usually, this is just `acc.add(Arc::new(self.clone()))` /// but if there exists one or more inner types, this becomes interesting: @@ -268,7 +258,7 @@ impl Type { .filter(|v| v.0.len() == 1) .and_then(|v| v.0.get(0)) { - o.add(Arc::new(t.clone())); + o.add_all(&t); } else { return None; } @@ -287,7 +277,7 @@ impl Type { .and_then(|v| v.0.get(0)) { nothing = false; - o.add(Arc::new(t.clone())); + o.add_all(&t); } } if nothing { @@ -315,7 +305,7 @@ impl Type { let mut o = Self::empty(); for t in &self.types { if let Some(t) = t.is_reference_to() { - o.add(Arc::new(t.clone())); + o.add_all(&t); } else { return None; } @@ -334,47 +324,45 @@ impl Type { // then repeat with the second type if possible (here not, but for longer tuples, probably?) // merge the last existing type in all the collections until we reach the first type again or the last types aren't equal anymore (how to check????) -impl MersType for Type { - fn is_same_type_as(&self, other: &dyn MersType) -> bool { +impl Type { + pub fn is_same_type_as(&self, other: &Self) -> bool { // TODO! improve self.is_included_in(other) && other.is_included_in(self) } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { - self.types.iter().all(|t| t.is_included_in_single(target)) + pub fn is_included_in(&self, target: &Self) -> bool { + self.types + .iter() + .all(|s| target.types.iter().any(|t| s.is_included_in(&**t))) } - fn is_included_in(&self, target: &dyn MersType) -> bool { - self.types.iter().all(|t| t.is_included_in(target)) + pub fn is_included_in_single(&self, target: &dyn MersType) -> bool { + self.types.iter().all(|s| s.is_included_in(target)) } - fn subtypes(&self, acc: &mut Type) { + pub fn subtypes(&self, acc: &mut Type) { for t in &self.types { t.subtypes(acc); } } - fn as_any(&self) -> &dyn Any { - self + pub fn subtypes_type(&self) -> Type { + let mut acc = Type::empty(); + self.subtypes(&mut acc); + acc } - fn mut_any(&mut self) -> &mut dyn Any { - self - } - fn to_any(self) -> Box { - Box::new(self) - } - fn iterable(&self) -> Option { + pub fn iterable(&self) -> Option { let mut o = Self::empty(); for t in self.types.iter() { if let Some(t) = t.iterable() { - o.add(Arc::new(t)); + o.add_all(&t); } else { return None; } } Some(o) } - fn get(&self) -> Option { + pub fn get(&self) -> Option { let mut o = Self::empty(); for t in self.types.iter() { if let Some(t) = t.get() { - o.add(Arc::new(t)); + o.add_all(&t); } else { return None; } diff --git a/mers_lib/src/data/object.rs b/mers_lib/src/data/object.rs index f1f5027..195dc46 100644 --- a/mers_lib/src/data/object.rs +++ b/mers_lib/src/data/object.rs @@ -48,7 +48,7 @@ impl MersType for ObjectT { .all(|((s1, t1), (s2, t2))| s1 == s2 && t1.is_same_type_as(t2)) }) } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { target .as_any() .downcast_ref::() diff --git a/mers_lib/src/data/reference.rs b/mers_lib/src/data/reference.rs index 21d7a1c..4869c33 100755 --- a/mers_lib/src/data/reference.rs +++ b/mers_lib/src/data/reference.rs @@ -44,7 +44,7 @@ impl MersType for ReferenceT { false } } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { // &int isn't included in &(int/float), otherwise we could assign a float to it self.is_same_type_as(target) } diff --git a/mers_lib/src/data/string.rs b/mers_lib/src/data/string.rs index 9c21a47..0207a77 100755 --- a/mers_lib/src/data/string.rs +++ b/mers_lib/src/data/string.rs @@ -36,7 +36,7 @@ impl MersType for StringT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { diff --git a/mers_lib/src/data/tuple.rs b/mers_lib/src/data/tuple.rs index e959608..9719936 100755 --- a/mers_lib/src/data/tuple.rs +++ b/mers_lib/src/data/tuple.rs @@ -48,7 +48,7 @@ impl MersType for TupleT { fn iterable(&self) -> Option { let mut o = Type::empty(); for t in self.0.iter() { - o.add(Arc::new(t.clone())); + o.add_all(&t); } Some(o) } @@ -64,7 +64,7 @@ impl MersType for TupleT { false } } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { if let Some(target) = target.as_any().downcast_ref::() { self.0.len() == target.0.len() && self diff --git a/mers_lib/src/parsing/types.rs b/mers_lib/src/parsing/types.rs index 5dfa643..5e92b5a 100755 --- a/mers_lib/src/parsing/types.rs +++ b/mers_lib/src/parsing/types.rs @@ -208,33 +208,33 @@ pub fn type_from_parsed( ) -> Result { let mut as_type = Type::empty(); for t in parsed.iter() { - as_type.add(match t { + match t { ParsedType::Reference(inner) => { let inner = type_from_parsed(inner, info)?; - Arc::new(data::reference::ReferenceT(inner)) + as_type.add(Arc::new(data::reference::ReferenceT(inner))); } - ParsedType::Tuple(t) => Arc::new(data::tuple::TupleT( + ParsedType::Tuple(t) => as_type.add(Arc::new(data::tuple::TupleT( t.iter() .map(|v| type_from_parsed(v, info)) .collect::>()?, - )), - ParsedType::Object(o) => Arc::new(data::object::ObjectT( + ))), + ParsedType::Object(o) => as_type.add(Arc::new(data::object::ObjectT( o.iter() .map(|(s, v)| -> Result<_, CheckError> { Ok((s.clone(), type_from_parsed(v, info)?)) }) .collect::>()?, - )), - ParsedType::Function(v) => Arc::new(data::function::FunctionT(Err(v + ))), + ParsedType::Function(v) => as_type.add(Arc::new(data::function::FunctionT(Err(v .iter() .map(|(i, o)| Ok((type_from_parsed(i, info)?, type_from_parsed(o, info)?))) - .collect::>()?))), + .collect::>()?)))), ParsedType::Type(name) => match info .scopes .iter() .find_map(|scope| scope.types.iter().find(|v| v.0 == name).map(|(_, v)| v)) { - Some(Ok(t)) => Arc::clone(t), + Some(Ok(t)) => as_type.add_all(&*t), Some(Err(_)) => { return Err(CheckError::new().msg(format!( "Type: specified type without info, but type needs additional info" @@ -252,10 +252,10 @@ pub fn type_from_parsed( "Type: specified type with info, but type {t} doesn't need it" ))) } - Some(Err(f)) => f(&additional_info, info)?, + Some(Err(f)) => as_type.add_all(&*f(&additional_info, info)?), None => return Err(CheckError::new().msg(format!("Unknown type '{name}'"))), }, - }); + } } Ok(as_type) } diff --git a/mers_lib/src/program/configs/mod.rs b/mers_lib/src/program/configs/mod.rs index d91334b..506eb57 100755 --- a/mers_lib/src/program/configs/mod.rs +++ b/mers_lib/src/program/configs/mod.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, RwLock}; use crate::{ - data::{self, Data, MersType}, + data::{self, Data, Type}, errors::CheckError, info::Local, program::run::CheckInfo, @@ -70,7 +70,7 @@ impl Config { .last_mut() .unwrap() .types - .insert(t.to_string(), Ok(Arc::new(t))); + .insert(t.to_string(), Ok(Arc::new(data::Type::new(t)))); }; } init_d!(data::bool::BoolT); @@ -106,8 +106,8 @@ impl Config { mut self, name: String, t: Result< - Arc, - Arc Result, CheckError> + Send + Sync>, + Arc, + Arc Result, CheckError> + Send + Sync>, >, ) -> Self { self.info_check.scopes[0].types.insert(name, t); diff --git a/mers_lib/src/program/configs/util.rs b/mers_lib/src/program/configs/util.rs index 9cd2b4b..d3932df 100644 --- a/mers_lib/src/program/configs/util.rs +++ b/mers_lib/src/program/configs/util.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::CheckError, info::Info, }; diff --git a/mers_lib/src/program/configs/with_base.rs b/mers_lib/src/program/configs/with_base.rs index 12c11c8..b3c0440 100755 --- a/mers_lib/src/program/configs/with_base.rs +++ b/mers_lib/src/program/configs/with_base.rs @@ -4,7 +4,7 @@ use std::{ }; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::CheckError, program::run::{CheckInfo, Info}, }; @@ -101,7 +101,7 @@ impl Config { .add_var("panic".to_string(), Data::new(data::function::Function { info: Arc::new(Info::neverused()), info_check: Arc::new(Mutex::new(CheckInfo::neverused())), - out: Arc::new(|a, _i| if a.is_included_in(&data::int::IntT) { + out: Arc::new(|a, _i| if a.is_included_in_single(&data::int::IntT) { Ok(Type::empty()) } else { Err(format!("cannot call exit with non-int argument").into()) diff --git a/mers_lib/src/program/configs/with_command_running.rs b/mers_lib/src/program/configs/with_command_running.rs index 5bacf4b..0f32c0b 100755 --- a/mers_lib/src/program/configs/with_command_running.rs +++ b/mers_lib/src/program/configs/with_command_running.rs @@ -20,15 +20,15 @@ impl Config { /// returns (int/(), string, string) on success (status code, stdout, stderr) pub fn with_command_running(self) -> Self { self - .add_type("RunCommandError".to_owned(), Ok(Arc::new(RunCommandErrorT))) - .add_type("ChildProcess".to_owned(), Ok(Arc::new(ChildProcessT))) + .add_type("RunCommandError".to_owned(), Ok(Arc::new(Type::new(RunCommandErrorT)))) + .add_type("ChildProcess".to_owned(), Ok(Arc::new(Type::new(ChildProcessT)))) .add_var( "run_command".to_string(), Data::new(data::function::Function { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.types.iter().all(|t| t.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in(&data::string::StringT) && t.0[1].iterable().is_some_and(|t| t.is_included_in(&data::string::StringT)))) { + if a.types.iter().all(|t| t.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in_single(&data::string::StringT) && t.0[1].iterable().is_some_and(|t| t.is_included_in_single(&data::string::StringT)))) { Ok(Type::newm(vec![ Arc::new(data::tuple::TupleT(vec![ Type::newm(vec![Arc::new(data::int::IntT), Arc::new(data::bool::BoolT)]), @@ -82,7 +82,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.types.iter().all(|t| t.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in(&data::string::StringT) && t.0[1].iterable().is_some_and(|t| t.is_included_in(&data::string::StringT)))) { + if a.types.iter().all(|t| t.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in_single(&data::string::StringT) && t.0[1].iterable().is_some_and(|t| t.is_included_in_single(&data::string::StringT)))) { Ok(Type::newm(vec![ Arc::new(ChildProcessT), Arc::new(RunCommandErrorT) @@ -125,7 +125,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&ChildProcessT) { + if a.is_included_in_single(&ChildProcessT) { Ok(Type::newm(vec![ Arc::new(data::tuple::TupleT(vec![Type::new(data::bool::BoolT)])), Arc::new(data::tuple::TupleT(vec![])), @@ -153,7 +153,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&ChildProcessT) { + if a.is_included_in_single(&ChildProcessT) { Ok(Type::newm(vec![ Arc::new(data::int::IntT), Arc::new(data::bool::BoolT), @@ -186,7 +186,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.types.iter().all(|a| a.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in(&ChildProcessT) && t.0[1].iterable().is_some_and(|i| i.is_included_in(&data::byte::ByteT)))) { + if a.types.iter().all(|a| a.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in_single(&ChildProcessT) && t.0[1].iterable().is_some_and(|i| i.is_included_in_single(&data::byte::ByteT)))) { Ok(Type::new(data::bool::BoolT)) } else { return Err(format!("childproc_write_bytes called on non-`(ChildProcess, Iter)` type {a}").into()); @@ -215,7 +215,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&data::tuple::TupleT(vec![Type::new(ChildProcessT), Type::new(data::string::StringT)])) { + if a.is_included_in_single(&data::tuple::TupleT(vec![Type::new(ChildProcessT), Type::new(data::string::StringT)])) { Ok(Type::new(data::bool::BoolT)) } else { return Err(format!("childproc_write_string called on non-`(ChildProcess, String)` type {a}").into()); @@ -244,7 +244,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&ChildProcessT) { + if a.is_included_in_single(&ChildProcessT) { Ok(Type::newm(vec![ Arc::new(data::tuple::TupleT(vec![Type::new(data::byte::ByteT)])), Arc::new(data::tuple::TupleT(vec![])), @@ -273,7 +273,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&ChildProcessT) { + if a.is_included_in_single(&ChildProcessT) { Ok(Type::newm(vec![ Arc::new(data::tuple::TupleT(vec![Type::new(data::byte::ByteT)])), Arc::new(data::tuple::TupleT(vec![])), @@ -302,7 +302,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&ChildProcessT) { + if a.is_included_in_single(&ChildProcessT) { Ok(Type::newm(vec![ Arc::new(data::tuple::TupleT(vec![Type::new(data::string::StringT)])), Arc::new(data::tuple::TupleT(vec![])), @@ -331,7 +331,7 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.is_included_in(&ChildProcessT) { + if a.is_included_in_single(&ChildProcessT) { Ok(Type::newm(vec![ Arc::new(data::tuple::TupleT(vec![Type::new(data::string::StringT)])), Arc::new(data::tuple::TupleT(vec![])), @@ -414,7 +414,7 @@ impl MersType for ChildProcessT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().is::() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { target.as_any().is::() } fn subtypes(&self, acc: &mut Type) { @@ -468,7 +468,7 @@ impl MersType for RunCommandErrorT { fn is_same_type_as(&self, other: &dyn MersType) -> bool { other.as_any().downcast_ref::().is_some() } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { self.is_same_type_as(target) } fn subtypes(&self, acc: &mut Type) { diff --git a/mers_lib/src/program/configs/with_get.rs b/mers_lib/src/program/configs/with_get.rs index 125a773..c547707 100755 --- a/mers_lib/src/program/configs/with_get.rs +++ b/mers_lib/src/program/configs/with_get.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, program::{self, run::CheckInfo}, }; @@ -22,7 +22,7 @@ impl Config { if t.0.len() != 2 { return Err(format!("called get on tuple with len != 2").into()); } - if !t.0[1].is_included_in(&data::int::IntT) { + if !t.0[1].is_included_in_single(&data::int::IntT) { return Err(format!( "called get with non-int index of type {}", t.0[1] @@ -30,7 +30,7 @@ impl Config { .into()); } if let Some(v) = t.0[0].get() { - out.add(Arc::new(v)); + out.add_all(&v); } else { return Err(format!( "called get on non-gettable type {t}, part of {a}" diff --git a/mers_lib/src/program/configs/with_iters.rs b/mers_lib/src/program/configs/with_iters.rs index 7f84e54..8ebf0e8 100755 --- a/mers_lib/src/program/configs/with_iters.rs +++ b/mers_lib/src/program/configs/with_iters.rs @@ -327,7 +327,7 @@ impl IterT { let t = match &iter { ItersT::Map(f) => f.o(&data)?, ItersT::Filter(f) => { - if f.o(&data)?.is_included_in(&data::bool::BoolT) { + if f.o(&data)?.is_included_in_single(&data::bool::BoolT) { data.clone() } else { return Err(format!( @@ -381,7 +381,7 @@ impl MersType for IterT { false } } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { if let Some(target) = target.as_any().downcast_ref::() { self.2.is_included_in(&target.2) } else { @@ -440,7 +440,7 @@ fn genfunc_iter_in_val_out( info_check: Arc::new(Mutex::new(crate::info::Info::neverused())), out: Arc::new(move |a, _i| { if let Some(iter_over) = a.iterable() { - if iter_over.is_included_in(&iter_type) { + if iter_over.is_included_in_single(&iter_type) { Ok(out_type.clone()) } else { Err(format!("Cannot call function {name} on iterator over type {a}, which isn't {iter_type}.").into()) diff --git a/mers_lib/src/program/configs/with_list.rs b/mers_lib/src/program/configs/with_list.rs index 747be08..aa715fe 100755 --- a/mers_lib/src/program/configs/with_list.rs +++ b/mers_lib/src/program/configs/with_list.rs @@ -29,7 +29,7 @@ impl Config { let mut src = Source::new_from_string_raw(s.to_owned()); let srca = Arc::new(src.clone()); let t = crate::parsing::types::parse_type(&mut src, &srca)?; - Ok(Arc::new(ListT(crate::parsing::types::type_from_parsed(&t, i)?)))}))) + Ok(Arc::new(Type::new(ListT(crate::parsing::types::type_from_parsed(&t, i)?))))}))) .add_var("get_mut".to_string(), Data::new(data::function::Function { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new(CheckInfo::neverused())), @@ -107,7 +107,7 @@ impl Config { let mut out = Type::empty(); for t in a.types.iter() { if let Some(t) = t.as_any().downcast_ref::() { - out.add(Arc::new(t.0.clone())); + out.add_all(&t.0); } else { return Err(format!( "pop: found a reference to {t}, which is not a list" @@ -115,8 +115,8 @@ impl Config { } } Ok(Type::newm(vec![ - Arc::new(Type::new(data::tuple::TupleT(vec![out]))), - Arc::new(Type::empty_tuple()) + Arc::new(data::tuple::TupleT(vec![out])), + Arc::new(data::tuple::TupleT(vec![])) ])) } else { return Err(format!("pop: not a reference: {a}").into()); @@ -286,7 +286,7 @@ impl MersType for ListT { .downcast_ref::() .is_some_and(|v| self.0.is_same_type_as(&v.0)) } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { target .as_any() .downcast_ref::() @@ -333,7 +333,7 @@ impl List { pub fn inner_type(&self) -> Type { let mut t = Type::empty(); for el in &self.0 { - t.add(Arc::new(el.read().unwrap().get().as_type())); + t.add_all(&el.read().unwrap().get().as_type()); } t } diff --git a/mers_lib/src/program/configs/with_math.rs b/mers_lib/src/program/configs/with_math.rs index 74f9960..07a1f66 100755 --- a/mers_lib/src/program/configs/with_math.rs +++ b/mers_lib/src/program/configs/with_math.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::CheckError, program::{self, run::CheckInfo}, }; diff --git a/mers_lib/src/program/configs/with_multithreading.rs b/mers_lib/src/program/configs/with_multithreading.rs index a22d1f7..2dbee37 100755 --- a/mers_lib/src/program/configs/with_multithreading.rs +++ b/mers_lib/src/program/configs/with_multithreading.rs @@ -24,7 +24,7 @@ impl Config { let mut src = Source::new_from_string_raw(s.to_owned()); let srca = Arc::new(src.clone()); let t = crate::parsing::types::parse_type(&mut src, &srca)?; - Ok(Arc::new(ThreadT(crate::parsing::types::type_from_parsed(&t, i)?))) + Ok(Arc::new(Type::new(ThreadT(crate::parsing::types::type_from_parsed(&t, i)?)))) })), ) .add_var( @@ -37,7 +37,7 @@ impl Config { for t in a.types.iter() { if let Some(f) = t.as_any().downcast_ref::() { match f.o(&Type::empty_tuple()) { - Ok(t) => out.add(Arc::new(t)), + Ok(t) => out.add_all(&t), Err(e) => return Err(CheckError::new().msg(format!("Can't call thread on a function which can't be called on an empty tuple: ")).err(e)) } } else { @@ -91,7 +91,7 @@ impl Config { let mut out = Type::empty(); for t in a.types.iter() { if let Some(t) = t.as_any().downcast_ref::() { - out.add(Arc::new(Clone::clone(&t.0))); + out.add_all(&t.0); } else { return Err(CheckError::new().msg(format!("Cannot call thread_await on a value of type {t}, which isn't a thread but part of the argument {a}."))); } @@ -146,9 +146,9 @@ impl MersType for ThreadT { false } } - fn is_included_in_single(&self, target: &dyn MersType) -> bool { + fn is_included_in(&self, target: &dyn MersType) -> bool { if let Some(target) = target.as_any().downcast_ref::() { - self.0.is_included_in_single(&target.0) + self.0.is_included_in(&target.0) } else { false } diff --git a/mers_lib/src/program/configs/with_string.rs b/mers_lib/src/program/configs/with_string.rs index 53d3631..67b9eae 100755 --- a/mers_lib/src/program/configs/with_string.rs +++ b/mers_lib/src/program/configs/with_string.rs @@ -1,6 +1,6 @@ use std::sync::{Arc, RwLock}; -use crate::data::{self, Data, MersType, Type}; +use crate::data::{self, Data, Type}; use super::{util, Config}; @@ -44,13 +44,13 @@ impl Config { if t.0.len() != 2 && t.0.len() != 3 { return Err(format!("cannot call substring with tuple argument of len != 3").into()); } - if !t.0[0].is_included_in(&data::string::StringT) { + if !t.0[0].is_included_in_single(&data::string::StringT) { return Err(format!("cannot call substring with tuple argument that isn't (*string*, int, int)").into()); } - if !t.0[1].is_included_in(&data::int::IntT) { + if !t.0[1].is_included_in_single(&data::int::IntT) { return Err(format!("cannot call substring with tuple argument that isn't (string, *int*, int)").into()); } - if t.0.len() > 2 && !t.0[2].is_included_in(&data::int::IntT) { + if t.0.len() > 2 && !t.0[2].is_included_in_single(&data::int::IntT) { return Err(format!("cannot call substring with tuple argument that isn't (string, int, *int*)").into()); } } else { diff --git a/mers_lib/src/program/run/as_type.rs b/mers_lib/src/program/run/as_type.rs index f732224..f59abb3 100644 --- a/mers_lib/src/program/run/as_type.rs +++ b/mers_lib/src/program/run/as_type.rs @@ -1,7 +1,7 @@ use colored::Colorize; use crate::{ - data::{Data, MersType, Type}, + data::{Data, Type}, errors::{error_colors, CheckError, SourceRange}, parsing::types::ParsedType, }; diff --git a/mers_lib/src/program/run/assign_to.rs b/mers_lib/src/program/run/assign_to.rs index 1f737ce..0ed67f8 100755 --- a/mers_lib/src/program/run/assign_to.rs +++ b/mers_lib/src/program/run/assign_to.rs @@ -1,7 +1,7 @@ use colored::Colorize; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::{error_colors, CheckError, SourceRange}, }; diff --git a/mers_lib/src/program/run/chain.rs b/mers_lib/src/program/run/chain.rs index 3f095ca..92ff676 100755 --- a/mers_lib/src/program/run/chain.rs +++ b/mers_lib/src/program/run/chain.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use colored::Colorize; use crate::{ @@ -40,7 +38,7 @@ impl MersStatement for Chain { .downcast_ref::() { match func.o(&arg) { - Ok(t) => o.add(Arc::new(t)), + Ok(t) => o.add_all(&t), Err(e) => { return Err(if let Some(_) = &self.as_part_of_include { CheckError::new() diff --git a/mers_lib/src/program/run/custom_type.rs b/mers_lib/src/program/run/custom_type.rs index ca122f9..190b937 100644 --- a/mers_lib/src/program/run/custom_type.rs +++ b/mers_lib/src/program/run/custom_type.rs @@ -1,7 +1,7 @@ use std::{fmt::Debug, sync::Arc}; use crate::{ - data::{Data, MersType, Type}, + data::{Data, Type}, errors::{CheckError, SourceRange}, }; @@ -15,12 +15,8 @@ pub struct CustomType { &CheckInfo, ) -> Result< Result< - Arc, - Arc< - dyn Fn(&str, &CheckInfo) -> Result, CheckError> - + Send - + Sync, - >, + Arc, + Arc Result, CheckError> + Send + Sync>, >, CheckError, > + Send diff --git a/mers_lib/src/program/run/if.rs b/mers_lib/src/program/run/if.rs index ee30a31..b436428 100755 --- a/mers_lib/src/program/run/if.rs +++ b/mers_lib/src/program/run/if.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use colored::Colorize; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, tuple::TupleT, Data, Type}, errors::{error_colors, CheckError, SourceRange}, }; @@ -27,7 +27,7 @@ impl MersStatement for If { return Err("can't init to statement type If".to_string().into()); } let cond_return_type = self.condition.check(info, None)?; - if !cond_return_type.is_included_in(&data::bool::BoolT) { + if !cond_return_type.is_included_in_single(&data::bool::BoolT) { return Err(CheckError::new() .src(vec![ (self.pos_in_src.clone(), None), @@ -46,9 +46,9 @@ impl MersStatement for If { } let mut t = self.on_true.check(info, None)?; if let Some(f) = &self.on_false { - t.add(Arc::new(f.check(info, None)?)); + t.add_all(&f.check(info, None)?); } else { - t.add(Arc::new(Type::empty_tuple())); + t.add(Arc::new(TupleT(vec![]))); } Ok(t) } diff --git a/mers_lib/src/program/run/mod.rs b/mers_lib/src/program/run/mod.rs index 67dd7ac..289612f 100755 --- a/mers_lib/src/program/run/mod.rs +++ b/mers_lib/src/program/run/mod.rs @@ -5,7 +5,7 @@ use std::{ }; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::{CheckError, SourceRange}, info, }; @@ -121,8 +121,8 @@ pub struct CheckLocal { pub types: HashMap< String, Result< - Arc, - Arc Result, CheckError> + Send + Sync>, + Arc, + Arc Result, CheckError> + Send + Sync>, >, >, } diff --git a/mers_lib/src/program/run/object.rs b/mers_lib/src/program/run/object.rs index dad4eab..ab15d06 100644 --- a/mers_lib/src/program/run/object.rs +++ b/mers_lib/src/program/run/object.rs @@ -1,4 +1,4 @@ -use std::{collections::VecDeque, sync::Arc}; +use std::collections::VecDeque; use colored::Colorize; @@ -43,7 +43,7 @@ impl MersStatement for Object { } ).into()); } - acc[i].add(Arc::new(t.clone())); + acc[i].add_all(&t); } } else { return Err(format!( diff --git a/mers_lib/src/program/run/try.rs b/mers_lib/src/program/run/try.rs index bd339ba..c424e44 100644 --- a/mers_lib/src/program/run/try.rs +++ b/mers_lib/src/program/run/try.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use crate::{ - data::{self, Data, MersType, Type}, + data::{self, Data, Type}, errors::{error_colors, CheckError, SourceRange}, }; diff --git a/mers_lib/src/program/run/tuple.rs b/mers_lib/src/program/run/tuple.rs index 048b547..8387b30 100755 --- a/mers_lib/src/program/run/tuple.rs +++ b/mers_lib/src/program/run/tuple.rs @@ -1,4 +1,4 @@ -use std::{collections::VecDeque, sync::Arc}; +use std::collections::VecDeque; use colored::Colorize; @@ -29,7 +29,7 @@ impl MersStatement for Tuple { if let Some(t) = t.as_any().downcast_ref::() { if t.0.len() == self.elems.len() { for (i, e) in t.0.iter().enumerate() { - vec[i].add(Arc::new(e.clone())); + vec[i].add_all(&e); } } else { return Err(