Show
Ignore:
Timestamp:
08/16/06 19:28:24 (2 years ago)
Author:
audreyt
Message:

* Glorious refactoring of the Var type.

Previously, Var is type synonym to String, and all package

lookups, OUTER
handling, sigil and twigil parsing etc were done in an extremely adhoc way with String operations.

Now we split Var into several parts.
Take "&Moose::Elk::infix:<antler>" as an example:

v_sigil
VarSigil? -- SScalar
v_twigil
VarTwigil? -- TNone
v_package
Pkg -- ["Moose", "Elk"]
v_categ
VarCateg? -- C_infix
v_name
ID -- "antler"

The names are stored as interned ByteStrings? for fast comparison.

All involved types are changed from String to new types as well,

such as (envPackage
Pkg).
Files:
1 modified

Legend:

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

    r12176 r12317  
    3737    let pwd = if hasSrc then pwd2 else pwd1 
    3838    glob    <- askGlobal 
    39     let syms = [ (name, tvar) | (('<':'*':name), [(_, tvar)]) <- padToList glob ] 
     39    let syms = [ (cast $ v_name var, tvar) 
     40               | (var, [(_, tvar)]) <- padToList glob 
     41               , SRegex == v_sigil var 
     42               , isGlobalVar var 
     43               ] 
    4044    subrules <- forM syms $ \(name, tvar) -> do 
    4145        ref         <- liftSTM $ readTVar tvar 
     
    106110        0 -> evalExp $ App (Val y) Nothing [] 
    107111        1 -> do 
    108              topic <- readVar "$_" 
     112             topic <- readVar (cast "$_") 
    109113             evalExp $ App (Val y) Nothing [Val topic] 
    110114        _ -> fail ("Unexpected arity in smart match: " ++ (show arity)) 
     
    142146        if not (matchOk match) then return (str, ok) else do 
    143147        glob    <- askGlobal 
    144         matchSV <- findSymRef "$/" glob 
     148        matchSV <- findSymRef (cast "$/") glob 
    145149        writeRef matchSV (VMatch match) 
    146150        str'    <- fromVal =<< evalExp subst 
     
    161165    if not (matchOk match) then return (VBool False) else do 
    162166    glob    <- askGlobal 
    163     matchSV <- findSymRef "$/" glob 
     167    matchSV <- findSymRef (cast "$/") glob 
    164168    writeRef matchSV (VMatch match) 
    165169    str'    <- fromVal =<< evalExp subst 
     
    205209    match   <- str `doMatch` rx 
    206210    glob    <- askGlobal 
    207     matchSV <- findSymRef "$/" glob 
     211    matchSV <- findSymRef (cast "$/") glob 
    208212    writeRef matchSV (VMatch match) 
    209213    ifListContext 
     
    275279pkgParents :: VStr -> Eval [VStr] 
    276280pkgParents pkg = do 
    277     ref     <- readVar (':':'*':pkg) 
     281    ref     <- readVar $ cast (':':'*':pkg) 
    278282    if ref == undef then return [] else do 
    279283    meta    <- readRef =<< fromVal ref 
     
    287291pkgParentClasses :: VStr -> Eval [VStr] 
    288292pkgParentClasses pkg = do 
    289     ref     <- readVar (':':'*':pkg) 
     293    ref     <- readVar $ cast (':':'*':pkg) 
    290294    if ref == undef then return [] else do 
    291295    meta    <- readRef =<< fromVal ref