Changeset 6594

Show
Ignore:
Timestamp:
08/30/05 22:57:49 (3 years ago)
Author:
putter
Message:

pugs - a Syn package/namespace now remembers whether it was a package/module/class/etc. When compiling to PIL, emit a kludge declaration info statement (eg &Module::_create("M"); for a module M {...}).
Prelude/JS.pm: added placeholder hooks for declaration info calls.

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • perl5/PIL2JS/lib6/Prelude/JS.pm

    r6563 r6594  
    108108  })')($sigil ~ join "::", @parts); 
    109109} 
     110 
     111 
     112# XXX PIL1 pugs -C kludge. 
     113sub Package::_create($name) {} 
     114sub Module::_create($name) {} 
     115sub Class::_create($name) {} 
     116sub Rule::_create($name) {} 
     117sub Grammar::_create($name) {} 
  • src/Pugs/AST.hs

    r5836 r6594  
    124124mergeStmts (Sym scope name x) y = Sym scope name (mergeStmts x y) 
    125125mergeStmts (Pad scope lex x) y = Pad scope lex (mergeStmts x y) 
    126 mergeStmts (Syn "package" [pkg@(Val (VStr _))]) y = 
    127     Syn "namespace" [pkg, y] 
     126mergeStmts (Syn "package" [kind, pkg@(Val (VStr _))]) y = 
     127    Syn "namespace" [kind, pkg, y] 
    128128mergeStmts x@(Pos pos (Syn syn _)) y | (syn ==) `any` words "subst match //"  = 
    129129    mergeStmts (Pos pos (App (Var "&infix:~~") Nothing [Var "$_", x])) y 
  • src/Pugs/Compile.hs

    r6589 r6594  
    167167        tailCall (PPos pos exp x) = PPos pos exp (tailCall x) 
    168168        tailCall x = x 
    169     Stmts this (Syn "namespace" [Val (VStr pkg), rest]) -> do 
     169    Stmts this (Syn "namespace" [Val (VStr sym), Val (VStr pkg), rest]) -> do 
    170170        thisC   <- enter cxtVoid $ compile this 
     171        declC   <- enter cxtVoid $ compile decl 
    171172        restC   <- enterPackage pkg $ compileStmts rest 
    172         return $ PStmts thisC restC 
     173        return $ PStmts thisC $ PStmts declC restC 
     174        where 
     175          -- XXX - kludge. 
     176          decl = App (Var func) Nothing [(Val (VStr pkg))] 
     177          func = "&" ++ (capitalize sym) ++ "::_create" 
     178          capitalize []     = [] 
     179          capitalize (c:cs) = toUpper c:cs 
     180 
    173181    Stmts this rest -> do 
    174182        thisC   <- enter cxtVoid $ compile this 
  • src/Pugs/Eval.hs

    r6581 r6594  
    688688    retEmpty 
    689689 
    690 reduceSyn "package" [exp] = reduceSyn "namespace" [exp, emptyExp] 
    691  
    692 reduceSyn "namespace" [exp, body] = do 
     690reduceSyn "package" [kind, exp] = reduceSyn "namespace" [kind, exp, emptyExp] 
     691 
     692reduceSyn "namespace" [_kind, exp, body] = do 
    693693    val <- evalExp exp 
    694694    str <- fromVal val 
  • src/Pugs/Parser.hs

    r6530 r6594  
    315315rulePackageBlockDeclaration :: RuleParser Exp 
    316316rulePackageBlockDeclaration = rule "package block declaration" $ do 
    317     (_, pkgVal, env) <- try $ do 
     317    (_, kind, pkgVal, env) <- try $ do 
    318318        rv <- rulePackageHead 
    319319        lookAhead (char '{') 
     
    322322    env' <- getRuleEnv 
    323323    putRuleEnv env'{ envPackage = envPackage env } 
    324     return $ Syn "namespace" [pkgVal, body] 
     324    return $ Syn "namespace" [kind, pkgVal, body] 
    325325 
    326326rulePackageDeclaration :: RuleParser Exp 
    327327rulePackageDeclaration = rule "package declaration" $ try $ do 
    328     (_, pkgVal, _) <- rulePackageHead 
    329     return $ Syn "package" [pkgVal] 
    330  
    331 rulePackageHead :: RuleParser (String, Exp, Env) 
     328    (_, kind, pkgVal, _) <- rulePackageHead 
     329    return $ Syn "package" [kind, pkgVal] 
     330 
     331rulePackageHead :: RuleParser (String, Exp, Exp, Env) 
    332332rulePackageHead = do 
    333333    sym <- choice $ map symbol (words "package module class role grammar") 
     
    349349                    envClasses = envClasses env `addNode` mkType name } 
    350350    let pkgVal = Val . VStr $ name -- ++ v ++ a 
    351     return (name, pkgVal, env) 
     351        kind   = Val . VStr $ sym 
     352    return (name, kind, pkgVal, env) 
    352353 
    353354ruleSubDeclaration :: RuleParser Exp