summaryrefslogtreecommitdiff
path: root/src/Hint/Eval.hs
diff options
context:
space:
mode:
authorKleidi Bujari <mail@4kb.net>2026-10-08 00:38:07 -0700
committerKleidi Bujari <mail@4kb.net>2026-10-08 00:41:13 -0700
commitb029315b7438b90b11d397c0db461065c8054bab (patch)
treeec284614576ce0e03fb4b49a97efa34dbbc36536 /src/Hint/Eval.hs
parent0d88f48bac56fe6a3134c9059309b5d8c2a3b580 (diff)
downloadhint-b029315b7438b90b11d397c0db461065c8054bab.tar.gz
hint-b029315b7438b90b11d397c0db461065c8054bab.tar.bz2
hint-b029315b7438b90b11d397c0db461065c8054bab.zip
simple stackful dictionary for tracking scope
Diffstat (limited to 'src/Hint/Eval.hs')
-rw-r--r--src/Hint/Eval.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Hint/Eval.hs b/src/Hint/Eval.hs
new file mode 100644
index 0000000..48f7b46
--- /dev/null
+++ b/src/Hint/Eval.hs
@@ -0,0 +1,32 @@
+module Hint.Eval where
+
+import Control.Applicative ((<|>))
+import qualified Data.Map as M
+import Hint.Parser (Value (..))
+
+type Ident = String
+type Env = M.Map Ident Value
+
+data Scope = Scope
+ { env :: [Env] }
+ deriving (Show, Eq)
+
+defaultEnv :: Env
+defaultEnv = M.fromList [("pi", VInt 3), ("version", VString "0.1")]
+
+basic :: Scope
+basic = Scope (pure defaultEnv)
+
+next :: Env
+next = M.fromList [("ident", VInt 12), ("pi", VInt 4)]
+
+enter :: Scope -> Env -> Scope
+enter (Scope es) e = Scope (e : es)
+
+leave :: Scope -> Scope
+leave (Scope [] ) = error "bad"
+leave (Scope (_ : es)) = Scope es
+
+scopeLookup :: Ident -> Scope -> Maybe Value
+scopeLookup _ (Scope []) = Nothing
+scopeLookup i (Scope (e : es)) = M.lookup i e <|> scopeLookup i (Scope es)