From 1c40dc42e7bc7b799b77f06d25414aca59a044ba Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 2 Jan 2021 19:37:10 +0100 Subject: =?UTF-8?q?Dynamic=20values,=20Types,=20Arrays,=20and=20Dictionari?= =?UTF-8?q?es=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Identifiers are now evaluated as variables instead of being plain values - Constants like `left` or `bold` are stored as dynamic values containing the respective rust types - We now distinguish between arrays and dictionaries to make things more intuitive (at the cost of a bit more complex parsing) - Spans were removed from collections (arrays, dictionaries), function arguments still have spans for the top-level values to enable good diagnostics --- src/eval/scope.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/eval/scope.rs') diff --git a/src/eval/scope.rs b/src/eval/scope.rs index c0624393..c9ce1423 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -3,12 +3,12 @@ use std::collections::HashMap; use std::fmt::{self, Debug, Formatter}; -use super::value::ValueFunc; +use super::Value; /// A map from identifiers to functions. #[derive(Default, Clone, PartialEq)] pub struct Scope { - functions: HashMap, + values: HashMap, } impl Scope { @@ -18,19 +18,19 @@ impl Scope { Self::default() } - /// Return the function with the given name if there is one. - pub fn get(&self, name: &str) -> Option<&ValueFunc> { - self.functions.get(name) + /// Return the value of the given variable. + pub fn get(&self, var: &str) -> Option<&Value> { + self.values.get(var) } - /// Associate the given name with the function. - pub fn set(&mut self, name: impl Into, function: ValueFunc) { - self.functions.insert(name.into(), function); + /// Store the value for the given variable. + pub fn set(&mut self, var: impl Into, value: impl Into) { + self.values.insert(var.into(), value.into()); } } impl Debug for Scope { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.debug_set().entries(self.functions.keys()).finish() + self.values.fmt(f) } } -- cgit v1.2.3