Changeset 6230

Show
Ignore:
Timestamp:
08/13/05 21:16:34 (3 years ago)
Author:
autrijus
svk:copy_cache_prev:
8452
Message:

* The "Perl5" code generator backend is upon us!

./pugs -CPerl5 -e 'say "Hello, World!"' | perl -MO=Deparse -

Location:
src
Files:
6 added
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/CodeGen.hs

    r6104 r6230  
    1616-- import Pugs.CodeGen.PIL2 (genPIL2) 
    1717import Pugs.CodeGen.PIR (genPIR) 
     18import Pugs.CodeGen.Perl5 (genPerl5) 
    1819import Pugs.Compile.Pugs (genPugs) 
    1920import Pugs.Compile.Haskell (genGHC) 
     
    2930    , ("Pil",         genPIL) 
    3031--  , ("Pil2",        genPIL2) 
     32    , ("Perl5",       genPerl5) 
    3133    , ("Pugs",        genPugs) 
    3234    ] 
  • src/Pugs/Compile.hs

    r6229 r6230  
    2626import Pugs.Eval.Var 
    2727import Pugs.Monads 
     28import Pugs.PIL1 
    2829import Emit.PIR 
    2930import Text.PrettyPrint 
    30  
    31 {-| 
    32     The plan here is to first compile the environment (subroutines, 
    33     statements, etc.) to an abstract syntax tree ('PIL' -- Pugs Intermediate 
    34     Language) using the 'compile' function and 'Compile' class. 
    35 -} 
    36  
    37 data PIL_Stmts = PNil 
    38     | PStmts 
    39         { pStmt  :: !PIL_Stmt 
    40         , pStmts :: !PIL_Stmts 
    41         } 
    42     | PPad 
    43         { pScope :: !Scope 
    44         , pSyms  :: ![(VarName, PIL_Expr)] 
    45         , pStmts :: !PIL_Stmts 
    46         } 
    47     deriving (Show, Eq, Ord, Typeable) 
    48  
    49 data PIL_Stmt = PNoop | PStmt { pExpr :: !PIL_Expr } | PPos 
    50         { pPos  :: !Pos 
    51         , pExp  :: !Exp 
    52         , pNode :: !PIL_Stmt 
    53         } 
    54     deriving (Show, Eq, Ord, Typeable) 
    55  
    56 data PIL_Expr 
    57     = PRawName { pRawName :: !VarName } 
    58     | PExp { pLV  :: !PIL_LValue } 
    59     | PLit { pLit :: !PIL_Literal } 
    60     | PThunk { pThunk :: !PIL_Expr } 
    61     | PCode 
    62         { pType    :: !SubType 
    63         , pParams  :: ![TParam] 
    64         , pBody    :: !PIL_Stmts 
    65         } 
    66     deriving (Show, Eq, Ord, Typeable) 
    67  
    68 data PIL_Decl = PSub 
    69     { pSubName      :: !SubName 
    70     , pSubType      :: !SubType 
    71     , pSubParams    :: ![TParam] 
    72     , pSubBody      :: !PIL_Stmts 
    73     } 
    74     deriving (Show, Eq, Ord, Typeable) 
    75  
    76 data PIL_Literal = PVal { pVal :: Val } 
    77     deriving (Show, Eq, Ord, Typeable) 
    78  
    79 data PIL_LValue = PVar { pVarName :: !VarName } 
    80     | PApp  
    81         { pCxt  :: !TCxt 
    82         , pFun  :: !PIL_Expr 
    83         , pInv  :: !(Maybe PIL_Expr) 
    84         , pArgs :: ![PIL_Expr] 
    85         } 
    86     | PAssign 
    87         { pLHS  :: ![PIL_LValue] 
    88         , pRHS  :: !PIL_Expr 
    89         } 
    90     | PBind 
    91         { pLHS  :: ![PIL_LValue] 
    92         , pRHS  :: !PIL_Expr 
    93         } 
    94     deriving (Show, Eq, Ord, Typeable) 
    95  
    96 data TParam = MkTParam 
    97     { tpParam   :: !Param 
    98     , tpDefault :: !(Maybe (PIL_Expr)) 
    99     } 
    100     deriving (Show, Eq, Ord, Typeable) 
    101  
    102 data TCxt 
    103     = TCxtVoid | TCxtLValue !Type | TCxtItem !Type | TCxtSlurpy !Type 
    104     | TTailCall !TCxt 
    105     deriving (Show, Eq, Ord, Typeable) 
    10631 
    10732tcVoid, tcLValue :: TCxt 
     
    11439tcSlurpy    = TCxtSlurpy anyType 
    11540-} 
    116  
    117 data TEnv = MkTEnv 
    118     { tLexDepth :: !Int                 -- ^ Lexical scope depth 
    119     , tTokDepth :: !Int                 -- ^ Exp nesting depth 
    120     , tCxt      :: !TCxt                -- ^ Current context 
    121     , tReg      :: !(TVar (Int, String))-- ^ Register name supply 
    122     , tLabel    :: !(TVar Int)          -- ^ Label name supply 
    123     } 
    124     deriving (Show, Eq, Ord, Typeable) 
    12541 
    12642type Comp a = Eval a