Changeset 14997 for src/Pugs/Prim.hs
- Timestamp:
- 01/05/07 11:01:29 (23 months ago)
- Files:
-
- 1 modified
-
src/Pugs/Prim.hs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim.hs
r14953 r14997 1106 1106 ys <- fromVals y 1107 1107 op1 "sort" . VList $ xs ++ ys 1108 op2 "IO::say" = op2Print hPutStrLn1109 op2 "IO::print" = op2Print hPutStr1108 op2 "IO::say" = op2Print True 1109 op2 "IO::print" = op2Print False 1110 1110 op2 "printf" = op3 "IO::printf" (VHandle stdout) 1111 1111 op2 "BUILDALL" = cascadeMethod reverse "BUILD" … … 1161 1161 asFractional = foldr (\d x -> (x / (base % 1)) + (d % 1)) (0 % 1) 1162 1162 1163 op2Print :: (Handle -> String -> IO ())-> Val -> Val -> Eval Val1164 op2Print fh v = do1163 op2Print :: Bool -> Val -> Val -> Eval Val 1164 op2Print newline h v = do 1165 1165 handle <- fromVal h 1166 1166 strs <- mapM fromVal =<< case v of … … 1168 1168 _ -> return [v] 1169 1169 guardIO $ do 1170 f handle . concatMap encodeUTF8 $ strs 1170 forM strs $ \str -> do 1171 forM (chunk 4096 str) $ \chunk -> do 1172 hPutStr handle chunk 1173 when newline (hPutStr handle "\n") 1171 1174 return $ VBool True 1175 where 1176 chunk :: Int -> [a] -> [[a]] 1177 chunk _ [] = [] 1178 chunk size xs = case splitAt size xs of (xs', xs'') -> xs' : chunk size xs'' 1172 1179 1173 1180 op2Split :: Val -> Val -> Eval Val … … 1352 1359 op3 "IO::printf" = \x y z -> do 1353 1360 rv <- evalExp $ App (_Var "&sprintf") Nothing [Val y, Val z] 1354 op2Print hPutStrx rv1361 op2Print False x rv 1355 1362 op3 other = \_ _ _ -> fail ("Unimplemented 3-ary op: " ++ other) 1356 1363
