summaryrefslogtreecommitdiff
path: root/app/Env.hs
blob: 0b648f8654b538a025fdb60a24f82d00dff9d82b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Env where

import Code (Id(..), InterpFn, PrlgEnv)
import CodeLens
import IR (StrTable, strtablize)
import Lens.Micro.Mtl

withStrTable :: (StrTable -> (StrTable, a)) -> Env.PrlgEnv a
withStrTable f = do
  (st', x) <- f <$> use strtable
  strtable .= st'
  return x

findStruct :: String -> Int -> Env.PrlgEnv Id
findStruct str arity = do
  stri <- findAtom str
  return Id {str = stri, arity = arity}

findAtom :: String -> Env.PrlgEnv Int
findAtom = withStrTable . flip strtablize

type PrlgEnv a = Code.PrlgEnv a

prlgError :: String -> InterpFn
prlgError = pure . pure . Left