Changeset 7190

Show
Ignore:
Timestamp:
09/28/05 23:08:26 (3 years ago)
Author:
autrijus
Message:

r7196@not: autrijus | 2005-09-28 11:04:59 +0300


r7197@not: autrijus | 2005-09-28 11:28:35 +0300

  • beginning of the main pugs cabal file r7198@not: autrijus | 2005-09-28 12:36:41 +0300
  • some more metadata for Pugs.cabal. r7211@not: autrijus | 2005-09-28 21:27:14 +0300
  • releng: normalize and todoize tests. r7221@not: autrijus | 2005-09-29 00:05:29 +0300
  • Remove the unreferenced Pugs.AST.Types.
  • Move the ill-named Pugs.Context back inside Pugs.Types.
  • Reuse its Tolkien quote for the underquoted Pugs.Version.
Files:
1 added
3 removed
17 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/AST/Internals.hs

    r7076 r7190  
    7272) where 
    7373import Pugs.Internals 
    74 import Pugs.Context 
    7574import Pugs.Types 
    7675import Pugs.Cont hiding (shiftT, resetT) 
  • src/Pugs/Eval.hs

    r7135 r7190  
    3535import Pugs.Prim 
    3636import Pugs.Prim.List (op0Zip) 
    37 import Pugs.Context 
    3837import Pugs.Monads 
    3938import Pugs.Pretty 
  • src/Pugs/Eval/Var.hs

    r6672 r7190  
    1616import Pugs.Prim.List (op2Fold, op1HyperPrefix, op1HyperPostfix, op2Hyper) 
    1717import Pugs.Prim.Param (foldParam) 
    18 import Pugs.Context 
    1918import Pugs.Pretty 
    2019import Pugs.Config 
  • src/Pugs/Monads.hs

    r7035 r7190  
    2525import Pugs.Internals 
    2626import Pugs.AST 
    27 import Pugs.Context 
    2827import Pugs.Types 
    2928import Control.Monad.RWS 
  • src/Pugs/Parser.hs

    r7142 r7190  
    2323import Pugs.AST 
    2424import Pugs.Types 
    25 import Pugs.Context 
    2625import Pugs.Version (versnum) 
    2726import Pugs.Lexer 
  • src/Pugs/Run.hs

    r6552 r7190  
    2222import Pugs.Internals 
    2323import Pugs.Config 
    24 import Pugs.Context 
    2524import Pugs.AST 
    2625import Pugs.Types 
  • src/Pugs/Types.hs

    r6826 r7190  
    1212 
    1313module Pugs.Types ( 
    14     Type(..), mkType, anyType, showType, 
    15     ClassTree, 
     14    Type(..), mkType, anyType, showType, isaType, isaType', deltaType, 
     15    ClassTree, initTree, addNode, 
    1616 
    1717    Cxt(..),  
     
    169169    show _ = "<tmvar>" 
    170170 
     171{-| 
     172Count the total number of types in a class tree, including both internal and 
     173leaf nodes. 
     174 
     175This is used by 'deltaType' to ensure that incompatible types are always 
     176further apart than compatible types. 
     177-} 
     178countTree :: ClassTree -> Int 
     179countTree (Node _ []) = 1 
     180countTree (Node _ cs) = 1 + sum (map countTree cs) 
     181 
     182{-| 
     183Find the \'difference\' between two types in the given class tree (for MMD 
     184purposes and such). 
     185 
     186Identical types (that exist in the class tree) produce 0. Compatible types 
     187will produce a small positive number representing their distance. 
     188Incompatible will produce a distance larger 
     189than any two compatible types. If one (or both) of the types doesn't exist in 
     190the tree, the result is a very large number. 
     191 
     192> <scook0> is deltaType supposed to be returning large positive numbers for  
     193>            types that are actually incompatible? 
     194> <autrijus> that is a open design question. 
     195> <autrijus> it is that way because we want 
     196> <autrijus> '1'+'2' 
     197> <autrijus> to work 
     198> <scook0> I see 
     199> <autrijus> without having to define <+> as Scalar Scalar 
     200> <autrijus> I think I did think of leaving a compatibleTypes as remedy 
     201> <autrijus> to specify things that are fundamentally uncastable 
     202> <scook0> I think I'll just document the current behaviour for now 
     203> <autrijus> nod. it is a mess. it really wants a rewrite. 
     204-} 
     205deltaType :: ClassTree -- ^ Class tree to use for the comparison 
     206          -> Type      -- ^ Base type 
     207          -> Type      -- ^ Possibly-derived type 
     208          -> Int 
     209deltaType = junctivate min max $ \tree base target -> 
     210    let distance = distanceType tree base target in 
     211    if distance < 0 
     212        then countTree tree - distance 
     213        else distance 
     214 
     215{-| 
     216Autothreading of comparisons between junctive types. 
     217 
     218Just as autothreading over value junctions will perform an operation on all 
     219junction elements and combine the results back into a junction, this function 
     220autothreads some type comparison over all the possible type permutations, 
     221then combines the results using two user-specified /functions/. 
     222 
     223E.g. if we want to check whether the type @(Int|Str)@ is a @Num@, we first 
     224check whether @Int@ is a @Num@ (@True@), then check whether @Str@ is a num 
     225(@False@), then combine the results using the specified disjunctive combiner 
     226(in this case Haskell's @(||)@). The result is thus @True@. 
     227-} 
     228junctivate :: (t -> t -> t) -- ^ Function to combine results over disjunctive  
     229                            --     (@|@) types 
     230           -> (t -> t -> t) -- ^ Function to combine results over conjunctive  
     231                            --     (@\&@) types 
     232           -> (ClassTree -> Type -> Type -> t) 
     233                            -- ^ Function that will actually perform the  
     234                            --     comparison (on non-junctive types) 
     235           -> ClassTree     -- ^ Class tree to pass to the comparison function 
     236           -> Type          -- ^ First type to compare 
     237           -> Type          -- ^ Second type to compare 
     238           -> t 
     239junctivate or and f tree base target 
     240    | TypeOr t1 t2 <- target 
     241    = redo base t1 `or` redo base t2 
     242    | TypeOr b1 b2 <- base 
     243    = redo b1 target `or` redo b2 target 
     244    | TypeAnd t1 t2 <- target 
     245    = redo base t1 `and` redo base t2 
     246    | TypeAnd b1 b2 <- base 
     247    = redo b1 target `and` redo b2 target 
     248    | otherwise 
     249    = f tree base target 
     250    where 
     251    redo = junctivate or and f tree 
     252 
     253-- When saying Int.isa(Scalar), Scalar is the base, Int is the target 
     254{-| 
     255A more convenient version of 'isaType\'' that automatically converts the base 
     256type string into an actual 'Type' value. 
     257-} 
     258isaType :: ClassTree -- ^ Class tree to use for the comparison 
     259        -> String    -- ^ Base type 
     260        -> Type      -- ^ Possibly-derived type 
     261        -> Bool 
     262isaType tree base target = isaType' tree (mkType base) target 
     263 
     264{-| 
     265Return true if the second type (the \'target\') is derived-from or equal-to the  
     266first type (the \'base\'), in the context of the given class tree. 
     267 
     268This function will autothread over junctive types. 
     269-} 
     270isaType' :: ClassTree -- ^ Class tree to use for the comparison 
     271         -> Type      -- ^ Base type 
     272         -> Type      -- ^ Possibly-derived type 
     273         -> Bool 
     274isaType' = junctivate (||) (&&) $ \tree base target -> 
     275    distanceType tree base target >= 0 
     276 
     277{-| 
     278Compute the \'distance\' between two types by applying 'findList' to each of 
     279them, and passing the resulting type chains to 'compareList'. 
     280 
     281See 'compareList' for further details. 
     282-} 
     283distanceType :: ClassTree -> Type -> Type -> Int 
     284distanceType tree base target = compareList l1 l2 
     285--  | not (castOk base target)  = 0 
     286--  | otherwise = compareList l1 l2 
     287    where 
     288    l1 = findList base tree 
     289    l2 = findList target tree 
     290 
     291{- 
     292-- | (This is currently unused...) 
     293castOk :: a -> b -> Bool 
     294castOk _ _ = True 
     295-} 
     296 
     297{-| 
     298Take two inheritance chains produced by 'findList', and determine how 
     299\'compatible\' the first one is with the second. 
     300 
     301Compatible types will produce a number indicating how distant they are. 
     302Incompatible types produce a negative number indicating how much the base type 
     303would need to be relaxed. If one (or both) types doesn't exist in the tree, a  
     304large negative number is produced 
     305 
     306E.g.: 
     307 
     308* comparing @Int@ and @Int@ will produce 0 
     309 
     310* comparing @Scalar@ and @String@ will produce 1 
     311 
     312* comparing @Num@ and @Scalar@ will produce -2 
     313 
     314* comparing @Blorple@ and @Method@ will produce -999 (or similar) 
     315-} 
     316compareList :: [Type] -- ^ Base type's chain 
     317            -> [Type] -- ^ Possibly-derived type's chain 
     318            -> Int 
     319compareList [] _ = -999 -- XXX hack (nonexistent base type?) 
     320compareList _ [] = -999 -- XXX hack (incompatible types) 
     321compareList l1 l2 
     322    | last l1 `elem` l2 =   length(l2 \\ l1) -- compatible types 
     323    | last l2 `elem` l1 = - length(l1 \\ l2) -- anti-compatible types 
     324    | otherwise = compareList l1 (init l2) 
     325 
     326{-| 
     327Produce the type \'inheritance\' chain leading from the base type (@Any@) to 
     328the given type. 
     329 
     330e.g. 
     331 
     332@ 
     333'findList' ('MkType' \"Num\") 'initTree' 
     334@ 
     335 
     336will produce the list of types 
     337 
     338@ 
     339Any, Void, Object, Scalar, Complex, Num 
     340@ 
     341 
     342This function does /not/ expect to be given junctive types. 
     343-} 
     344findList :: Type      -- ^ 'Type' to find the inheritance chain of 
     345         -> ClassTree -- ^ Class tree to look in 
     346         -> [Type] 
     347findList base (Node l cs) 
     348    | base == l                             = [l] 
     349    | Just ls <- find (not . null) found    = l:ls 
     350    | otherwise                             = [] 
     351    where 
     352    found :: [[Type]] 
     353    found = map (findList base) cs 
     354 
     355{- 
     356{-| 
     357Pretty-print the initial class tree, using @Tree@'s @drawTree@. 
     358 
     359(This seems to be a debugging aid, since it's not actually used anywhere.) 
     360-} 
     361prettyTypes :: String 
     362prettyTypes = drawTree $ fmap show initTree 
     363-} 
     364 
     365{-| 
     366Add a new \'top-level\' type to the class tree, under @Object@. 
     367-} 
     368addNode :: ClassTree -> Type -> ClassTree 
     369addNode (Node obj [Node any (Node item ns:rest), junc]) typ = 
     370    Node obj [Node any (Node item ((Node typ []):ns):rest), junc] 
     371addNode _ _ = error "malformed tree" 
     372 
     373{-| 
     374Default class tree, containing all built-in types. 
     375-} 
     376initTree :: ClassTree 
     377initTree = fmap MkType $ Node "Object" 
     378    [ Node "Any" 
     379        [ Node "Item" 
     380            [ Node "List" 
     381                [ Node "Lazy" 
     382                    [ Node "Array" 
     383                        [ Node "Array::Const" [] 
     384                        , Node "Array::Slice" [] 
     385                        ] 
     386                    , Node "Hash" 
     387                        [ Node "Hash::Const" [] 
     388                        , Node "Hash::Env" [] 
     389                        ] 
     390                    ] 
     391                , Node "Eager" [] 
     392                ] 
     393            , Node "Scalar" 
     394                [ Node "Complex" 
     395                    [ Node "Num" 
     396                        [ Node "Rat" 
     397                            [ Node "Int" 
     398                                [ Node "Bit" [] ] ] ] ] 
     399                , Node "Bool" [] 
     400                , Node "Str" [] 
     401                , Node "Ref" [] 
     402                , Node "IO" 
     403                    [ Node "IO::Dir" [] 
     404                    ] 
     405                , Node "Socket" [] 
     406                , Node "Thread" [] 
     407                , Node "Code" 
     408                    [ Node "Routine" 
     409                        [ Node "Sub" 
     410                            [ Node "Method" [] 
     411                            , Node "Submethod" []  -- why isn't this a node off Method? - mugwump 
     412                            ] 
     413                        , Node "Macro" [] ] 
     414                    , Node "Block" [] 
     415                    ] 
     416                , Node "Rul" [] 
     417                , Node "Pugs::Internals::VRule" [] 
     418                , Node "Match" [] 
     419                , Node "Scalar::Const" [] 
     420                , Node "Scalar::Proxy" [] 
     421                , Node "Scalar::Lazy" [] 
     422                , Node "Scalar::Perl5" [] 
     423                , Node "Proxy" [] 
     424                , Node "Control::Caller" [] 
     425                , Node "Time::Local" [] 
     426                , Node "Type" 
     427                    [ Node "Package" 
     428                        [ Node "Module" 
     429                            [ Node "Class" 
     430                                [ Node "Role" [] 
     431                                , Node "Grammar" [] 
     432                                ] ] ] ] 
     433                ] 
     434            ] 
     435        , Node "Pair" [] 
     436        ] 
     437    , Node "Junction" [] ] 
     438 
  • src/Pugs/Version.hs

    r6793 r7190  
    33{-| 
    44    Version information. 
     5 
     6>   Tree and flower and leaf and grass, 
     7>   Let them pass! Let them pass! 
     8>   Hill and water under sky, 
     9>   Pass them by! Pass them by! 
     10 
    511-} 
    612 
  • t/subroutines/signature_matching.t

    r5495 r7190  
    88# check the subroutine with the closest matching signature is called 
    99 
    10 sub earth (+$me)               {"me $me"}; 
    11 sub earth (+$him)              {"him $him"}; 
    12 sub earth (+$me, +$him)        {"me $me him $him"}; 
    13 sub earth (+$me, +$him, +$her) {"me $me him $him her $her"}; 
    14 sub earth ($me)                {"pos $me"}; 
    15 sub earth ($me, +$you)         {"pos $me you $you"}; 
    16 sub earth ($me, +$her)         {"pos $me her $her"}; 
    17 sub earth ($me, $you)          {"pos $me pos $you"}; 
    18 sub earth ($me, $you, +$her)   {"pos $me pos $you her $her"}; 
     10multi earth (+$me)               {"me $me"}; 
     11multi earth (+$him)              {"him $him"}; 
     12multi earth (+$me, +$him)        {"me $me him $him"}; 
     13multi earth (+$me, +$him, +$her) {"me $me him $him her $her"}; 
     14multi earth ($me)                {"pos $me"}; 
     15multi earth ($me, +$you)         {"pos $me you $you"}; 
     16multi earth ($me, +$her)         {"pos $me her $her"}; 
     17multi earth ($me, $you)          {"pos $me pos $you"}; 
     18multi earth ($me, $you, +$her)   {"pos $me pos $you her $her"}; 
    1919 
    2020is( earth(me => 1),                     'me 1',             'named me', :todo<feature>); 
     
    3838# 
    3939 
    40 sub wind ($me, $you, +$her)   {"pos $me pos $you her $her"}; 
    41 sub wind ($me, $you)          {"pos $me pos $you"}; 
    42 sub wind ($me, +$her)         {"pos $me her $her"}; 
    43 sub wind ($me, +$you)         {"pos $me you $you"}; 
    44 sub wind ($me)                {"pos $me"}; 
    45 sub wind (+$me, +$him, +$her) {"me $me him $him her $her"}; 
    46 sub wind (+$me, +$him)        {"me $me him $him"}; 
    47 sub wind (+$him)              {"him $him"}; 
    48 sub wind (+$me)               {"me $me"}; 
     40multi wind ($me, $you, +$her)   {"pos $me pos $you her $her"}; 
     41multi wind ($me, $you)          {"pos $me pos $you"}; 
     42multi wind ($me, +$her)         {"pos $me her $her"}; 
     43multi wind ($me, +$you)         {"pos $me you $you"}; 
     44multi wind ($me)                {"pos $me"}; 
     45multi wind (+$me, +$him, +$her) {"me $me him $him her $her"}; 
     46multi wind (+$me, +$him)        {"me $me him $him"}; 
     47multi wind (+$him)              {"him $him"}; 
     48multi wind (+$me)               {"me $me"}; 
    4949 
    5050is( wind(me => 1),                     'me 1',             'named me', :todo<feature>); 
  • t/var/assigning_refs.t

    r6659 r7190  
    2121  my @array    = ($arrayref); 
    2222 
    23   is +@array, 1, '@array = ($arrayref) does not flatten the arrayref'; 
     23  is +@array, 1, '@array = ($arrayref) does not flatten the arrayref', :todo<bug>; 
    2424} 
    2525 
     
    2828  my @array    = $arrayref; 
    2929 
    30   is +@array, 1, '@array = $arrayref does not flatten the arrayref'; 
     30  is +@array, 1, '@array = $arrayref does not flatten the arrayref', :todo<bug>; 
    3131} 
    3232 
     
    3737  my %hash    = ($hashref,); 
    3838 
    39   is +%hash, 1, '%hash = ($hashref,) does not flatten the hashref'; 
     39  is +%hash, 1, '%hash = ($hashref,) does not flatten the hashref', :todo<bug>; 
    4040} 
    4141 
     
    4444  my %hash    = ($hashref); 
    4545 
    46   is +%hash, 1, '%hash = ($hashref) does not flatten the hashref'; 
     46  is +%hash, 1, '%hash = ($hashref) does not flatten the hashref', :todo<bug>; 
    4747} 
    4848 
     
    5151  my %hash    = $hashref; 
    5252 
    53   is +%hash, 1, '%hash = $hashref does not flatten the hashref'; 
     53  is +%hash, 1, '%hash = $hashref does not flatten the hashref', :todo<bug>; 
    5454} 
    5555 
  • t/var/codevars_should_not_autovivify.t

    r6596 r7190  
    1313dies_ok { 
    1414  &New::Package::foo(); 
    15 }, "...but invoking it should die"; 
     15}, "...but invoking it should die", :todo<bug>; 
  • t/var/constant.t

    r6801 r7190  
    1515    '; 
    1616 
    17     ok $ok, "declaring a sigilless constant using 'constant' works"; 
     17    ok $ok, "declaring a sigilless constant using 'constant' works", :todo<feature>; 
    1818} 
    1919 
     
    2626    '; 
    2727 
    28     ok $ok, "declaring a constant with a sigil using 'constant' works"; 
     28    ok $ok, "declaring a constant with a sigil using 'constant' works", :todo<feature>; 
    2929} 
    3030 
     
    3737    '; 
    3838 
    39     ok $ok, "declaring a sigilless constant with a type specification using 'constant' works"; 
     39    ok $ok, "declaring a sigilless constant with a type specification using 'constant' works", :todo<feature>; 
    4040} 
    4141 
     
    4848    '; 
    4949 
    50     ok $ok, "declaring an Unicode constant using 'constant' works"; 
     50    ok $ok, "declaring an Unicode constant using 'constant' works", :todo<feature>; 
    5151} 
    5252 
     
    6464    '; 
    6565 
    66     is $ok, 3, "a constant declared using 'constant' is actually constant (1)"; 
     66    is $ok, 3, "a constant declared using 'constant' is actually constant (1)", :todo<feature>; 
    6767} 
    6868 
     
    7979    '; 
    8080 
    81     is $ok, 3, "a constant declared using 'constant' is actually constant (2)"; 
     81    is $ok, 3, "a constant declared using 'constant' is actually constant (2)", :todo<feature>; 
    8282} 
    8383 
     
    9494    '; 
    9595 
    96     is $ok, 3, "a constant declared using 'constant' is actually constant (3)"; 
     96    is $ok, 3, "a constant declared using 'constant' is actually constant (3)", :todo<feature>; 
    9797} 
    9898 
     
    109109    '; 
    110110 
    111     is $ok, 3, "a constant declared using 'constant' is actually constant (4)"; 
     111    is $ok, 3, "a constant declared using 'constant' is actually constant (4)", :todo<feature>; 
    112112} 
    113113 
     
    129129    '; 
    130130 
    131     is $ok, 2, "declaring constants using 'my constant' works"; 
     131    is $ok, 2, "declaring constants using 'my constant' works", :todo<feature>; 
    132132} 
    133133 
     
    147147    '; 
    148148 
    149     is $ok, 3, "constants declared by 'my constant' shadow correctly"; 
     149    is $ok, 3, "constants declared by 'my constant' shadow correctly", :todo<feature>; 
    150150} 
    151151 
     
    162162    '; 
    163163 
    164     is $ok, 2, "declaring constants using 'our constant' works"; 
     164    is $ok, 2, "declaring constants using 'our constant' works", :todo<feature>; 
    165165} 
    166166 
     
    177177    '; 
    178178 
    179     is $ok, 2, "declaring constants using 'constant' creates package-scoped vars"; 
     179    is $ok, 2, "declaring constants using 'constant' creates package-scoped vars", :todo<feature>; 
    180180} 
  • t/var/is_readonly.t

    r6755 r7190  
    2020    is $a, 42, "binding the variable now works"; 
    2121 
    22     dies_ok { $a := 17 }, "but binding it again does not work"; 
     22    dies_ok { $a := 17 }, "but binding it again does not work", :todo<feature>; 
    2323} 
    2424 
     
    2828 
    2929    $a := 42; 
    30     ok (try{ exists $a }), "exists() returns true now"; 
     30    ok (try{ exists $a }), "exists() returns true now", :todo<feature>; 
    3131} 
    3232 
     
    3434    my $a = 3; 
    3535 
    36     ok (try{ exists $a }), "exists() on a plain normal initialized variable returns true"; 
     36    ok (try{ exists $a }), "exists() on a plain normal initialized variable returns true", :todo<feature>; 
    3737} 
  • t/var/lazy.t

    r6925 r7190  
    3434 
    3535  is $var,          42, 'our lazy var still has the correct value'; 
    36   is $was_in_lazy,   1, 'our lazy block was not executed again'; 
     36  is $was_in_lazy,   1, 'our lazy block was not executed again', :todo<bug>; 
    3737} 
    3838 
  • t/var/let.t

    r6603 r7190  
    1717    1; 
    1818  } 
    19   is $a, 23, "let() should not restore the variable, as our block exited succesfully (1)"; 
     19  is $a, 23, "let() should not restore the variable, as our block exited succesfully (1)", :todo<feature>; 
    2020} 
    2121 
     
    4040    let $a = 23; 
    4141    is $a,       23, "let() changed the variable (2-1)"; 
    42     is $get_a(), 23, "let() changed the variable (2-2)"; 
     42    is $get_a(), 23, "let() changed the variable (2-2)", :todo<feature>; 
    4343    1; 
    4444  } 
    45   is $a, 23, "let() should not restore the variable, as our block exited succesfully (2)"; 
     45  is $a, 23, "let() should not restore the variable, as our block exited succesfully (2)", :todo<feature>; 
    4646} 
    4747 
  • t/var/my.t

    r6938 r7190  
    1111 
    1212{ 
    13   dies_ok { my $x; my $x }, "test declare my() variable twice in same scope"; 
     13  is(eval('my $x; my $x; 1'), undef, "test declare my() variable twice in same scope"); 
    1414} 
    1515 
  • t/var/refs_point_to_containers.t

    r6573 r7190  
    1414 
    1515  $num = 4; 
    16   is $$ref, 4, "refs to scalars point to containers, not cells or even values (1)"; 
     16  is $$ref, 4, "refs to scalars point to containers, not cells or even values (1)", :todo<bug>; 
    1717 
    1818  $num := 5; 
    19   is $$ref, 5, "refs to scalars point to containers, not cells or even values (2)"; 
     19  is $$ref, 5, "refs to scalars point to containers, not cells or even values (2)", :todo<bug>; 
    2020} 
    2121 
     
    2626 
    2727  @array[1] = 3; 
    28   is $$ref, 3, "refs to arrays point to containers, not cells or even values (1)"; 
     28  is $$ref, 3, "refs to arrays point to containers, not cells or even values (1)", :todo<bug>; 
    2929 
    3030  try { @array[1] := 4 }; 
    31   is $$ref, 4, "refs to arrays point to containers, not cells or even values (2)"; 
     31  is $$ref, 4, "refs to arrays point to containers, not cells or even values (2)", :todo<bug>; 
    3232