Changeset 15442 for src/Pugs/Eval

Show
Ignore:
Timestamp:
03/04/07 14:42:58 (21 months ago)
Author:
audreyt
Message:

* Pgugs.Eval.Var: Grand Unified Dispatch for both VV and PerlSV.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval/Var.hs

    r15420 r15442  
    1 {-# OPTIONS_GHC -fglasgow-exts -cpp -fallow-overlapping-instances -funbox-strict-fields #-} 
     1{-# OPTIONS_GHC -fglasgow-exts -fallow-overlapping-instances -funbox-strict-fields -fparr #-} 
    22 
    33module Pugs.Eval.Var ( 
     
    1010import Pugs.AST 
    1111import Pugs.Types 
    12 import Pugs.Embed.Perl5 
    1312import Pugs.Bind 
    1413import Pugs.Prim.List (op2Reduce, op1HyperPrefix, op1HyperPostfix, op2Hyper) 
     
    165164    | Nothing <- _invs = do 
    166165        findBuiltinSub NoMatchingMulti _var 
    167     | not (isQualifiedVar _var) = case unwrap _inv of 
    168         Val vv@VV{}     -> withExternalCall callMethodVV vv 
    169         Val sv@PerlSV{} -> withExternalCall callMethodPerl5 sv 
    170         inv' -> do 
    171             typ <- evalInvType inv' 
    172             if typ == mkType "Scalar::Perl5" 
    173                 then evalExp inv' >>= withExternalCall callMethodPerl5 
    174                 else findTypedSub (cast typ) _var 
     166    | not (isQualifiedVar _var) = do 
     167        case unwrap _inv of 
     168            Val vv@VV{}     -> withExternalCall callMethodVV vv 
     169            Val sv@PerlSV{} -> withExternalCall callMethodVV sv 
     170            inv' -> do 
     171                typ <- evalInvType inv' 
     172                if typ == mkType "Scalar::Perl5" -- code for "VV" 
     173                    then evalExp inv' >>= withExternalCall callMethodVV 
     174                    else findTypedSub (cast typ) _var 
    175175    | Just var' <- dropVarPkg _SUPER _var = do 
    176176        pkg <- asks envPackage 
     
    231231                        key <- fromVal k 
    232232                        val <- fromVal v 
    233                         return (key, [val])   :: Eval (ID, [Val.Val]) 
    234  
    235                 -- This is the Capture object we are going to work with 
    236                 -- let capt = CaptMeth invVV (MkArguments Val.MkFeed posVVs namVVs] 
    237                 -- callMethod methName [] 
    238                 -- inv ./ meth = ivDispatch inv $ MkMethodInvocation meth (mkArgs []) 
    239                 resVV <- invVV ./ cast methName 
    240                 return . castV $ resVV 
     233                        return (key, val)   :: Eval (ID, Val.Val) 
     234                rv <- tryT $ do 
     235                    resVV <- invVV ./ (methName, posVVs, namVVs) 
     236                    vvToVal resVV 
     237                case rv of 
     238                    VError (VStr s) _ 
     239                        | "Can't locate object method" `isPrefixOf` s || "Can't call method" `isPrefixOf` s -> do 
     240                        let capt = miArguments (cast (methName, (invVV:posVVs), namVVs) :: Call) 
     241                        rv' <- tryT . evalExp $ App (Var _var{ v_sigil = SCodeMulti }) Nothing [Syn "|" [Val (VV (mkVal capt))]] 
     242                        case rv' of 
     243                            VError (VStr s') _ | "No compatible subroutine found" `isPrefixOf` s' -> EvalT $ return (RException rv) 
     244                            VError{} -> EvalT $ return (RException rv') 
     245                            _ -> return rv' 
     246                    VError{} -> EvalT $ return (RException rv) 
     247                    _ -> return rv 
    241248            } 
    242249 
    243250    -- callMethodPerl5 :: (_var :: Var, _invs :: Maybe Exp, _args :: [Exp]) 
    244251    --     => Eval (Maybe VCode) 
     252    {- 
    245253    callMethodPerl5 = do 
    246254        let name = cast (v_name _var) 
     
    268276                        runInvokePerl5 subSV sv svs 
    269277            } 
    270  
     278    -} 
    271279    -- findWithPkg :: (_var :: Var, _invs :: Maybe Exp, _args :: [Exp]) 
    272280    --     => Pkg -> Var -> Eval (Either FindSubFailure VCode) 
     
    674682        return var{ v_package = currentPkg } 
    675683toQualified var = return var 
     684