Changeset 4102

Show
Ignore:
Timestamp:
05/29/05 18:05:01 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
5515
Message:

* Perl5Embed: .kv, .keys, .values, .pairs etc now works on Perl hashrefs.

Location:
src/Pugs
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/Keyed.hs

    r4085 r4102  
    1616 
    1717pairsFromVal :: Val -> Eval [Val] 
     18pairsFromVal (PerlSV sv) = do 
     19    keys    <- hash_fetchKeys sv 
     20    return $ VList (map castV keys) 
     21    elems   <- mapM (hash_fetchElem sv) keys 
     22    return $ map (VRef . MkRef . IPair) (keys `zip` elems) 
    1823pairsFromVal v = do 
    1924    ref  <- fromVal v 
     
    2227 
    2328keysFromVal :: Val -> Eval Val 
     29keysFromVal (PerlSV sv) = do 
     30    keys    <- hash_fetchKeys sv 
     31    return $ VList (map castV keys) 
    2432keysFromVal (VList vs) = return . VList $ map VInt [0 .. (genericLength vs) - 1] 
    2533keysFromVal (VRef ref) = do 
    2634    vals <- keysFromRef ref 
    2735    return $ VList vals 
    28 keysFromVal (PerlSV sv) = do 
    29     keys    <- hash_fetchKeys sv 
    30     return $ VList (map castV keys) 
    3136keysFromVal v = retError "Not a keyed reference" v 
    3237 
     
    3742    vals <- valuesFromRef ref 
    3843    return $ VList vals 
     44valuesFromVal (PerlSV sv) = do 
     45    pairs <- hash_fetch sv 
     46    return . VList $ Map.elems pairs 
    3947valuesFromVal v = retError "Not a keyed reference" v 
    4048 
  • src/Pugs/Types/Array.hs

    r3961 r4102  
    264264        idxSV   <- fromVal $ castV idx 
    265265        evalPerl5Sub "sub { $_[0]->[$_[1]] }" [sv, idxSV] 
     266    array_clear sv = do 
     267        evalPerl5Sub "sub { undef @{$_[0]} }" [sv] 
     268        return () 
    266269    array_storeVal sv idx val = do 
    267270        idxSV   <- fromVal $ castV idx 
     
    269272        evalPerl5Sub "sub { $_[0]->[$_[1]] = $_[2] }" [sv, idxSV, valSV] 
    270273        return () 
    271     array_storeElem _ _ _  = retConstError undef 
    272     array_deleteElem _ _   = retConstError undef 
     274    array_deleteElem sv idx = do 
     275        idxSV   <- fromVal $ castV idx 
     276        evalPerl5Sub "sub { delete $_[0]->[$_[1]] }" [sv, idxSV] 
     277        return () 
  • src/Pugs/Types/Hash.hs

    r4084 r4102  
    123123        keySV   <- fromVal $ castV key 
    124124        evalPerl5Sub "sub { $_[0]->{$_[1]} }" [sv, keySV] 
    125     hash_clear _ = retConstError undef 
    126     hash_store _ _ = retConstError undef 
     125    hash_clear sv = do 
     126        evalPerl5Sub "sub { undef %{$_[0]} }" [sv] 
     127        return () 
    127128    hash_storeVal sv key val = do 
    128129        keySV   <- fromVal $ castV key 
     
    134135        keysStr <- fromVal keysSV 
    135136        return $ lines keysStr 
    136     hash_storeElem _ _ _ = retConstError undef 
    137     hash_deleteElem _ _ = retConstError undef 
     137    hash_deleteElem sv key = do 
     138        keySV   <- fromVal $ castV key 
     139        evalPerl5Sub "sub { delete $_[0]->{$_[1]} }" [sv, keySV] 
     140        return () 
     141    hash_isEmpty sv = do 
     142        fromVal =<< evalPerl5Sub "sub { !!%{$_[0]} }" [sv]