fix problem with Pohuy trait

This commit is contained in:
MeexReay 2024-07-29 00:57:34 +03:00
parent 31fac01e46
commit 8897ccfb0a
5 changed files with 726 additions and 412 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,9 @@
pub mod command; pub mod command;
pub mod other;
pub mod script; pub mod script;
pub mod var; pub mod var;
pub use command::*; pub use command::*;
pub use other::*;
pub use script::*; pub use script::*;
pub use var::*; pub use var::*;

5
src/sustlang/other.rs Normal file
View File

@ -0,0 +1,5 @@
pub trait Pohuy<T, E> {
fn pohuy(&self) {}
}
impl<T, E> Pohuy<T, E> for Result<T, E> {}

View File

@ -1,7 +1,7 @@
use super::super::command::{Command, CommandType}; use super::super::command::{Command, CommandType};
use super::super::script::ScriptError; use super::super::other::Pohuy;
use super::super::var::{VarType, Variable}; use super::super::var::{VarType, Variable};
use super::RunningScript; use super::{RunningScript, ScriptError};
use std::collections::HashMap; use std::collections::HashMap;
@ -33,7 +33,6 @@ impl Function {
script: &mut RunningScript, script: &mut RunningScript,
result_var: String, result_var: String,
args: Vec<Variable>, args: Vec<Variable>,
globals: &mut HashMap<String, Variable>,
is_global: bool, is_global: bool,
) -> Result<(), (ScriptError, Command)> { ) -> Result<(), (ScriptError, Command)> {
let mut locals: HashMap<String, Variable> = HashMap::new(); let mut locals: HashMap<String, Variable> = HashMap::new();
@ -54,27 +53,30 @@ impl Function {
return Ok(()); return Ok(());
} }
command command.execute(script, is_global, &mut locals, &mut temp_vars)?;
.execute(script, is_global, &mut locals, globals, &mut temp_vars)
.map_err(|f| (f, command.clone()))?;
if let CommandType::TempVar = command.command_type { if let CommandType::TempVar = command.command_type {
continue; continue;
} }
for ele in temp_vars.clone() { for ele in temp_vars.clone() {
script.drop_var(ele, &mut locals); script
.drop_var(ele, &mut locals)
.map_err(|f| (f, command.clone()))
.pohuy();
} }
} }
if result_var != "null" { if result_var != "null" {
script.set_var( script
.set_var(
result_var, result_var,
locals.get("result").unwrap().clone(), locals.get("result").unwrap().clone(),
is_global, is_global,
false, false,
&mut locals, &mut locals,
); )
.unwrap();
} }
Ok(()) Ok(())

View File

@ -288,9 +288,8 @@ impl RunningScript {
} }
pub fn run(&mut self) -> Result<(), (ScriptError, Command)> { pub fn run(&mut self) -> Result<(), (ScriptError, Command)> {
let globals = &mut self.variables.clone();
let main_function = self.main_function.clone(); let main_function = self.main_function.clone();
main_function.execute(self, "null".to_string(), Vec::new(), globals, true) main_function.execute(self, "null".to_string(), Vec::new(), true)
} }
} }