Changeset 4
- Timestamp:
- 02/06/05 20:01:10 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Files:
-
- 1 added
- 10 modified
-
ChangeLog (added)
-
MANIFEST (modified) (1 diff)
-
lib/Perl6/Pugs.pm (modified) (2 diffs)
-
src/AST.hs (modified) (1 diff)
-
src/Internals.hs (modified) (1 diff)
-
src/Lexer.hs (modified) (3 diffs)
-
src/Main.hs (modified) (4 diffs)
-
src/Parser.hs (modified) (3 diffs)
-
src/Pretty.hs (modified) (1 diff)
-
src/Prim.hs (modified) (2 diffs)
-
src/Shell.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
MANIFEST
r1 r4 9 9 inc/Module/Install/WriteAll.pm 10 10 lib/Perl6/Pugs.pm 11 lib/Perl6/Pugs/00Apocrypha.pod 12 lib/Perl6/Pugs/01Parsing.pod 11 ChangeLog 13 12 Makefile.PL 14 13 MANIFEST This list of files -
lib/Perl6/Pugs.pm
r1 r4 8 8 Perl6::Pugs - Perl6 User's Golfing System 9 9 10 =head1 VERSION 11 12 This document describes version 6.0.0 of Pugs, released February 7, 2005. 13 10 14 =head1 SYNOPSIS 11 15 … … 15 19 =head1 DESCRIPTION 16 20 17 Pugs is an interpreter for Perl6. 21 Started at 2005-02-01, Pugs is an attempt at writing a Perl6 interpreter in 22 Haskell. Currently it is in its very early stages. 23 24 Although Pugs does not yet directly relate to PGE or Parrot, the hope is that 25 it can flesh out corner cases in the Synopses during implementation, as well 26 as contributing more test cases to the main Perl6 project. 27 28 =head2 Featherweight Perl6 29 30 Featherweight Perl6 (FP6) is a simplified, side-effect-free subset of the 31 Perl6 language, inspired by I<Featherweight Java>. It is the first-step 32 target language of Pugs. 33 34 Notable features in Perl6 that are I<not> in FP6: 35 36 =over 4 37 38 =item * Assignments and mutable variables. 39 40 =item * Grammar, Rules and Macros. 41 42 =item * Unboxed types. 43 44 =item * Run-time applications of "but" and "does". 45 46 =item * I/O primitives. 47 48 =item * Perl5 Compatibility Mode. 49 50 =item * Non-ascii symbols: E<171>, E<187> and E<165>. 51 52 =back 53 54 The only ways to do I/O in FP6 are: 55 56 =over 4 57 58 =item * C<@*ARGS>, C<$*PID>, C<$*PROGRAM_NAME>, etc.. 59 60 =item * C<< <> >> (lazily-evaluated lines of input) 61 62 =item * The toplevel evaluation result is printed under flattened list context with items stringified. 63 64 =back 65 66 =head2 Release Plans 67 68 The major/minor version numbers of Pugs converges to 2*pi; each significant 69 digit in the minor version represents a milestone. The third digit is 70 incremented for each release. 71 72 The current milestones are: 73 74 =over 4 75 76 =item 6.0: Initial release. 77 78 =item 6.2: Implement FP6, without user-defined subtypes. 79 80 =item 6.28: Full FP6, with classes and traits. 81 82 =item 6.283: Assignment and I/O primitives. 83 84 =item 6.2831: Role composition and other runtime features. 85 86 =item 6.28318: Rules and Grammars. 87 88 =item 6.283185: Macros; full Perl6 bootstrapping. 89 90 =back 18 91 19 92 =head1 SEE ALSO -
src/AST.hs
r1 r4 13 13 14 14 module AST where 15 import Data.List 16 import Data.Word 17 import Data.Char 18 import Data.Ratio 19 import Data.Complex 20 import Data.FiniteMap 21 import Text.ParserCombinators.Parsec.Pos 15 import Internals 22 16 23 17 type Ident = String -
src/Internals.hs
r1 r4 14 14 -} 15 15 16 module Internals ( 17 module System.Environment, 18 module System.IO, 19 module Data.Bits, 20 module Data.List, 21 module Data.Word, 22 module Data.Char, 23 module Data.Maybe, 24 module Data.Ratio, 25 module Data.Complex, 26 module Data.FiniteMap, 27 module Debug.Trace, 28 module Text.ParserCombinators.Parsec, 29 module Text.ParserCombinators.Parsec.Expr, 30 module Text.ParserCombinators.Parsec.Language, 31 ) where 32 33 import System.Environment 34 import System.IO hiding (try) 35 import qualified System.IO (try) 36 import Data.Bits 37 import Data.Maybe 38 import Data.Ratio 39 import Data.List 40 import Data.Word 41 import Data.Char 42 import Data.Ratio 43 import Data.Complex 44 import Data.FiniteMap 45 import Debug.Trace 46 import Text.ParserCombinators.Parsec 47 import Text.ParserCombinators.Parsec.Expr 48 import Text.ParserCombinators.Parsec.Language -
src/Lexer.hs
r3 r4 11 11 12 12 module Lexer where 13 import Data.Char 14 import Debug.Trace 15 import Text.ParserCombinators.Parsec 16 import Text.ParserCombinators.Parsec.Expr 17 import Text.ParserCombinators.Parsec.Pos 13 import Internals 18 14 import qualified Text.ParserCombinators.Parsec.Token as P 19 import Text.ParserCombinators.Parsec.Language20 15 21 16 perl6Def = javaStyle … … 89 84 90 85 fraction = do{ char '.' 91 ; digits <- many 1digit <?> "fraction"86 ; digits <- many digit <?> "fraction" 92 87 ; return (foldr op 0.0 digits) 93 88 } … … 149 144 150 145 quotedQuote = do 151 string "\\'"152 return '\''146 char '\\' 147 anyChar 153 148 -
src/Main.hs
r1 r4 15 15 16 16 module Main where 17 import IO 18 import System 17 import Internals 19 18 20 19 import AST … … 32 31 run (('-':'e':str@(_:_)):args) = doRun str args 33 32 run ("-e":str:args) = doRun str args 33 run ("-h":_) = printHelp 34 34 run (file:args) = readFile file >>= (`doRun` args) 35 35 run [] = do 36 36 hSetBuffering stdout NoBuffering 37 banner 38 repLoop () 37 isTTY <- hIsTerminalDevice stdin 38 if isTTY 39 then banner >> repLoop () 40 else do 41 str <- getContents 42 doRun str [] 39 43 40 44 repLoop :: State -> IO () … … 45 49 Load fn -> load fn 46 50 Eval str -> doEval str [] >> repLoop initState 47 Parse str-> parse str >> repLoop initState51 Parse str-> doParse str >> repLoop initState 48 52 Help -> printHelp >> repLoop state 49 53 … … 51 55 return () 52 56 53 parse str = runLex print parseOp str57 doParse str = runLex print parseOp str 54 58 55 59 eval str = doEval str [] -
src/Parser.hs
r1 r4 11 11 12 12 module Parser where 13 import Internals 13 14 import AST 14 15 import Lexer 15 import Text.ParserCombinators.Parsec16 import Text.ParserCombinators.Parsec.Expr17 16 18 17 type StateParser a = GenParser Char () a … … 37 36 , ternOps [("??", "::")] -- Ternary 38 37 , leftOps " = := ::= += **= xx= " -- Assignment 38 -- XXX rewrite chained Ops using sepBy! 39 39 , rightOps " , " -- List Item Separator 40 40 , preOps primitiveListFunctions -- List Operator … … 71 71 parseTerm = parens parseOp 72 72 <|> parseLit 73 <|> nonTerm73 -- <|> nonTerm 74 74 <?> "term" 75 75 -
src/Pretty.hs
r1 r4 13 13 14 14 module Pretty where 15 import Internals 15 16 import AST 16 import Data.List17 import Data.Ratio18 17 19 18 class (Show a) => Pretty a where -
src/Prim.hs
r1 r4 13 13 14 14 module Prim where 15 import Internals 15 16 import AST 16 import Data.Char17 import Data.Bits18 import Data.Word19 import Data.List20 import Data.Maybe21 import Data.Ratio22 17 23 18 op1 :: Ident -> (forall a. Context a => a) -> Val 24 op1 "!" = VBool . not 19 op1 "!" = \x -> case op1 "?" x of 20 VBool True -> VBool False 21 VBool False -> VBool True 25 22 op1 "+" = op1Numeric id 26 23 op1 "-" = op1Numeric negate … … 154 151 op1Numeric f VUndef = VInt $ f 0 155 152 op1Numeric f (VInt x) = VInt $ f x 153 op1Numeric f (VList l) = VInt $ f $ genericLength l 156 154 op1Numeric f x = VNum $ f (vCast x) 157 155 -
src/Shell.hs
r1 r4 1 {-# OPTIONS -cpp #-} 1 {-# OPTIONS -fglasgow-exts -cpp #-} 2 3 {- 4 Interactive shell. 5 6 There is an inn, a merry old inn, 7 beneath an old grey hill, 8 And there they brew a beer so brown 9 That the Man in the Moon himself came down 10 one night to drink his fill... 11 -} 12 13 module Shell where 14 import Internals 15 import AST 16 2 17 #define READLINE 1 3 18 #include "config.h" 4 19 5 {-------------------------------------------------------------------------------6 7 Copyright: Bernie Pope 20048 9 Module: Shell10 11 Description: The Baskell interpreter command line.12 13 Primary Authors: Bernie Pope14 15 Notes:16 17 Will use GNU readline if it is available.18 19 -------------------------------------------------------------------------------}20 21 module Shell22 ( Command (..)23 , getCommand24 , initializeShell25 )26 where27 28 import AST29 import Char30 20 #ifdef READLINE 31 21 import qualified System.Console.Readline as Readline 32 ( readline33 , addHistory34 , initialize35 )36 22 #endif 37 38 --------------------------------------------------------------------------------39 23 40 24 data Command … … 46 30 | Type Exp 47 31 | Help 48 #ifdef DEBUG49 | ShowAST50 | ShowDepend51 #endif52 32 53 33 -- read some input from the user 54 34 -- parse the input and return the corresponding command 55 35 getCommand :: IO Command 56 getCommand 57 = do input <- readline "pugs> " 58 case input of 59 Nothing -> return Quit 60 Just line 61 -> if all isSpace line 62 then getCommand 63 else do 64 addHistory line 65 return $ parseCommandLine line 36 getCommand = do 37 input <- readline "pugs> " 38 doCommand input 39 40 doCommand Nothing = return Quit 41 doCommand (Just line) 42 | all isSpace line = getCommand 43 | (s, _) <- break (== '#') line 44 , all isSpace s = getCommand 45 | otherwise = do 46 addHistory line 47 return $ parseCommandLine line 66 48 67 49 parseCommandLine :: String -> Command … … 70 52 parseCommandLine (':':'q':_) = Quit 71 53 parseCommandLine (':':'h':_) = Help 72 parseCommandLine (':':'b':_) = Browse73 parseCommandLine (':':'l':str) = Load . unwords . tail $ words str54 -- parseCommandLine (':':'b':_) = Browse 55 -- parseCommandLine (':':'l':str) = Load . unwords . tail $ words str 74 56 parseCommandLine str = Eval str 75 76 --------------------------------------------------------------------------------77 78 -- optional support for GNU Readline79 57 80 58 initializeShell :: IO ()
