Changeset 3961 for src/Pugs/Types

Show
Ignore:
Timestamp:
05/27/05 05:22:52 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
5515
Message:

* Perl 5 Array and Hash are now accessible from Perl 6.

Location:
src/Pugs/Types
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Types/Array.hs

    r3947 r3961  
    251251    array_deleteElem _ _   = retConstError undef 
    252252 
     253evalPerl5Sub :: String -> [PerlSV] -> Eval Val 
     254evalPerl5Sub code args = do 
     255    env   <- ask 
     256    fmap PerlSV . liftIO $ do 
     257        envSV <- mkVal env 
     258        subSV <- evalPerl5 code envSV (enumCxt cxtItemAny) 
     259        callPerl5 subSV nullSV args envSV (enumCxt cxtItemAny) 
     260 
    253261instance ArrayClass PerlSV where 
    254262    array_iType = const $ mkType "Array::Perl" 
    255     array_fetchVal _  _    = return undef 
    256     array_storeVal _ _ _   = retConstError undef 
     263    array_fetchVal sv idx = do 
     264        idxSV   <- fromVal $ castV idx 
     265        evalPerl5Sub "sub { $_[0]->[$_[1]] }" [sv, idxSV] 
     266    array_storeVal sv idx val = do 
     267        idxSV   <- fromVal $ castV idx 
     268        valSV   <- fromVal val 
     269        evalPerl5Sub "sub { $_[0]->[$_[1]] = $_[2] }" [sv, idxSV, valSV] 
     270        return () 
    257271    array_storeElem _ _ _  = retConstError undef 
    258272    array_deleteElem _ _   = retConstError undef 
  • src/Pugs/Types/Hash.hs

    r3947 r3961  
    120120instance HashClass PerlSV where 
    121121    hash_iType = const $ mkType "Hash::Perl" 
     122    hash_fetchVal sv key = do 
     123        keySV   <- fromVal $ castV key 
     124        evalPerl5Sub "sub { $_[0]->{$_[1]} }" [sv, keySV] 
    122125    hash_clear _ = retConstError undef 
    123126    hash_store _ _ = retConstError undef 
    124     hash_storeVal _ _ _ = retConstError undef 
     127    hash_storeVal sv key val = do 
     128        keySV   <- fromVal $ castV key 
     129        valSV   <- fromVal val 
     130        evalPerl5Sub "sub { $_[0]->{$_[1]} = $_[2] }" [sv, keySV, valSV] 
     131        return () 
    125132    hash_storeElem _ _ _ = retConstError undef 
    126133    hash_deleteElem _ _ = retConstError undef