cabal sandbox
cabal-install
packages:
- HsParrot/
- HsPerl5/
- HsSyck/
- MetaObject/
- Pugs/
- pugs-compat/
- pugs-DrIFT/
extra-deps:
- FindBin-0.0.5
- control-timeout-0.1.2
- stringtable-atom-0.0.7
resolver: lts-2.20
Install stack
and libperl-dev
, libtinfo-dev
, then:
$ git clone git@github.com:perl6/Pugs.hs.git
$ cd Pugs.hs
$ stack build --install-ghc
$ stack exec -- pugs
A popular Perl6 benchmark:
% time pugs -e 'my $i=0; for (1..5_000) { $i++ }; say $i'
5000
pugs 0.23s user 0.01s system 98% cpu 0.239 total
Eval
monadnewtype Eval a = EvalT ContT (EvalResult Val) (ReaderT Env SIO) (EvalResult a)
data EvalResult a
= RNormal !a
| RException !Val
newtype Eval a = EvalT ContT (EvalResult Val) (ReaderT Env SIO) (EvalResult a)
data EvalResult a
= RNormal !a
| RException !Val
Unrolled Monad.
newtype Eval a = Eval (Env -> (a -> SIO Val) -> (Val -> SIO Val) -> SIO Val)
newtype EvalResult a = RException Val
% time pugs -e 'my $i=0; for (1..5_000) { $i++ }; say $i'
5000
pugs 0.23s user 0.01s system 98% cpu 0.239 total
% time pugs-patched -e 'my $i=0; for (1..5_000) { $i++ }; say $i'
5000
pugs-patched 0.20s user 0.01s system 98% cpu 0.206 total
% time perl6 -e 'my $i=0; for (1..5_000) { $i++ }; say $i'
5000
perl6 0.22s user 0.03s system 98% cpu 0.259 total
% time pugs -e 'my $i=0; for (1..10_000) { $i++ }; say $i'
10000
pugs 0.40s user 0.01s system 99% cpu 0.416 total
% time pugs-patched -e 'my $i=0; for (1..10_000) { $i++ }; say $i'
10000
pugs-patched 0.36s user 0.01s system 99% cpu 0.368 total
% time perl6 -e 'my $i=0; for (1..10_000) { $i++ }; say $i'
10000
perl6 0.23s user 0.03s system 99% cpu 0.263 total
A reference implementations of Werl6
A reference implementations of Werl6
$ git clone git@github.com:hiratara/Pugs.hs.git
$ cd Pugs.hs
$ git checkout origin/wugs
$ stack build --install-ghc
$ stack exec -- wugs
% stack exec -- wugs
__ __ (W)erl 6
/ \ / \__ __ ____ ______ (U)ser's
\ \/\/ / | \/ ___\/ ___/ (G)olfing
\ /| | / /_/ >___ \ (S)ystem
\__/\ / |____/\___ /____ > Version: 6.2.13.dev
\/ /_____/ \/ Copyright 2005-2015, The Wugs Contributors
--------------------------------------------------------------------
Welcome to Wugs -- Werl6 User's Golfing System
Type :h for help.
Loading Prelude... done.
wugs> wwwWw 1 .. 80 -> $wW { WWwwWW wwWWWW > .5 ?? 'W' !! 'w' }; wWWWw
WWWwwWWWwWwwwWwWwWWWWwWWWwwwwwwWwwWwwWWWwWWwwwwWWWwWWwWwWWwwWWwwwWwWwwwWwwwWWwWw
Bool::True
Werl5
Wwwww wwww_wwww {
WWW $w_w = WWwWWW;
WWW $w_ww = WWwWWW;
wWW ($w_w >= $w_ww) {
wwWwWWw $w_w;
} WWwWW {
wwWwWWw $w_ww;
}
}
wwWwWww wwww_wwww(10,20),"\n";
Werl6 is more readable
Wwwww wwww_wwww (WWW $w_w, WWW $w_ww){
wWW ($w_w >= $w_ww) {
wwWwWWw $w_w;
} WWwWW {
wwWwWWw $w_ww;
}
}
wWWWw wwww_wwww(10,20);
The map of reserved words
+werl6perl6 :: [(String, String)]
+werl6perl6 =
+ [ ("w", "m")
+ , ("W", "q")
+ , ("ww", "s")
+ , ("wW", "x")
+ , ("Ww", "y")
+ , ("WW", "do")
+ , ("www", "eq")
+ , ("wwW", "ge")
+ , ("wWw", "gt")
+ , ("wWW", "if")
+ , ("Www", "lc")
+ , ("WwW", "le")
+ , ("WWw", "lt")
+ , ("WWW", "my")
Parse both Perl6 and Werl6 reserved words
symbol :: String -> RuleParser String
-symbol s = try $ do
+symbol s = case perl6ToWerl6 s of
+ Nothing -> symbol' s
+ Just w -> do ret <- symbol' s <|> symbol' w
+ return $ case werl6ToPerl6 ret of
+ Nothing -> ret
+ Just p -> p
-O
\(fun\) ☺