summaryrefslogtreecommitdiff
path: root/app/Env.hs
blob: 592d60801b513d359b9b87dd725753e9a43dccbb (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 (InterpFn, PrlgEnv)
import CodeLens
import qualified IR
import Lens.Family2.State

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

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

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

type PrlgEnv a = Code.PrlgEnv a

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