mirror of
https://github.com/Dummi26/mers.git
synced 2026-01-18 00:00:28 +01:00
fix "weird" behavior with globalinfo not updating
This commit is contained in:
@@ -80,11 +80,25 @@ impl Function {
|
||||
pub fn check(&self, arg: &Type) -> Result<Type, CheckError> {
|
||||
self.get_as_type().o(arg)
|
||||
}
|
||||
pub fn run_mut(&mut self, arg: Data) -> Result<Data, CheckError> {
|
||||
pub fn run_mut(
|
||||
&mut self,
|
||||
arg: Data,
|
||||
gi: crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Result<Data, CheckError> {
|
||||
self.info.global = gi;
|
||||
self.run_mut_with_prev_gi(arg)
|
||||
}
|
||||
pub fn run_mut_with_prev_gi(&mut self, arg: Data) -> Result<Data, CheckError> {
|
||||
(self.run)(arg, &mut self.info)
|
||||
}
|
||||
pub fn run_immut(&self, arg: Data) -> Result<Data, CheckError> {
|
||||
(self.run)(arg, &mut self.info.duplicate())
|
||||
pub fn run_immut(
|
||||
&self,
|
||||
arg: Data,
|
||||
gi: crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Result<Data, CheckError> {
|
||||
let mut i = self.info.duplicate();
|
||||
i.global = gi;
|
||||
(self.run)(arg, &mut i)
|
||||
}
|
||||
pub fn get_as_type(&self) -> FunctionT {
|
||||
let info = self.info_check.lock().unwrap().clone();
|
||||
@@ -114,13 +128,25 @@ impl MersData for Function {
|
||||
fn executable(&self) -> Option<crate::data::function::FunctionT> {
|
||||
Some(self.get_as_type())
|
||||
}
|
||||
fn execute(&self, arg: Data) -> Option<Result<Data, CheckError>> {
|
||||
Some(self.run_immut(arg))
|
||||
fn execute(
|
||||
&self,
|
||||
arg: Data,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Result<Data, CheckError>> {
|
||||
Some(self.run_immut(arg, gi.clone()))
|
||||
}
|
||||
fn iterable(&self) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
fn iterable(
|
||||
&self,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
let mut s = Clone::clone(self);
|
||||
let mut gi = Some(gi.clone());
|
||||
Some(Box::new(std::iter::from_fn(move || {
|
||||
match s.run_mut(Data::empty_tuple()) {
|
||||
match if let Some(gi) = gi.take() {
|
||||
s.run_mut(Data::empty_tuple(), gi)
|
||||
} else {
|
||||
s.run_mut_with_prev_gi(Data::empty_tuple())
|
||||
} {
|
||||
Err(e) => Some(Err(e)),
|
||||
Ok(v) => {
|
||||
if let Some(v) = v.one_tuple_content() {
|
||||
|
||||
@@ -30,16 +30,28 @@ pub trait MersData: Any + Debug + Send + Sync {
|
||||
None
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
fn execute(&self, arg: Data) -> Option<Result<Data, CheckError>> {
|
||||
fn execute(
|
||||
&self,
|
||||
arg: Data,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Result<Data, CheckError>> {
|
||||
None
|
||||
}
|
||||
fn iterable(&self) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
#[allow(unused_variables)]
|
||||
fn iterable(
|
||||
&self,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
None
|
||||
}
|
||||
/// By default, uses `iterable` to get an iterator and `nth` to retrieve the nth element.
|
||||
/// Should have a custom implementation for better performance on most types
|
||||
fn get(&self, i: usize) -> Option<Result<Data, CheckError>> {
|
||||
self.iterable()?.nth(i)
|
||||
fn get(
|
||||
&self,
|
||||
i: usize,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Result<Data, CheckError>> {
|
||||
self.iterable(gi)?.nth(i)
|
||||
}
|
||||
/// If self and other are different types (`other.as_any().downcast_ref::<Self>().is_none()`),
|
||||
/// this *must* return false.
|
||||
|
||||
@@ -27,7 +27,11 @@ impl MersData for Reference {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn execute(&self, arg: Data) -> Option<Result<Data, CheckError>> {
|
||||
fn execute(
|
||||
&self,
|
||||
arg: Data,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Result<Data, CheckError>> {
|
||||
let mut inner = self.0.write().unwrap();
|
||||
let mut inner = inner.get_mut();
|
||||
if let Some(func) = inner
|
||||
@@ -35,13 +39,17 @@ impl MersData for Reference {
|
||||
.mut_any()
|
||||
.downcast_mut::<crate::data::function::Function>()
|
||||
{
|
||||
Some(func.run_mut(arg))
|
||||
Some(func.run_mut(arg, gi.clone()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn iterable(&self) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
fn iterable(
|
||||
&self,
|
||||
gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let gi = gi.clone();
|
||||
Some(Box::new(std::iter::from_fn(move || {
|
||||
match inner
|
||||
.write()
|
||||
@@ -50,7 +58,7 @@ impl MersData for Reference {
|
||||
.mut_any()
|
||||
.downcast_mut::<crate::data::function::Function>()
|
||||
.unwrap()
|
||||
.run_mut(Data::empty_tuple())
|
||||
.run_mut(Data::empty_tuple(), gi.clone())
|
||||
{
|
||||
Err(e) => Some(Err(e)),
|
||||
Ok(v) => {
|
||||
|
||||
@@ -35,7 +35,10 @@ impl MersData for Tuple {
|
||||
false
|
||||
}
|
||||
}
|
||||
fn iterable(&self) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
fn iterable(
|
||||
&self,
|
||||
_gi: &crate::program::run::RunLocalGlobalInfo,
|
||||
) -> Option<Box<dyn Iterator<Item = Result<Data, CheckError>>>> {
|
||||
Some(Box::new(self.0.clone().into_iter().map(Ok)))
|
||||
}
|
||||
fn clone(&self) -> Box<dyn MersData> {
|
||||
|
||||
Reference in New Issue
Block a user