Changeset 7843

Show
Ignore:
Timestamp:
11/05/05 11:41:57 (3 years ago)
Author:
autrijus
Message:

[Massive backport from svn.perl.org now openfoundry is back]

* theorbtwo notes that FIRST {} blocks did not

desugar into anything that passes PIL compilation,
as it's useing a Stmt in LValue position.
Fixed by desugaring using ternary if.

* Squash an empty import warning for precompiled preludes.

* Support for "./pugs -C PIL2".

Currently, "-C PIL" and "-C PIL1" both maps to PIL1,
but some day "-C PIL" may change to PIL2.

* Repo copy Pugs.CodeGen?.PIL to Pugs.CodeGen?.PIL2
* Also rename CodeGen?.PIL to CodeGen?.PIL1

* Add DrIFT-generated source of PIL2.hs.

* Repo copy PIL1 to PIL2 for the long-much-overdue PIL2

refactoring. The goals are:

  • Compile time object serialization
  • Lexical hoisting
  • Static creation of Code objects with scope (no PSub forms)
  • Full Cxt information
  • PIL2 is *after* type erasure -- *no* static type annotation should be left after that -- it's somewhere between F<: and ANF, so to speak.

* Adds support for "./pugs -BPugs -e ...", which just takes

-CPugs output and feed to the "runghc" executable in PATH.

* pugscc: chase the s/MainCC.mainCC/Main.main/ change

as the now-cabalized Pugs package no longer exports "main".

* Compile-time objects now survives "./pugs -CPugs" compilation.

This means the line below works now:

pugscc -e 'class F {}; my $x ::= F.new; say $x'

Previously, the ::= would prevent compilation because we
did not have a serialization protocol for VObject types.
(This work is going to be carried over to PIL.)

Files:
5 added
1 removed
9 modified

Legend:

