mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-14 11:16:17 +01:00
Type no longer implements MersType
This commit is contained in:
@@ -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<dyn MersType>,
|
||||
Arc<dyn Fn(&str, &CheckInfo) -> Result<Arc<dyn MersType>, CheckError> + Send + Sync>,
|
||||
Arc<Type>,
|
||||
Arc<dyn Fn(&str, &CheckInfo) -> Result<Arc<Type>, CheckError> + Send + Sync>,
|
||||
>,
|
||||
) -> Self {
|
||||
self.info_check.scopes[0].types.insert(name, t);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::{
|
||||
data::{self, Data, MersType, Type},
|
||||
data::{self, Data, Type},
|
||||
errors::CheckError,
|
||||
info::Info,
|
||||
};
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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::<data::tuple::TupleT>().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::<data::tuple::TupleT>().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::<data::tuple::TupleT>().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::<data::tuple::TupleT>().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::<data::tuple::TupleT>().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::<data::tuple::TupleT>().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<Byte>)` 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::<Self>()
|
||||
}
|
||||
fn is_included_in_single(&self, target: &dyn MersType) -> bool {
|
||||
fn is_included_in(&self, target: &dyn MersType) -> bool {
|
||||
target.as_any().is::<Self>()
|
||||
}
|
||||
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::<Self>().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) {
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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>() {
|
||||
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())
|
||||
|
||||
@@ -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::<ListT>() {
|
||||
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::<Self>()
|
||||
.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::<Self>()
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
};
|
||||
|
||||
@@ -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::<data::function::FunctionT>() {
|
||||
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::<ThreadT>() {
|
||||
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>() {
|
||||
self.0.is_included_in_single(&target.0)
|
||||
self.0.is_included_in(&target.0)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user