Changeset 16412

Show
Ignore:
Timestamp:
05/18/07 00:13:01 (18 months ago)
Author:
audreyt
Message:

* Pugs.AST.Internals - Tidy up initial structs for the new VCode/Pad

layout for greater sanity.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/AST/Internals.hs

    r16391 r16412  
    1111    SubAssoc(..), TraitBlocks(..), emptyTraitBlocks, 
    1212 
    13     MPad, Pad(..), PadEntry(..), EntryFlags(..), PadMutator, -- uses Var, TVar, VRef 
     13    MPad(..), LexPad(..), LexPads, Pad(..), PadEntry(..), EntryFlags(..), PadMutator, -- uses Var, TVar, VRef 
    1414    Param(..), -- uses Cxt, Exp 
    1515    Params, -- uses Param 
     
    10361036-- | Represents a sub, method, closure etc. -- basically anything callable. 
    10371037data VCode = MkCode 
    1038     { isMulti           :: !Bool        -- ^ Is this a multi sub\/method? 
    1039     , subName           :: !ByteString  -- ^ Name of the closure 
    1040     , subType           :: !SubType     -- ^ Type of the closure 
    1041     , subLexPads        :: !LexPads     -- ^ Lexical pads for thie scope 
    1042     , subLexical        :: !Pad         -- ^ Cached merged pads 
    1043     , subEntered        :: !(TVar Bool) -- ^ Whether this pad has been entered before (for runtime) 
    1044     , subPackage        :: !Pkg         -- ^ Package of the subroutine 
    1045     , subAssoc          :: !SubAssoc    -- ^ Associativity 
    1046     , subParams         :: !Params      -- ^ Parameters list 
    1047     , subBindings       :: !Bindings    -- ^ Currently assumed bindings 
    1048     , subSlurpLimit     :: !SlurpLimit  -- ^ Max. number of slurpy arguments 
    1049     , subReturns        :: !Type        -- ^ Return type 
    1050     , subLValue         :: !Bool        -- ^ Is this a lvalue sub? 
    1051     , subBody           :: !Exp         -- ^ Body of the closure 
     1038    { isMulti           :: !Bool                  -- ^ Is this a multi sub\/method? 
     1039    , subName           :: !ByteString            -- ^ Name of the closure 
     1040    , subType           :: !SubType               -- ^ Type of the closure 
     1041    , subOuterPads      :: !LexPads               -- ^ Lexical pads for this scope 
     1042    , subInnerPad       :: !Pad                   -- ^ Inner lexical pad (immutable) 
     1043--  , subLexical        :: !Pad                   -- ^ Cached merged pads 
     1044    , subPackage        :: !Pkg                   -- ^ Package of the subroutine 
     1045    , subAssoc          :: !SubAssoc              -- ^ Associativity 
     1046    , subParams         :: !Params                -- ^ Parameters list 
     1047    , subBindings       :: !Bindings              -- ^ Currently assumed bindings 
     1048    , subSlurpLimit     :: !SlurpLimit            -- ^ Max. number of slurpy arguments 
     1049    , subReturns        :: !Type                  -- ^ Return type 
     1050    , subLValue         :: !Bool                  -- ^ Is this a lvalue sub? 
     1051    , subBody           :: !Exp                   -- ^ Body of the closure 
    10521052    , subCont           :: !(Maybe (TVar VThunk)) -- ^ Coroutine re-entry point 
    10531053    , subStarted        :: !(Maybe (TVar Bool))   -- ^ Whether START was run 
     
    10811081mkPrim :: VCode 
    10821082mkPrim = MkCode 
    1083     { isMulti = True 
    1084     , subName = cast "&" 
    1085     , subType = SubPrim 
    1086     , subLexPads = [] 
    1087     , subPackage = emptyPkg 
    1088     , subAssoc = ANil 
    1089     , subParams = [] 
    1090     , subBindings = [] 
    1091     , subSlurpLimit = [] 
    1092     , subReturns = anyType 
    1093     , subBody = emptyExp 
    1094     , subLValue = False 
    1095     , subCont = Nothing 
     1083    { isMulti        = True 
     1084    , subName        = cast "&" 
     1085    , subType        = SubPrim 
     1086    , subOuterPads   = [] 
     1087    , subInnerPad    = emptyPad 
     1088--  , subLexical     = emptyPad 
     1089    , subPackage     = emptyPkg 
     1090    , subAssoc       = ANil 
     1091    , subParams      = [] 
     1092    , subBindings    = [] 
     1093    , subSlurpLimit  = [] 
     1094    , subReturns     = anyType 
     1095    , subBody        = emptyExp 
     1096    , subLValue      = False 
     1097    , subCont        = Nothing 
     1098    , subStarted     = Nothing 
    10961099    , subTraitBlocks = emptyTraitBlocks 
    10971100    } 
     
    10991102mkSub :: VCode 
    11001103mkSub = MkCode 
    1101     { isMulti = False 
    1102     , subName = cast "&" 
    1103     , subType = SubBlock 
    1104     , subLexPads = [] 
    1105     , subPackage = emptyPkg 
    1106     , subAssoc = ANil 
    1107     , subParams = [] 
    1108     , subBindings = [] 
    1109     , subSlurpLimit = [] 
    1110     , subReturns = anyType 
    1111     , subBody = emptyExp 
    1112     , subLValue = False 
    1113     , subCont = Nothing 
     1104    { isMulti        = False 
     1105    , subName        = cast "&" 
     1106    , subType        = SubBlock 
     1107    , subOuterPads   = [] 
     1108    , subInnerPad    = emptyPad 
     1109--  , subLexical     = emptyPad 
     1110    , subPackage     = emptyPkg 
     1111    , subAssoc       = ANil 
     1112    , subParams      = [] 
     1113    , subBindings    = [] 
     1114    , subSlurpLimit  = [] 
     1115    , subReturns     = anyType 
     1116    , subBody        = emptyExp 
     1117    , subLValue      = False 
     1118    , subCont        = Nothing 
     1119    , subStarted     = Nothing 
    11141120    , subTraitBlocks = emptyTraitBlocks 
    11151121    } 
     
    11171123mkCode :: VCode 
    11181124mkCode = MkCode 
    1119     { isMulti = False 
    1120     , subName = cast "&" 
    1121     , subType = SubBlock 
    1122     , subLexPads = [] 
    1123     , subPackage = emptyPkg 
    1124     , subAssoc = ANil 
    1125     , subParams = [] 
    1126     , subBindings = [] 
    1127     , subSlurpLimit = [] 
    1128     , subReturns = anyType 
    1129     , subBody = emptyExp 
    1130     , subLValue = False 
    1131     , subCont = Nothing 
     1125    { isMulti        = False 
     1126    , subName        = cast "&" 
     1127    , subType        = SubBlock 
     1128    , subOuterPads   = [] 
     1129    , subInnerPad    = emptyPad 
     1130--  , subLexical     = emptyPad 
     1131    , subPackage     = emptyPkg 
     1132    , subAssoc       = ANil 
     1133    , subParams      = [] 
     1134    , subBindings    = [] 
     1135    , subSlurpLimit  = [] 
     1136    , subReturns     = anyType 
     1137    , subBody        = emptyExp 
     1138    , subLValue      = False 
     1139    , subCont        = Nothing 
     1140    , subStarted     = Nothing 
    11321141    , subTraitBlocks = emptyTraitBlocks 
    11331142    }  
     
    13261335type DebugInfo = Maybe (TVar (Map ID String)) 
    13271336 
    1328 data LexPads 
    1329     = PCompiling { pc_pads :: !([MPad]) } 
    1330     | PRuntime 
    1331         { pr_pads   :: !([Pad]) 
    1332         , pr_merged :: !Pad 
    1333 --      , pr_fresh  :: !(TVar Bool) 
    1334         } 
    1335  
    1336  
    1337 data LexPads 
    1338     = PRuntime      ![Pad] 
    1339     | PCompiling    ![MPad] 
     1337type LexPads = [LexPad] 
     1338data LexPad 
     1339    = PRuntime      { pr_pad :: !Pad } 
     1340    | PCompiling    { pc_pad :: !MPad } 
    13401341    deriving (Show, Eq, Ord, Typeable) 
    13411342 
     
    13481349-} 
    13491350data Env = MkEnv 
    1350     { envContext :: !Cxt                 -- ^ Current context 
    1351                                          -- ('CxtVoid', 'CxtItem' or 'CxtSlurpy') 
    1352     , envLValue  :: !Bool                -- ^ Are we in an LValue context? 
    1353     , envLexical :: !Pad                 -- ^ Cached lexical pad for variable lookup 
    1354     , envLexPads :: ![TVar Pad]          -- ^ Current lexical pads; MY is leftmost, OUTER is next, etc 
    1355     , envDynPads :: ![Pad]               -- ^ CONTEXT pads; CALLER is leftmost (CALLER::OUTER is not there) 
    1356     , envCompPad :: !(Maybe (TVar Pad))  -- ^ Current COMPILING pad 
    1357     , envGlobal  :: !(TVar Pad)          -- ^ Global pad for variable lookup 
    1358     , envPackage :: !Pkg                 -- ^ Current package 
    1359     , envEval    :: !(Exp -> Eval Val)   -- ^ Active evaluator 
    1360     , envBody    :: !Exp                 -- ^ Current AST expression 
    1361     , envFrames  :: !(Set Frame)         -- ^ Special-markers in the dynamic path 
    1362     , envDebug   :: !DebugInfo           -- ^ Debug info map 
    1363     , envPos     :: !Pos                 -- ^ Source position range 
    1364     , envPragmas :: ![Pragma]            -- ^ List of pragmas in effect 
    1365     , envInitDat :: !(TVar InitDat)      -- ^ BEGIN result information 
    1366     , envMaxId   :: !(TVar ObjectId)     -- ^ Current max object id 
    1367     , envAtomic  :: !Bool                -- ^ Are we in an atomic transaction? 
     1351    { envContext :: !Cxt                -- ^ Current context 
     1352                                        -- ('CxtVoid', 'CxtItem' or 'CxtSlurpy') 
     1353    , envLValue  :: !Bool               -- ^ Are we in an LValue context? 
     1354    , envLexical :: !Pad                -- ^ Cached lexical pad for variable lookup 
     1355    , envLexPads :: !LexPads            -- ^ Current lexical pads; MY is leftmost, OUTER is next, etc 
     1356    , envCaller  :: !(Maybe Env)        -- ^ CALLER pads 
     1357    , envCompPad :: !(Maybe MPad)       -- ^ Current COMPILING pad 
     1358    , envGlobal  :: !MPad               -- ^ Global pad for variable lookup 
     1359    , envPackage :: !Pkg                -- ^ Current package 
     1360    , envEval    :: !(Exp -> Eval Val)  -- ^ Active evaluator 
     1361    , envBody    :: !Exp                -- ^ Current AST expression 
     1362    , envFrames  :: !(Set Frame)        -- ^ Special-markers in the dynamic path 
     1363    , envDebug   :: !DebugInfo          -- ^ Debug info map 
     1364    , envPos     :: !Pos                -- ^ Source position range 
     1365    , envPragmas :: ![Pragma]           -- ^ List of pragmas in effect 
     1366    , envInitDat :: !(TVar InitDat)     -- ^ BEGIN result information 
     1367    , envMaxId   :: !(TVar ObjectId)    -- ^ Current max object id 
     1368    , envAtomic  :: !Bool               -- ^ Are we in an atomic transaction? 
    13681369    }  
    13691370    deriving (Show, Eq, Ord, Typeable) -- don't derive YAML for now 
     
    20262027    return $ MkEnv 
    20272028        { envContext = CxtVoid 
    2028         , envLexical = MkPad Map.empty 
     2029        , envLexical = emptyPad 
    20292030        , envLexPads = [] 
    2030         , envDynPads = [] 
     2031        , envCaller  = Nothing 
    20312032        , envCompPad = Nothing 
    20322033        , envLValue  = False