Unmodified
Added
Removed
  • Pugs.cabal.in

    r7579 r7843  
    1212author: Autrijus Tang <autrijus@autrijus.org> 
    1313tested-with: GHC -any 
    14 exposed-modules: Pugs Pugs.AST Pugs.AST.Internals Pugs.AST.Pad Pugs.AST.Pos Pugs.AST.Prag Pugs.AST.SIO Pugs.AST.Scope Pugs.Bind Pugs.CodeGen Pugs.CodeGen.Binary Pugs.CodeGen.JSON Pugs.CodeGen.PIL Pugs.CodeGen.PIR Pugs.CodeGen.PIR.Prelude Pugs.CodeGen.Perl5 Pugs.Compat Pugs.Compile Pugs.Compile.Haskell Pugs.Compile.Pugs Pugs.Config Pugs.Cont Pugs.Embed Pugs.Embed.Haskell Pugs.Embed.Parrot Pugs.Embed.Perl5 Pugs.Eval Pugs.Eval.Var Pugs.External Pugs.External.Haskell Pugs.Help Pugs.Internals Pugs.Junc Pugs.Lexer Pugs.Monads Pugs.PIL1 Pugs.Parser Pugs.Parser.Number Pugs.Parser.Program Pugs.Parser.Types Pugs.Parser.Unsafe Pugs.Pretty Pugs.Prim Pugs.Prim.Code Pugs.Prim.Eval Pugs.Prim.FileTest Pugs.Prim.Keyed Pugs.Prim.Lifts Pugs.Prim.List Pugs.Prim.Match Pugs.Prim.Numeric Pugs.Prim.Param Pugs.Prim.Yaml Pugs.Rule Pugs.Rule.Char Pugs.Rule.Combinator Pugs.Rule.Error Pugs.Rule.Expr Pugs.Rule.Language Pugs.Rule.Pos Pugs.Rule.Prim Pugs.Rule.Token Pugs.Run Pugs.Run.Args Pugs.Run.Perl5 Pugs.Shell Pugs.Types Pugs.Version Emit.Common Emit.PIR  
     14exposed-modules: Pugs Pugs.AST Pugs.AST.Internals Pugs.AST.Pad Pugs.AST.Pos Pugs.AST.Prag Pugs.AST.SIO Pugs.AST.Scope Pugs.Bind Pugs.CodeGen Pugs.CodeGen.Binary Pugs.CodeGen.JSON Pugs.CodeGen.PIL1 Pugs.CodeGen.PIL2 Pugs.CodeGen.PIR Pugs.CodeGen.PIR.Prelude Pugs.CodeGen.Perl5 Pugs.Compat Pugs.Compile Pugs.Compile.Haskell Pugs.Compile.Pugs Pugs.Config Pugs.Cont Pugs.Embed Pugs.Embed.Haskell Pugs.Embed.Parrot Pugs.Embed.Perl5 Pugs.Embed.Pugs Pugs.Eval Pugs.Eval.Var Pugs.External Pugs.External.Haskell Pugs.Help Pugs.Internals Pugs.Junc Pugs.Lexer Pugs.Monads Pugs.PIL1 Pugs.PIL2 Pugs.Parser Pugs.Parser.Number Pugs.Parser.Program Pugs.Parser.Types Pugs.Parser.Unsafe Pugs.Pretty Pugs.Prim Pugs.Prim.Code Pugs.Prim.Eval Pugs.Prim.FileTest Pugs.Prim.Keyed Pugs.Prim.Lifts Pugs.Prim.List Pugs.Prim.Match Pugs.Prim.Numeric Pugs.Prim.Param Pugs.Prim.Yaml Pugs.Rule Pugs.Rule.Char Pugs.Rule.Combinator Pugs.Rule.Error Pugs.Rule.Expr Pugs.Rule.Language Pugs.Rule.Pos Pugs.Rule.Prim Pugs.Rule.Token Pugs.Run Pugs.Run.Args Pugs.Run.Perl5 Pugs.Shell Pugs.Types Pugs.Version Emit.Common Emit.PIR  
    1515buildable: True 
    1616c-sources: src/cbits/fpstring.c src/pcre/pcre.c __UNICODE_C__ 
  • docs/AES/S22draft.pod

    r7842 r7843  
    99Jos Boumans <kane@cpan.org> 
    1010Autrijus Tang <autrijus@autrijus.org> 
    11 Florian Ragwitz <rafl@debian.org> 
    1211 
    1312=head1 VERSION 
     
    2423 
    2524'package management means several things': 
    26     - metadata collection                           (1) perl6-thingy or maybe debtags? 
     25    - metadata collection                           (1) perl6-thingy 
    2726    - package building                              (2) make dist 
    2827        - intermediate format for transport 
     
    3029            - decomposed to hooks and probes 
    3130        - uploading package to central area         (3) CPAN 
    32         - indexing                                  (4) apt-ftparchive 
    33                     - I don't think apt-ftparchive is enough here. I think we'll need to set up 
    34                           or even wright something like dak, the Debian archive maintaince scripts 
    35                           packages.debian.org/dak 
    36         - understanding/querying index              (5) apt-cache, debtags 
     31        - indexing                                  (4) aptftp-archive 
     32        - understanding/querying index              (5) apt-cache 
    3733        - fetching package 
    3834        - building final package                    (6) dpkg-deb 
     
    116112 
    117113=head3 Repositories 
    118  
    119 My ideas for the repository layout look like this. It's modeled after the 
    120 Debian archive structure. 
    121  
    122  / 
    123  |- dists/                  This directory only contains so called Packages files. 
    124  |  |                       They know some meta-information about the packages (description, ...) 
    125  |  |                       and a path to the real package inside pool/. Using this Packages 
    126  |  |                       files modules can be categorized very well. There are more then the 
    127  |  |                       showed categories possible, of course. It's only an example. 
    128  |  | 
    129  |  |- authors/             The whole archive sorted by authors 
    130  |  |  |- stevan.gz         Stevan's modules 
    131  |  |  |- autrijus.gz       All of autrijus modules 
    132  |  |  |- autrijus/ 
    133  |  |  |  |- Perl6-Pugs.gz  Individual modules 
    134  |  |  |  `- Acme-Hello.gz 
    135  |  |  `- rafl.gz           rafl's modules. 
    136  |  | 
    137  |  |- languages/           The archive sorted by language 
    138  |  |  |- perl.gz           All available perl modules 
    139  |  |  |- perl/ 
    140  |  |  |  |- kane.gz        kane's modules 
    141  |  |  |  `- gbarr.gz       gbarr's modules 
    142  |  |  |- js.gz             All js modules 
    143  |  |  |- js/ 
    144  |  |  |- ruby.gz 
    145  |  |  `- ruby/             Ruby stuff 
    146  |  | 
    147  |  `- modules/             Categorized by modules 
    148  |     |- DBI/ 
    149  |     |  |- timb.gz        Tim's DBI 
    150  |     |  `- rafl.gz        My DBI 
    151  |     |- Net-SMTP/ 
    152  |     `- Net-IMCP/ 
    153  | 
    154  `- pool/                       The real modules are stored here. The Packages files point here. 
    155     |- a/                       Modules startihg with 'a' 
    156     |  |- Acme-Foo/             All Acme-Foo versions 
    157     |  |  |- Acme-Foo-0.1.deb   Packages for specific Acme-Foo versions 
    158     |  |  `- Acme-Foo-0.2.deb 
    159     |  |- Acme-Bar/ 
    160     |  `- Acme-Hello/ 
    161     |- b/ 
    162     |- c/ 
    163     |- ./ 
    164     |- ./ 
    165     |- ./ 
    166     |- y/ 
    167     `- z/ 
    168114 
    169115=head3 Probing 
     
    261207            - without which we can't possibly roll this out 
    262208 
    263 rafl thinks: 
    264 - dpkg seems to be not the optimal choice 
    265     - maybe only adopt the package and metadata format from the .deb format version 2 
    266           and write the tools to manipulate and install it ourself. Preferably in Perl 6. 
    267         - I fear that tools like dpkg/apt/.. aren't portable as we need it because they 
    268           were mainly written for use with a single Linux distribution. 
    269         - The Debian tools can be useful as a provisional solutions until we wrote 
    270           something own or as a reference implementation. 
    271  
    272209=head2 Policy File 
    273210 
  • script/pugscc

    r7830 r7843  
    9191    my $rv = system( 
    9292        $ghc_exe, 
    93         "-v0", "-o", $out, "--make", "-main-is", "MainCC.mainCC", 
    94         "$base/MainCC.hs" 
     93        "-v0", "-O", "-o", $out, "--make", "$base/MainCC.hs" 
    9594    ); 
    9695 
  • src/Pugs/CodeGen.hs

    r7127 r7843  
    1313import Pugs.AST 
    1414import Pugs.Internals 
    15 import Pugs.CodeGen.PIL (genPIL) 
     15import Pugs.CodeGen.PIL1 (genPIL1) 
     16import Pugs.CodeGen.PIL2 (genPIL2) 
    1617import Pugs.CodeGen.PIR (genPIR) 
    1718import Pugs.CodeGen.Perl5 (genPerl5) 
     
    2021import Pugs.Compile.Pugs (genPugs) 
    2122import Pugs.Compile.Haskell (genGHC) 
    22 -- import Pugs.CodeGen.PIL2 (genPIL2) 
    2323-- import Pugs.CodeGen.XML (genXML) 
    2424import qualified Data.Map as Map 
     
    3131    , ("Parrot",      genPIR) 
    3232    , ("PIR",         genPIR) 
    33     , ("PIL",         genPIL) 
    34 --  , ("PIL2",        genPIL2) 
     33    , ("PIL1",        genPIL1) 
     34    , ("PIL2",        genPIL2) 
    3535    , ("Perl5",       genPerl5) 
    3636    , ("Pugs",        genPugs) 
     
    4949    norm' "parrot" = "Parrot" 
    5050    norm' "pir"    = "PIR" 
    51     norm' "pil"    = "PIL" 
    52     -- norm' "pil2"   = "PIL2" 
     51    norm' "pil"    = "PIL1" -- XXX - this will change 
     52    norm' "pil1"   = "PIL1" 
     53    norm' "pil2"   = "PIL2" 
    5354    norm' "perl5"  = "Perl5" 
    5455    norm' "pugs"   = "Pugs" 
  • src/Pugs/Compile/Pugs.hs

    r5360 r7843  
    1 {-# OPTIONS_GHC -cpp -fglasgow-exts -fth #-} 
     1{-# OPTIONS_GHC -cpp -fglasgow-exts #-} 
    22 
    33#include "../pugs_config.h" 
     
    88import Pugs.Internals 
    99import Text.PrettyPrint 
     10import qualified Data.Map as Map 
    1011 
    1112class (Show x) => Compile x where 
     
    2526 
    2627prettyDo :: [Doc] -> Doc 
    27 prettyDo docs = parens $ sep (text "do":punctuate semi docs) 
     28prettyDo docs = parens $ text "do" <+> braces (sep $ punctuate semi docs) 
    2829 
    2930prettyRecord :: String -> [(String, Doc)] -> Doc 
     
    3233 
    3334prettyBind :: String -> Doc -> Doc 
    34 prettyBind var doc = text var `sep1` nest 1 (text "<-" <+> doc) 
    35  
     35prettyBind var doc = text var <+> text "<-" <+> doc 
    3636 
    3737instance Compile (Maybe Exp) where 
     
    127127                ] 
    128128 
    129 instance Compile (TVar Bool) where 
    130     compile fresh = do 
    131         bool <- liftSTM $ readTVar fresh 
    132         return $ text "liftSTM" <+> parens (text "newTVar" <+> text (show bool)) 
    133  
    134 instance Compile (TVar VRef) where 
     129instance Compile Bool where 
     130    compile bool = return $ text "return" <+> parens (text $ show bool) 
     131 
     132instance Compile a => Compile (Map VStr a) where 
     133    compile map | Map.null map = return (text "return Map.empty") 
     134    compile map = error (show map)  
     135 
     136instance Compile (IVar VScalar) where 
     137    compile iv = do 
     138        val     <- readIVar iv 
     139        valC    <- compile val 
     140        return $ prettyDo 
     141            [ prettyBind "val" valC 
     142            , text "newScalar val" 
     143            ] 
     144 
     145instance (Typeable a, Compile a) => Compile (TVar a) where 
    135146    compile fresh = do 
    136147        vref    <- liftSTM $ readTVar fresh 
     
    169180            , text "return $ VCode code" 
    170181            ] 
     182    compile (VObject obj) = do 
     183        objC <- compile obj 
     184        return $ prettyDo 
     185            [ prettyBind "obj" objC 
     186            , text "return $ VObject obj" 
     187            ] 
    171188    compile x = return $ text "return" $+$ parens (text $ show x) 
    172189 
    173 -- We need a compile VObject! 
     190instance Compile VObject where 
     191    compile (MkObject typ attrs Nothing _) = do 
     192        attrsC <- compile attrs 
     193        let vobj = prettyRecord "MkObject" $ 
     194                [ ("objType",   text (show typ)) 
     195                , ("objAttrs",  text "attrs") 
     196                , ("objOpaque", text "Nothing") 
     197                , ("objId",     text "id") 
     198                ] 
     199        return $ prettyDo 
     200            [ prettyBind "attrs" attrsC 
     201            , prettyBind "id" (text "liftIO newUnique") 
     202            , text "return" <+> parens vobj 
     203            ] 
     204    compile obj = fail $ "Cannot compile Object of Dynamic type: " ++ show obj 
    174205 
    175206-- Haddock can't cope with Template Haskell 
     
    207238    expC    <- compile exp 
    208239    return . VStr . unlines $ 
    209         [ "{-# OPTIONS_GHC -fglasgow-exts -fno-warn-unused-imports -fno-warn-unused-binds -O #-}" 
    210         , "module MainCC where" 
     240        [ "{-# OPTIONS_GHC -fglasgow-exts -fno-warn-unused-imports -fno-warn-unused-binds #-}" 
     241        , "module Main where" 
    211242        , "import Pugs.Run" 
    212243        , "import Pugs.AST" 
    213244        , "import Pugs.Types" 
    214245        , "import Pugs.Internals" 
    215         , "" 
    216         , "mainCC = do" 
     246        , "import qualified Data.Map as Map" 
     247        , "" 
     248        , "main = do" 
    217249        , "    glob <- globC" 
    218250        , "    exp  <- expC" 
  • src/Pugs/Embed.hs

    r4655 r7843  
    1414    module Pugs.Embed.Haskell, 
    1515    module Pugs.Embed.Parrot, 
     16    module Pugs.Embed.Pugs, 
    1617    evalEmbedded 
    1718    -- module Pugs.Embed.Ponie, 
     
    2021import Pugs.Embed.Haskell 
    2122import Pugs.Embed.Parrot 
    22 -- import Pugs.Embed.Ponie 
     23import Pugs.Embed.Pugs 
    2324 
    2425evalEmbedded :: String -> String -> IO () 
     
    2627evalEmbedded "PIR" = evalParrot 
    2728evalEmbedded "Parrot" = evalParrot 
     29evalEmbedded "Pugs" = evalPugs 
    2830{- evalEmbedded "Haskell" code = do 
    2931    evalHaskell code 
  • src/Pugs/Parser.hs

    r7815 r7843  
    984984    --   state $?FIRST_RESULT; 
    985985    --   state $?FIRST_RUN; 
    986     --   $?FIRST_RUN || { $?FIRST_RUN++; $?FIRST_RESULT = { 42 }() }; 
    987     --   $?FIRST_RESULT; 
     986    --   $?FIRST_RUN++ ?? $?FIRST_RESULT !! $?FIRST_RESULT = { 42 }(); 
    988987    -- } 
    989988    -- These are the two state variables we need. 
     
    994993    return $ Syn "block"        -- The outer block 
    995994        [ Pad SState lexDiff $  -- state ($?FIRST_RESULT, $?FIRST_RUN); 
    996             Stmts (App (Var "&infix:||")    --  $?FIRST_RUN || 
    997                 Nothing 
    998                 [ Var "$?FIRST_RUN" 
    999                 , Stmts (App (Var "&postfix:++") Nothing [Var "$?FIRST_RUN"]) 
    1000                         (Syn "=" [Var "$?FIRST_RESULT", App (Val code) Nothing []]) 
    1001                 ])   --  { $?FIRST_RUN++; $?FIRST_RESULT = { 42 }() }; 
    1002             (Var "$?FIRST_RESULT") --  $?FIRST_RESULT; 
     995            Syn "if" 
     996                [ App (Var "&postfix:++") Nothing [Var "$?FIRST_RUN"] 
     997                , Var "$?FIRST_RESULT" 
     998                , Syn "=" [Var "$?FIRST_RESULT", App (Val code) Nothing []] 
     999                ]   --  { $?FIRST_RUN++; $?FIRST_RESULT = { 42 }() }; 
    10031000        ] 
    10041001 
  • src/Pugs/PreludePC.hs-null

    r7838 r7843  
    11{-# OPTIONS_GHC -fglasgow-exts -fno-full-laziness -fno-cse #-} 
     2 
     3import Pugs.Prim.Eval 
    24 
    35{- 
  • src/Pugs/Run.hs

    r7838 r7843  
    2626import Pugs.Eval 
    2727import Pugs.Prim 
    28 import Pugs.Prim.Eval 
    2928import Pugs.Embed 
    3029import Data.IORef