summaryrefslogtreecommitdiff
path: root/app/Code.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2022-11-13 00:46:38 +0100
committerMirek Kratochvil <exa.exa@gmail.com>2022-11-13 00:46:38 +0100
commit8d5353dc8c7ef3eefb0ae4860e67602c455c1a58 (patch)
treec668dc93c1dddd517cfd771da5506c2159e6a2c7 /app/Code.hs
parent9d7868431792dcd94ec71adb9f95f55ab4bf027d (diff)
downloadprlg-8d5353dc8c7ef3eefb0ae4860e67602c455c1a58.tar.gz
prlg-8d5353dc8c7ef3eefb0ae4860e67602c455c1a58.tar.bz2
builtins are built in
Diffstat (limited to 'app/Code.hs')
-rw-r--r--app/Code.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/app/Code.hs b/app/Code.hs
index 00d1d1c..5721d17 100644
--- a/app/Code.hs
+++ b/app/Code.hs
@@ -1,8 +1,10 @@
module Code where
+import Control.Monad.Trans.State.Lazy
import qualified Data.Map as M
import IR (Id(..), StrTable)
import Operators (Ops)
+import System.Console.Haskeline
data Datum
= Atom Int -- unifies a constant
@@ -12,16 +14,10 @@ data Datum
| HeapRef Int (Maybe Int) -- heap structure idx
deriving (Show, Eq, Ord)
-data BuiltinFunc =
- BuiltinFunc (Interp -> Interp)
-
-instance Show BuiltinFunc where
- show _ = "BuiltinFunc _"
-
data Instr
= U Datum -- something unifiable
| NoGoal -- trivial goal (directly after head)
- | Builtin BuiltinFunc -- trivial goal (directly after head)
+ | Invoke Builtin -- also directly after head
| Goal -- a new goal (set head)
| Call -- all seems okay, call the head's hoal
| LastCall -- tail call the head's goal
@@ -64,3 +60,13 @@ data Interp =
, strtable :: StrTable -- string table
}
deriving (Show)
+
+type PrlgEnv a = StateT Interp (InputT IO) a
+
+type BuiltinFn = PrlgEnv (Maybe (Either String Bool))
+
+data Builtin =
+ Builtin BuiltinFn
+
+instance Show Builtin where
+ show _ = "Builtin _"