Changeset 3328 for src/Pugs/AST/Internals.hs
- Timestamp:
- 05/17/05 11:33:37 (4 years ago)
- svk:copy_cache_prev:
- 4908
- Files:
-
- 1 modified
-
src/Pugs/AST/Internals.hs (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/AST/Internals.hs
r3200 r3328 129 129 Nothing -> errIndex def idx 130 130 131 -- |Check whether a 'Val' is of the specified type. Based on the result, 132 -- either the first or the second evaluation should be performed. 131 {-| 132 Check whether a 'Val' is of the specified type. Based on the result, 133 either the first or the second evaluation should be performed. 134 -} 133 135 ifValTypeIsa :: Val -- ^ Value to check the type of 134 136 -> String -- ^ Name of the type to check against … … 144 146 else falseM 145 147 146 -- |If we are in list context (i.e. 'CxtSlurpy'), then perform the first 147 -- evaluation; otherwise perform the second. 148 {-| 149 If we are in list context (i.e. 'CxtSlurpy'), then perform the first 150 evaluation; otherwise perform the second. 151 -} 148 152 ifListContext :: (MonadReader Env m) 149 153 => m t -- ^ The @then@ case … … 156 160 _ -> falseM 157 161 158 -- |Return the appropriate 'empty' value for the current context -- either 159 -- an empty list ('VList' []), or undef ('VUndef'). 162 {-| 163 Return the appropriate 'empty' value for the current context -- either 164 an empty list ('VList' []), or undef ('VUndef'). 165 -} 160 166 retEmpty :: Eval Val 161 167 retEmpty = do … … 189 195 -} 190 196 191 -- |Typeclass indicating types that can be converted to\/from 'Val's. 192 -- Not to be confused with 'Val' itself, or the 'Exp' constructor @Val@. 197 {-| 198 Typeclass indicating types that can be converted to\/from 'Val's. 199 200 Not to be confused with 'Val' itself, or the 'Exp' constructor @Val@. 201 -} 193 202 class (Typeable n, Show n, Ord n) => Value n where 194 203 fromVal :: Val -> Eval n … … 306 315 doCast _ = True 307 316 308 -- |Collapse a junction value into a single boolean value. Works by 309 -- recursively casting the junction members to booleans, then performing 310 -- the actual junction test. 317 {-| 318 Collapse a junction value into a single boolean value. 319 320 Works by recursively casting the junction members to booleans, then performing 321 the actual junction test. 322 -} 311 323 juncToBool :: VJunc -> Bool 312 324 juncToBool (MkJunc JAny _ vs) = True `Set.member` Set.map vCast vs … … 481 493 type VType = Type 482 494 483 -- |Represents a value. Note that 'Val' is also a constructor for 'Exp' (i.e. 484 -- an expression containing a value), so don't confuse the two. Similarly, 485 -- all the constructors for @data 'Val'@ are themselves puns on the types of 486 -- values they contain. 495 {-| 496 Represents a value. 497 498 Note that 'Val' is also a constructor for 'Exp' (i.e. an expression containing 499 a value), so don't confuse the two. Similarly, all the constructors for 500 @data 'Val'@ are themselves puns on the types of values they contain. 501 -} 487 502 data Val 488 503 = VUndef -- ^ Undefined value … … 512 527 deriving (Show, Eq, Ord, Typeable) 513 528 514 -- |Find the 'Type' of the value contained by a 'Val'. See "Pugs.Types" for 515 -- info on types. 529 {-| 530 Find the 'Type' of the value contained by a 'Val'. 531 532 See "Pugs.Types" for info on types. 533 -} 516 534 valType :: Val -> Type 517 535 valType VUndef = mkType "Scalar" … … 547 565 deriving (Show, Eq, Ord) 548 566 549 -- |Represents a junction value. 550 -- Note that @VJunc@ is also a pun for a 'Val' constructor /containing/ a 551 -- 'VJunc'. 567 {-| 568 Represents a junction value. 569 570 Note that @VJunc@ is also a pun for a 'Val' constructor /containing/ a 'VJunc'. 571 -} 552 572 data VJunc = MkJunc 553 573 { juncType :: !JuncType -- ^ 'JAny', 'JAll', 'JNone' or 'JOne' … … 564 584 } deriving (Eq, Ord) 565 585 566 -- | The combining semantics of a junction. See 'VJunc' for more info.586 -- | The combining semantics of a junction. See 'VJunc' for more info. 567 587 data JuncType = JAny -- ^ Matches if /at least one/ member matches 568 588 | JAll -- ^ Matches only if /all/ members match … … 585 605 "" $ Set.elems set) ++ ")" 586 606 587 -- |Each 'VCode' structure has a 'SubType' indicating what \'level\' of 588 -- callable item it is. 'doApply' uses this to figure out how to enter 589 -- the proper scope and 'Env' when the sub is called. 590 -- Note that this is the \'type\' of a \'sub\', and has nothing to do with 591 -- subtyping. 607 {-| 608 Each 'VCode' structure has a 'SubType' indicating what \'level\' of 609 callable item it is. 'doApply' uses this to figure out how to enter 610 the proper scope and 'Env' when the sub is called. 611 612 Note that this is the \'type\' of a \'sub\', and has nothing to do with 613 subtyping. 614 -} 592 615 data SubType = SubMethod -- ^ Method 593 616 | SubRoutine -- ^ Regular subroutine … … 599 622 isSlurpy param = isSlurpyCxt $ paramContext param 600 623 601 -- |A formal parameter of a sub (or other callable). These represent 602 -- declared parameters; don't confuse them with actual parameter values. 624 {-| 625 A formal parameter of a sub (or other callable). 626 627 These represent declared parameters; don't confuse them with actual parameter 628 values. 629 -} 603 630 data Param = MkParam 604 631 { isInvocant :: !Bool -- ^ Is it in invocant slot? … … 615 642 deriving (Show, Eq, Ord) 616 643 617 -- | A list of formal parameters.644 -- | A list of formal parameters. 618 645 type Params = [Param] 619 -- |A list of bindings from formal parameters ('Param') to actual parameter 620 -- expressions ('Exp'). 646 {-| 647 A list of bindings from formal parameters ('Param') to actual parameter 648 expressions ('Exp'). 649 -} 621 650 type Bindings = [(Param, Exp)] 622 651 {-| … … 645 674 type SlurpLimit = [(VInt, Exp)] 646 675 647 -- | Represents a sub, method, closure etc. -- basically anything callable.676 -- | Represents a sub, method, closure etc. -- basically anything callable. 648 677 data VCode = MkCode 649 678 { isMulti :: !Bool -- ^ Is this a multi sub\/method? … … 661 690 deriving (Show, Eq, Ord, Typeable) 662 691 663 -- |Construct a 'VCode' representing a built-in primitive operator. 664 -- See "Pugs.Prim" for more info. 692 {-| 693 Construct a 'VCode' representing a built-in primitive operator. 694 695 See "Pugs.Prim" for more info. 696 -} 665 697 mkPrim :: VCode 666 698 mkPrim = MkCode … … 712 744 -} 713 745 714 -- | Represents an expression tree.746 -- | Represents an expression tree. 715 747 data Exp 716 748 = Noop -- ^ No-op … … 731 763 732 764 class Unwrap a where 733 -- |Unwrap a nested expression, throwing away wrappers (such as 'Cxt' or 734 -- 'Pos' to get at the more interesting expression underneath. Works both 735 -- on individual 'Exp's, and elementwise on ['Exp']s. 765 {-| 766 Unwrap a nested expression, throwing away wrappers (such as 'Cxt' or 767 'Pos' to get at the more interesting expression underneath. Works both 768 on individual 'Exp's, and elementwise on ['Exp']s. 769 -} 736 770 unwrap :: a -> a 737 771 unwrap = id … … 762 796 compare _ _ = EQ 763 797 764 -- |(Is this even used? A @grep@ through the sources doesn't find any 765 -- callers...) 798 {-| 799 (Is this even used? A @grep@ through the sources doesn't find any callers...) 800 -} 766 801 extractExp :: Exp -> ([Exp], [String]) -> ([Exp], [String]) 767 802 extractExp ex (exps, vs) = (ex':exps, vs') … … 769 804 (ex', vs') = extract ex vs 770 805 771 -- | (Used by 'extractExp'...)806 -- | (Used by 'extractExp'...) 772 807 extract :: Exp -> [String] -> (Exp, [String]) 773 808 extract (App n invs args) vs = (App n invs' args', vs'') … … 803 838 804 839 -- can be factored 805 -- |Return the context implied by a particular primary sigil 806 -- (\$, \@, \% or \&). E.g. used to find what context to impose on 807 -- the RHS of a binding (based on the sigil of the LHS). 840 {-| 841 Return the context implied by a particular primary sigil 842 (\$, \@, \% or \&). E.g. used to find what context to impose on 843 the RHS of a binding (based on the sigil of the LHS). 844 -} 808 845 cxtOfSigil :: Char -> Cxt 809 846 cxtOfSigil '$' = cxtItemAny … … 815 852 cxtOfSigil x = internalError $ "cxtOfSigil: unexpected character: " ++ show x 816 853 817 -- |Return the type of variable implied by a name beginning with the specified 818 -- sigil. 854 {-| 855 Return the type of variable implied by a name beginning with the specified 856 sigil. 857 -} 819 858 typeOfSigil :: Char -> Type 820 859 typeOfSigil '$' = mkType "Scalar" … … 857 896 type DebugInfo = Maybe (TVar (Map String String)) 858 897 859 -- | Evaluation environment. The current environment is stored in the 860 -- @Reader@ monad inside the current 'Eval' monad, and can be retrieved using 861 -- @ask@ for the whole 'Env', or @asks@ if you just want a single field. 898 {-| 899 Evaluation environment. 900 901 The current environment is stored in the @Reader@ monad inside the current 902 'Eval' monad, and can be retrieved using @ask@ for the whole 'Env', or @asks@ 903 if you just want a single field. 904 -} 862 905 data Env = MkEnv 863 906 { envContext :: !Cxt -- ^ Current context … … 886 929 showCxt (CxtSlurpy typ) = "List (" ++ showType typ ++ ")" 887 930 888 {- |A 'Pad' keeps track of the names of all currently-bound symbols, and 931 {-| 932 A 'Pad' keeps track of the names of all currently-bound symbols, and 889 933 associates them with the things they actually represent. 890 934 … … 927 971 return $ "(unsafePerformIO . atomically $ do { bool <- newTVar True; ref <- (newTVar " ++ vCast dump ++ "); return (bool, ref) })" 928 972 929 -- |Produce a 'Pad' from a list of bindings. The inverse of 'padToList'. 930 -- Not to be confused with the actual 'Pad' constructor @MkPad@. 973 {-| 974 Produce a 'Pad' from a list of bindings. The inverse of 'padToList'. 975 976 Not to be confused with the actual 'Pad' constructor @MkPad@. 977 -} 931 978 mkPad :: [(Var, [(TVar Bool, TVar VRef)])] -> Pad 932 979 mkPad = MkPad . Map.fromList 933 980 934 -- | Look up a symbol in a 'Pad'.981 -- | Look up a symbol in a 'Pad', returning the ref it is bound to. 935 982 lookupPad :: Var -- ^ Symbol to look for 936 983 -> Pad -- ^ Pad to look in … … 940 987 Nothing -> Nothing 941 988 942 -- |Transform a pad into a flat list of bindings. The inverse of 'mkPad'. 943 -- Note that @Data.Map.assocs@ returns a list of mappings in ascending key 944 -- order. 989 {-| 990 Transform a pad into a flat list of bindings. The inverse of 'mkPad'. 991 992 Note that @Data.Map.assocs@ returns a list of mappings in ascending key order. 993 -} 945 994 padToList :: Pad -> [(Var, [(TVar Bool, TVar VRef)])] 946 995 padToList (MkPad map) = Map.assocs map 947 996 948 -- | Return the difference between two pads.997 -- | Return the difference between two pads. 949 998 diffPads :: Pad -- ^ Pad a 950 999 -> Pad -- ^ Pad b … … 1064 1113 defined VUndef = False 1065 1114 defined _ = True 1066 -- | Return an undefinedvalue (i.e. 'VUndef').1115 -- | Produce an undefined Perl6 value (i.e. 'VUndef'). 1067 1116 undef :: VScalar 1068 1117 undef = VUndef
