From 8d5353dc8c7ef3eefb0ae4860e67602c455c1a58 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sun, 13 Nov 2022 00:46:38 +0100 Subject: builtins are built in --- app/Code.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'app/Code.hs') 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 _" -- cgit v1.2.3