mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-16 20:17:50 +01:00
mers rewrite is starting to be usable
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
use crate::data::{self, Data};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::data::{self, Data, Type};
|
||||
|
||||
use super::MersStatement;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Variable {
|
||||
pub is_init: bool,
|
||||
pub is_ref: bool,
|
||||
pub var: (usize, usize),
|
||||
}
|
||||
@@ -12,19 +15,44 @@ impl MersStatement for Variable {
|
||||
fn has_scope(&self) -> bool {
|
||||
false
|
||||
}
|
||||
fn run_custom(&self, info: &mut super::Info) -> Data {
|
||||
while info.scopes[self.var.0].vars.len() <= self.var.1 {
|
||||
info.scopes[self.var.0]
|
||||
.vars
|
||||
.push(Data::new(data::bool::Bool(false)));
|
||||
fn check_custom(
|
||||
&self,
|
||||
info: &mut super::CheckInfo,
|
||||
init_to: Option<&Type>,
|
||||
) -> Result<data::Type, super::CheckError> {
|
||||
if self.is_init {
|
||||
while info.scopes[self.var.0].vars.len() <= self.var.1 {
|
||||
info.scopes[self.var.0].vars.push(Type::empty());
|
||||
}
|
||||
info.scopes[self.var.0].vars[self.var.1] = init_to
|
||||
.expect("variable's is_init was true, but check_custom's assign was None? How?")
|
||||
.clone();
|
||||
}
|
||||
if self.is_ref {
|
||||
Data::new(data::reference::Reference(
|
||||
Ok(if self.is_ref {
|
||||
Type::new(data::reference::ReferenceT(
|
||||
info.scopes[self.var.0].vars[self.var.1].clone(),
|
||||
))
|
||||
} else {
|
||||
// Full-Clones!
|
||||
Data::new_boxed(info.scopes[self.var.0].vars[self.var.1].get().clone())
|
||||
info.scopes[self.var.0].vars[self.var.1].clone()
|
||||
})
|
||||
}
|
||||
fn run_custom(&self, info: &mut super::Info) -> Data {
|
||||
if self.is_init {
|
||||
let nothing = Arc::new(Mutex::new(Data::new(data::bool::Bool(false))));
|
||||
while info.scopes[self.var.0].vars.len() <= self.var.1 {
|
||||
info.scopes[self.var.0].vars.push(Arc::clone(¬hing));
|
||||
}
|
||||
info.scopes[self.var.0].vars[self.var.1] = nothing;
|
||||
}
|
||||
if self.is_ref {
|
||||
Data::new(data::reference::Reference(Arc::clone(
|
||||
&info.scopes[self.var.0].vars[self.var.1],
|
||||
)))
|
||||
} else {
|
||||
info.scopes[self.var.0].vars[self.var.1]
|
||||
.lock()
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user