summaryrefslogtreecommitdiff
path: root/src/eval/scope.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-02 19:37:10 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-02 19:37:10 +0100
commit1c40dc42e7bc7b799b77f06d25414aca59a044ba (patch)
treeea8bdedaebf59f5bc601346b0108236c7264a29d /src/eval/scope.rs
parent8cad78481cd52680317032c3bb84cacda5666489 (diff)
Dynamic values, Types, Arrays, and Dictionaries 🚀
- 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
Diffstat (limited to 'src/eval/scope.rs')
-rw-r--r--src/eval/scope.rs18
1 files changed, 9 insertions, 9 deletions
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<String, ValueFunc>,
+ values: HashMap<String, Value>,
}
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<String>, function: ValueFunc) {
- self.functions.insert(name.into(), function);
+ /// Store the value for the given variable.
+ pub fn set(&mut self, var: impl Into<String>, value: impl Into<Value>) {
+ 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)
}
}