Changeset 19959
- Timestamp:
- 02/20/08 18:52:10 (9 months ago)
- Location:
- src/Pugs
- Files:
-
- 2 modified
-
Meta/Str.hs (modified) (1 diff)
-
Types.hs (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Meta/Str.hs
r16504 r19959 15 15 _StrClass = mkPureClass "Str" 16 16 [ "reverse" ... Str.reverse 17 , "join" ... Str. join17 , "join" ... Str.intercalate 18 18 , "chop" ... (\str -> if Str.null str then str else Str.init str) 19 19 , "index" ... (\str sub pos -> fromMaybe (-1) $ Str.findSubstring sub $ Str.drop pos str) -
src/Pugs/Types.hs
r17044 r19959 1 {-# OPTIONS_GHC -fglasgow-exts -fno-warn-orphans -funbox-strict-fields -fallow-overlapping-instances -fparr #-} 1 {-# OPTIONS_GHC -fglasgow-exts -fno-warn-orphans -funbox-strict-fields -fallow-overlapping-instances -fparr #-} 2 2 {-| 3 3 Implementation Types. … … 10 10 -} 11 11 12 module Pugs.Types 12 module Pugs.Types 13 13 {- 14 14 ( … … 16 16 ClassTree, initTree, 17 17 18 Cxt(..), 18 Cxt(..), 19 19 cxtItem, cxtSlurpy, cxtVoid, cxtItemAny, cxtSlurpyAny, 20 20 typeOfCxt, isSlurpyCxt, isItemCxt, isVoidCxt, … … 35 35 import qualified Data.IntSet as IntSet 36 36 import qualified Data.ByteString.Char8 as Buf -- Intentionally not UTF8! 37 import qualified Data.ByteString as B (findSubstring) 37 38 38 39 data Type … … 215 216 216 217 instance ((:>:) ByteString) Pkg where 217 cast (MkPkg ns) = Buf. join(__"::") ns218 cast (MkPkg ns) = Buf.intercalate (__"::") ns 218 219 219 220 instance Show Var where … … 398 399 399 400 {-| 400 Transform an operator name, for example @&infix:\<+\>@ or @&prefix:«[+]»@, 401 Transform an operator name, for example @&infix:\<+\>@ or @&prefix:«[+]»@, 401 402 into its internal name (@&infix:+@ and @&prefix:[+]@ respectively). 402 403 -} … … 480 481 _ -> (TNil, toPkg (tokenPkg afterSig)) 481 482 afterTwi = tokenPkg (Buf.tail afterSig) 482 toPkg (p kg, rest) = (MkPkg pkg, rest)483 toPkg (pg, rest) = (MkPkg pg, rest) 483 484 tokenPkg :: ByteString -> ([ByteString], (VarCateg, ByteString)) 484 485 tokenPkg str = case Buf.elemIndex ':' str of 485 Just idx1 -> case B uf.findSubstring (__":(") str of486 Just idx1 -> case B.findSubstring (__":(") str of 486 487 Just idxSig | idx1 == idxSig -> ([], (CNil, str)) 487 _ -> case B uf.findSubstring (__"::") str of488 _ -> case B.findSubstring (__"::") str of 488 489 Nothing -> ([], (cast (Buf.take idx1 str), Buf.drop (succ idx1) str)) 489 490 Just 0 -> tokenPkg (Buf.drop 2 str) -- '$::x' is the same as $x … … 491 492 | idx == idx1 -> case cast (Buf.take idx1 str) of 492 493 -- &infix::= should parse as infix:<:=>, not infix::<=> 493 Just c at -> ([], (cat, Buf.drop (succ idx1) str))494 Just ct -> ([], (ct, Buf.drop (succ idx1) str)) 494 495 -- &Infix::= should parse as Infix::<=>, not Infix:<:=> 495 496 _ -> let (rest, final) = tokenPkg (Buf.drop (idx + 2) str) in … … 497 498 | otherwise -> ([], (cast (Buf.take idx1 str), Buf.drop (succ idx1) str)) 498 499 _ -> ([], (CNil, str)) 499 (name, longname) = case B uf.findSubstring (__":(") fullname of500 (name, longname) = case B.findSubstring (__":(") fullname of 500 501 Just idx -> (cast (Buf.take idx fullname), cast (Buf.drop idx fullname)) 501 502 _ -> (cast fullname, nullID) … … 511 512 | C_infix <- cat 512 513 , __">>" `Buf.isPrefixOf` afterCat 513 , __"<<" `Buf.isSuffixOf` afterCat 514 , __"<<" `Buf.isSuffixOf` afterCat 514 515 = (Buf.drop 2 (dropEnd 2 afterCat), MHyper) 515 516 | C_prefix <- cat … … 518 519 = case Buf.drop 2 (Buf.init afterCat) of 519 520 maybeHyper | __">>" `Buf.isPrefixOf` maybeHyper 520 , __"<<" `Buf.isSuffixOf` maybeHyper 521 , __"<<" `Buf.isSuffixOf` maybeHyper 521 522 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperScan) 522 523 maybeHyper | __"\187" `Buf.isPrefixOf` maybeHyper 523 , __"\171" `Buf.isSuffixOf` maybeHyper 524 , __"\171" `Buf.isSuffixOf` maybeHyper 524 525 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperScan) 525 526 other -> (other, MScan) … … 529 530 = case Buf.tail (Buf.init afterCat) of 530 531 maybeHyper | __">>" `Buf.isPrefixOf` maybeHyper 531 , __"<<" `Buf.isSuffixOf` maybeHyper 532 , __"<<" `Buf.isSuffixOf` maybeHyper 532 533 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperFold) 533 534 maybeHyper | __"\187" `Buf.isPrefixOf` maybeHyper 534 , __"\171" `Buf.isSuffixOf` maybeHyper 535 , __"\171" `Buf.isSuffixOf` maybeHyper 535 536 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperFold) 536 537 other -> (other, MFold) … … 542 543 = case Buf.drop 2 (dropEnd 3 afterCat) of 543 544 maybeHyper | __">>" `Buf.isPrefixOf` maybeHyper 544 , __"<<" `Buf.isSuffixOf` maybeHyper 545 , __"<<" `Buf.isSuffixOf` maybeHyper 545 546 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperScanPost) 546 547 maybeHyper | __"\187" `Buf.isPrefixOf` maybeHyper 547 , __"\171" `Buf.isSuffixOf` maybeHyper 548 , __"\171" `Buf.isSuffixOf` maybeHyper 548 549 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperScanPost) 549 550 other -> (other, MScanPost) … … 553 554 = case Buf.tail (dropEnd 3 afterCat) of 554 555 maybeHyper | __">>" `Buf.isPrefixOf` maybeHyper 555 , __"<<" `Buf.isSuffixOf` maybeHyper 556 , __"<<" `Buf.isSuffixOf` maybeHyper 556 557 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperFoldPost) 557 558 maybeHyper | __"\187" `Buf.isPrefixOf` maybeHyper 558 , __"\171" `Buf.isSuffixOf` maybeHyper 559 , __"\171" `Buf.isSuffixOf` maybeHyper 559 560 -> (Buf.drop 2 (dropEnd 2 maybeHyper), MHyperFoldPost) 560 561 other -> (other, MFoldPost) … … 656 657 the tree, the result is a very large number. 657 658 658 > <scook0> is deltaType supposed to be returning large positive numbers for 659 > <scook0> is deltaType supposed to be returning large positive numbers for 659 660 > types that are actually incompatible? 660 661 > <autrijus> that is a open design question. … … 691 692 (in this case Haskell's @(||)@). The result is thus @True@. 692 693 -} 693 junctivate :: (t -> t -> t) -- ^ Function to combine results over disjunctive 694 junctivate :: (t -> t -> t) -- ^ Function to combine results over disjunctive 694 695 -- (@|@) types 695 -> (t -> t -> t) -- ^ Function to combine results over conjunctive 696 -> (t -> t -> t) -- ^ Function to combine results over conjunctive 696 697 -- (@\&@) types 697 698 -> (Type -> Type -> t) 698 -- ^ Function that will actually perform the 699 -- ^ Function that will actually perform the 699 700 -- comparison (on non-junctive types) 700 701 -> Type -- ^ First type to compare 701 702 -> Type -- ^ Second type to compare 702 703 -> t 703 junctivate or andf base target704 junctivate ors ands f base target 704 705 | TypeOr t1 t2 <- target 705 = redo base t1 `or ` redo base t2706 = redo base t1 `ors` redo base t2 706 707 | TypeOr b1 b2 <- base 707 = redo b1 target `or ` redo b2 target708 = redo b1 target `ors` redo b2 target 708 709 | TypeAnd t1 t2 <- target 709 = redo base t1 `and ` redo base t2710 = redo base t1 `ands` redo base t2 710 711 | TypeAnd b1 b2 <- base 711 = redo b1 target `and ` redo b2 target712 = redo b1 target `ands` redo b2 target 712 713 | otherwise 713 714 = f base target 714 715 where 715 redo = junctivate or andf716 redo = junctivate ors ands f 716 717 717 718 -- When saying Int.isa(Scalar), Scalar is the base, Int is the target … … 726 727 727 728 {-| 728 Return true if the second type (the \'target\') is derived-from or equal-to the 729 Return true if the second type (the \'target\') is derived-from or equal-to the 729 730 first type (the \'base\'), in the context of the given class tree. 730 731 … … 743 744 -} 744 745 distanceType :: Type -> Type -> Int 745 distanceType base@(MkType b) target@(MkType t) = 746 distanceType base@(MkType b) target@(MkType t) = 746 747 IntMap.findWithDefault (distanceType base' target') (bk `shiftL` 16 + tk) initCache 747 748 -- | not (castOk base target) = 0 … … 787 788 Compatible types will produce a number indicating how distant they are. 788 789 Incompatible types produce a negative number indicating how much the base type 789 would need to be relaxed. If one (or both) types doesn't exist in the tree, a 790 would need to be relaxed. If one (or both) types doesn't exist in the tree, a 790 791 large negative number is produced 791 792
