From 8ef7118dc1270386d5455e4d407a272a0c7b0724 Mon Sep 17 00:00:00 2001 From: ondra05 Date: Wed, 21 Sep 2022 00:28:57 +0200 Subject: [PATCH] initial vars - &mut self --- ablescript/src/host_interface.rs | 4 ++-- ablescript/src/interpret.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ablescript/src/host_interface.rs b/ablescript/src/host_interface.rs index 2f9ab3e..0808aab 100644 --- a/ablescript/src/host_interface.rs +++ b/ablescript/src/host_interface.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; /// Host Environment Interface pub trait HostInterface { /// Initial variables for a stack frame - fn initial_vars() -> HashMap; + fn initial_vars(&mut self) -> HashMap; /// Print a string fn print(&mut self, string: &str, new_line: bool) -> std::io::Result<()>; @@ -23,7 +23,7 @@ pub trait HostInterface { #[derive(Clone, Copy, Default)] pub struct Standard; impl HostInterface for Standard { - fn initial_vars() -> HashMap { + fn initial_vars(&mut self) -> HashMap { HashMap::default() } diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 6274e51..13c6fb3 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -89,12 +89,12 @@ pub const READ_BITS: u8 = 3; impl ExecEnv { /// Create a new Scope with no predefined variable definitions or /// other information. - pub fn with_host_interface(host_interface: H) -> Self { + pub fn with_host_interface(mut host_interface: H) -> Self { Self { stack: vec![ Default::default(), Scope { - variables: H::initial_vars(), + variables: host_interface.initial_vars(), }, ], read_buf: Default::default(), @@ -104,7 +104,7 @@ impl ExecEnv { } /// Create a new Scope with predefined variables - pub fn new_with_vars(host_interface: H, vars: I) -> Self + pub fn new_with_vars(mut host_interface: H, vars: I) -> Self where I: IntoIterator, { @@ -114,7 +114,7 @@ impl ExecEnv { variables: ablescript_consts().into_iter().chain(vars).collect(), }, Scope { - variables: H::initial_vars(), + variables: host_interface.initial_vars(), }, ], read_buf: Default::default(),