| | 87 | trans (PThunk exp) = do |
| | 88 | [begL, sndL, retL, endL] <- genLabel ["thunkBegin", "thunkAgain", "thunkReturn", "thunkEnd"] |
| | 89 | this <- genPMC "block" |
| | 90 | tellIns $ "newsub" .- [reg this, bare ".Continuation", bare begL] |
| | 91 | tellIns $ "goto" .- [bare endL] |
| | 92 | tellLabel begL |
| | 93 | cc <- genPMC "cc" |
| | 94 | fetchCC cc (reg this) |
| | 95 | expC <- trans exp |
| | 96 | tellIns $ "set_addr" .- [reg this, bare sndL] |
| | 97 | tellIns $ "goto" .- [bare retL] |
| | 98 | tellLabel sndL |
| | 99 | fetchCC cc (reg this) |
| | 100 | tellLabel retL |
| | 101 | tellIns $ if parrotBrokenXXX |
| | 102 | then "store_global" .- [tempSTR, expC] |
| | 103 | else "set_args" .- [lit "(0b10)", expC] |
| | 104 | tellIns $ "invoke" .- [reg cc] |
| | 105 | tellLabel endL |
| | 106 | return (ExpLV this) |
| | 107 | trans (PCode styp params body) = do |
| | 108 | [begL, endL] <- genLabel ["blockBegin", "blockEnd"] |
| | 109 | this <- genPMC "block" |
| | 110 | tellIns $ "newsub" .- [reg this, bare ".Closure", bare begL] |
| | 111 | tellIns $ "goto" .- [bare endL] |
| | 112 | tellLabel begL |
| | 113 | let prms = map tpParam params |
| | 114 | mapM_ (tellIns . InsLocal RegPMC . prmToIdent) prms |
| | 115 | tellIns $ "get_params" .- sigList (map prmToSig prms) |
| | 116 | tellIns $ "new_pad" .- [lit curPad] |
| | 117 | wrapSub styp $ do |
| | 118 | mapM storeLex params |
| | 119 | trans body -- XXX - consistency check |
| | 120 | bodyC <- lastPMC |
| | 121 | tellIns $ "set_returns" .- retSigList [bodyC] |
| | 122 | tellIns $ "returncc" .- [] |
| | 123 | tellLabel endL |
| | 124 | return (ExpLV this) |
| | 125 | |
| | 126 | instance Translate PIL_Decl Decl where |
| | 127 | trans (PSub name styp params body) | Just (pkg, name') <- isQualified name = do |
| | 128 | declC <- trans $ PSub name' styp params body |
| | 129 | return $ DeclNS pkg [declC] |
| | 130 | trans (PSub name styp params body) = do |
| | 131 | (_, stmts) <- listen $ do |
| | 132 | let prms = map tpParam params |
| | 133 | mapM_ (tellIns . InsLocal RegPMC . prmToIdent) prms |
| | 134 | tellIns $ "get_params" .- sigList (map prmToSig prms) |
| | 135 | tellIns $ "new_pad" .- [lit curPad] |
| | 136 | wrapSub styp $ do |
| | 137 | mapM storeLex params |
| | 138 | trans body |
| | 139 | bodyC <- lastPMC |
| | 140 | tellIns $ "set_returns" .- retSigList [bodyC] |
| | 141 | tellIns $ "returncc" .- [] |
| | 142 | return (DeclSub name [] stmts) |
| | 143 | |
| | 144 | instance Translate PIL_Literal Literal where |
| 145 | | trans (PPad SMy pad exps) = do |
| 146 | | valsC <- mapM trans (map snd pad) |
| 147 | | pass $ do |
| 148 | | expsC <- trans exps |
| 149 | | return ([], (StmtPad (map fst pad `zip` valsC) expsC:)) |
| 150 | | trans (PExp exp) = fmap ExpLV $ trans exp |
| 151 | | trans (PCode styp params body) = do |
| 152 | | [begL, endL] <- genLabel ["blockBegin", "blockEnd"] |
| 153 | | this <- genPMC "block" |
| 154 | | tellIns $ "newsub" .- [reg this, bare ".Closure", bare begL] |
| 155 | | tellIns $ "goto" .- [bare endL] |
| 156 | | tellLabel begL |
| 157 | | let prms = map tpParam params |
| 158 | | mapM_ (tellIns . InsLocal RegPMC . prmToIdent) prms |
| 159 | | tellIns $ "get_params" .- sigList (map prmToSig prms) |
| 160 | | tellIns $ "new_pad" .- [lit curPad] |
| 161 | | wrapSub styp $ do |
| 162 | | mapM storeLex params |
| 163 | | trans body -- XXX - consistency check |
| 164 | | bodyC <- lastPMC |
| 165 | | tellIns $ "set_returns" .- retSigList [bodyC] |
| 166 | | tellIns $ "returncc" .- [] |
| 167 | | tellLabel endL |
| 168 | | return (ExpLV this) |
| 169 | | trans (PThunk exp) = do |
| 170 | | [begL, sndL, retL, endL] <- genLabel ["thunkBegin", "thunkAgain", "thunkReturn", "thunkEnd"] |
| 171 | | this <- genPMC "block" |
| 172 | | tellIns $ "newsub" .- [reg this, bare ".Continuation", bare begL] |
| 173 | | tellIns $ "goto" .- [bare endL] |
| 174 | | tellLabel begL |
| 175 | | cc <- genPMC "cc" |
| 176 | | fetchCC cc (reg this) |
| 177 | | expC <- trans exp |
| 178 | | tellIns $ "set_addr" .- [reg this, bare sndL] |
| 179 | | tellIns $ "goto" .- [bare retL] |
| 180 | | tellLabel sndL |
| 181 | | fetchCC cc (reg this) |
| 182 | | tellLabel retL |
| 183 | | tellIns $ if parrotBrokenXXX |
| 184 | | then "store_global" .- [tempSTR, expC] |
| 185 | | else "set_args" .- [lit "(0b10)", expC] |
| 186 | | tellIns $ "invoke" .- [reg cc] |
| 187 | | tellLabel endL |
| 188 | | return (ExpLV this) |
| 189 | | trans (PRawName name) = fmap ExpLV $ genName name |
| 190 | | trans (PSub name styp params body) | Just (pkg, name') <- isQualified name = do |
| 191 | | declC <- trans $ PSub name' styp params body |
| 192 | | return $ DeclNS pkg [declC] |
| 193 | | trans (PSub name styp params body) = do |
| 194 | | (_, stmts) <- listen $ do |
| 195 | | let prms = map tpParam params |
| 196 | | mapM_ (tellIns . InsLocal RegPMC . prmToIdent) prms |
| 197 | | tellIns $ "get_params" .- sigList (map prmToSig prms) |
| 198 | | tellIns $ "new_pad" .- [lit curPad] |
| 199 | | wrapSub styp $ do |
| 200 | | mapM storeLex params |
| 201 | | trans body |
| 202 | | bodyC <- lastPMC |
| 203 | | tellIns $ "set_returns" .- retSigList [bodyC] |
| 204 | | tellIns $ "returncc" .- [] |
| 205 | | return (DeclSub name [] stmts) |