From 9498270f46646c34cba3885a2e455b08daf9c324 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 30 Jun 2016 21:18:07 +0200 Subject: Descriptors, Program --- Def.dcl | 22 ++++++++++++++++++++++ Descriptors.dcl | 14 ++++++++++++++ Descriptors.icl | 24 ++++++++++++++++++++++++ Program.dcl | 13 +++++++++++++ Program.icl | 30 ++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+) create mode 100644 Descriptors.dcl create mode 100644 Descriptors.icl create mode 100644 Program.dcl create mode 100644 Program.icl diff --git a/Def.dcl b/Def.dcl index fe68896..a0c3f6c 100644 --- a/Def.dcl +++ b/Def.dcl @@ -1,9 +1,31 @@ definition module ABC.Def +from ABC.AStack import ::AStack +from ABC.BStack import ::BStack +from ABC.CStack import ::CStack +from ABC.GraphStore import ::GraphStore +from ABC.Descriptors import ::DescStore +from ABC.Program import ::ProgramStore +from ABC.IO import ::IO + +:: State = { astack :: AStack + , bstack :: BStack + , cstack :: CStack + , graphstore :: GraphStore + , descstore :: DescStore + , pc :: InstrId + , program :: ProgramStore + , io :: IO + } + :: NodeId :== Int :: NrArgs :== Int :: ArgNr :== Int :: DescId :== Int :: InstrId :== Int +:: Name :== String + +:: Instruction :== State -> State +:: APEntry :== InstrId :: Args :== [NodeId] diff --git a/Descriptors.dcl b/Descriptors.dcl new file mode 100644 index 0000000..b2dcce4 --- /dev/null +++ b/Descriptors.dcl @@ -0,0 +1,14 @@ +definition module ABC.Descriptors + +from ABC.Def import ::Arity, ::InstrId + +:: Desc = Desc APEntry Arity Name + +d_ap_entry :: Desc -> InstrId +d_arity :: Desc -> Arity +d_name :: Desc -> String + +:: DescStore (:== [Desc]) + +ds_get :: DescId DescStore -> Desc +ds_init :: [Desc] -> DescStore diff --git a/Descriptors.icl b/Descriptors.icl new file mode 100644 index 0000000..11ec8ea --- /dev/null +++ b/Descriptors.icl @@ -0,0 +1,24 @@ +implementation module ABC.Descriptors + +import StdEnv + +import ABC.Machine +import ABC.Misc + +d_ap_entry :: Desc -> InstrId +d_ap_entry (Desc e _ _) = e + +d_arity :: Desc -> Arity +d_arity (Desc _ a _) = a + +d_name :: Desc -> String +d_name (Desc _ _ n) = n + + +ds_get :: DescId DescStore -> Desc +ds_get 0 [d:_] = d +ds_get _ [] = abortn "ds_get: index too large" +ds_get i [_:s] = ds_get (i-1) s + +ds_init :: [Desc] -> DescStore +ds_init ds = ds diff --git a/Program.dcl b/Program.dcl new file mode 100644 index 0000000..31b61d7 --- /dev/null +++ b/Program.dcl @@ -0,0 +1,13 @@ +definition module ABC.Program + +from ABC.Def import ::InstrId, ::Instruction + +pc_init :: InstrId +pc_next :: InstrId -> InstrId +pc_halt :: InstrId -> InstrId +pc_end :: InstrId -> Bool + +:: ProgramStore + +ps_get :: InstrId ProgramStore -> Instruction +ps_init :: [Instruction] -> ProgramStore diff --git a/Program.icl b/Program.icl new file mode 100644 index 0000000..4a34ec6 --- /dev/null +++ b/Program.icl @@ -0,0 +1,30 @@ +implementation module ABC.Program + +import StdEnv + +import ABC.Machine +import ABC.Misc + +pc_init :: InstrId +pc_init = 0 + +pc_next :: InstrId -> InstrId +pc_next i = i + 1 + +pc_halt :: InstrId -> InstrId +pc_halt _ = -1 + +pc_end :: InstrId -> Bool +pc_end i = i < 0 + +:: Location = I Instruction +:: ProgramStore :== [Location] + +ps_get :: InstrId ProgramStore -> Instruction +ps_get 0 [I p:_] = p +ps_get _ [] = abortn "ps_get: index too large" +ps_get i [_:ps] = ps_get (i-1) ps + +ps_init :: [Instruction] -> ProgramStore +ps_init [] = [] +ps_init [i:is] = [I i:ps_init is] -- cgit v1.2.3