Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Actors.cpp

    r3830c84 rccf1d99  
    4545    // finds and sets a ptr to the actor, message, and request structs, which are needed in the next pass
    4646    void previsit( const StructDecl * decl ) {
    47         if ( !decl->body ) return;
    48         if ( decl->name == "actor" ) {
    49             actorStructDecls.insert( decl ); // skip inserting fwd decl
    50             *actorDecl = decl;
    51         } else if( decl->name == "message" ) {
    52             messageStructDecls.insert( decl ); // skip inserting fwd decl
    53             *msgDecl = decl;
    54         } else if( decl->name == "request" ) *requestDecl = decl;
    55         else {
    56             GuardValue(insideStruct);
    57             insideStruct = true;
    58             parentDecl = mutate( decl );
    59         }
     47        GuardValue(insideStruct);
     48        insideStruct = true;
     49        parentDecl = mutate( decl );
     50        if( decl->name == "actor" ) *actorDecl = decl;
     51        if( decl->name == "message" ) *msgDecl = decl;
     52        if( decl->name == "request" ) *requestDecl = decl;
    6053        }
    6154
     
    7164    }
    7265
    73     // this collects the derived actor and message struct decl ptrs
     66    // this collects the valid actor and message struct decl pts
    7467    void postvisit( const StructInstType * node ) {
    7568        if ( ! *actorDecl || ! *msgDecl ) return;
    7669        if ( insideStruct && !namedDecl ) {
    77             auto actorIter = actorStructDecls.find( node->aggr() );   
    78             if ( actorIter != actorStructDecls.end() ) {
     70            if ( node->aggr() == *actorDecl ) {
    7971                actorStructDecls.insert( parentDecl );
    80                 return;
    81             }
    82             auto messageIter = messageStructDecls.find( node->aggr() );
    83             if ( messageIter != messageStructDecls.end() ) {
     72            } else if ( node->aggr() == *msgDecl ) {
    8473                messageStructDecls.insert( parentDecl );
    8574            }
     
    191180};
    192181
    193 // generates the definitions of send operators for actors
    194 // collects data needed for next pass that does the circular defn resolution
    195 //     for message send operators (via table above)
    196 struct GenFuncsCreateTables : public ast::WithDeclsToAdd<> {
     182#define __ALLOC 0 // C_TODO: complete swap to no-alloc version
     183
     184struct GenReceiveDecls : public ast::WithDeclsToAdd<> {
    197185    unordered_set<const StructDecl *> & actorStructDecls;
    198186    unordered_set<const StructDecl *>  & messageStructDecls;
     
    203191    FwdDeclTable & forwardDecls;
    204192
    205     // generates the operator for actor message sends
    206193        void postvisit( const FunctionDecl * decl ) {
    207194        // return if not of the form receive( param1, param2 ) or if it is a forward decl
     
    222209        auto messageIter = messageStructDecls.find( arg2InstType->aggr() );
    223210        if ( actorIter != actorStructDecls.end() && messageIter != messageStructDecls.end() ) {
     211
     212            // check that we have found all the decls we need from <actor.hfa>
     213            if ( !*allocationDecl || !*requestDecl )
     214                SemanticError( decl->location, "using actors requires a header, add #include <actor.hfa>\n" );
     215
    224216            //////////////////////////////////////////////////////////////////////
    225217            // The following generates this send message operator routine for all receive(derived_actor &, derived_msg &) functions
    226218            /*
    227219                static inline derived_actor & ?|?( derived_actor & receiver, derived_msg & msg ) {
    228                     request new_req;
     220                    request * new_req = alloc();
    229221                    Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;
    230222                    __receive_fn fn = (__receive_fn)my_work_fn;
    231                     new_req{ &receiver, &msg, fn };
    232                     send( receiver, new_req );
     223                    (*new_req){ &receiver, &msg, fn };
     224                    send( receiver, *new_req );
    233225                    return receiver;
    234226                }
    235             */
     227            */ // C_TODO: update this with new no alloc version
    236228            CompoundStmt * sendBody = new CompoundStmt( decl->location );
    237229
     230            #if __ALLOC
     231            // Generates: request * new_req = alloc();
     232            sendBody->push_back( new DeclStmt(
     233                decl->location,
     234                new ObjectDecl(
     235                    decl->location,
     236                    "new_req",
     237                    new PointerType( new StructInstType( *requestDecl ) ),
     238                    new SingleInit( decl->location, new UntypedExpr( decl->location, new NameExpr( decl->location, "alloc" ), {} ) )
     239                )
     240            ));
     241            #else
    238242            // Generates: request new_req;
    239243            sendBody->push_back( new DeclStmt(
     
    245249                )
    246250            ));
     251            #endif
    247252           
    248253            // Function type is: Allocation (*)( derived_actor &, derived_msg & )
     
    263268            ));
    264269
    265             // Function type is: Allocation (*)( actor &, message & )
     270            // Function type is: Allocation (*)( actor &, messsage & )
    266271            FunctionType * genericReceive = new FunctionType();
    267272            genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) );
     
    269274            genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
    270275
    271             // Generates: Allocation (*fn)( actor &, message & ) = (Allocation (*)( actor &, message & ))my_work_fn;
     276            // Generates: Allocation (*fn)( actor &, messsage & ) = (Allocation (*)( actor &, messsage & ))my_work_fn;
    272277            // More readable synonymous code:
    273278            //     typedef Allocation (*__receive_fn)(actor &, message &);
     
    285290            ));
    286291
     292            #if __ALLOC
     293            // Generates: (*new_req){ &receiver, &msg, fn };
     294            sendBody->push_back( new ExprStmt(
     295                decl->location,
     296                                new UntypedExpr (
     297                    decl->location,
     298                                        new NameExpr( decl->location, "?{}" ),
     299                                        {
     300                                                new UntypedExpr( decl->location, new NameExpr( decl->location, "*?" ), {  new NameExpr( decl->location, "new_req" ) } ),
     301                        new AddressExpr( new NameExpr( decl->location, "receiver" ) ),
     302                        new AddressExpr( new NameExpr( decl->location, "msg" ) ),
     303                        new NameExpr( decl->location, "fn" )
     304                                        }
     305                                )
     306                        ));
     307
     308            // Generates: send( receiver, *new_req );
     309            sendBody->push_back( new ExprStmt(
     310                decl->location,
     311                                new UntypedExpr (
     312                    decl->location,
     313                                        new NameExpr( decl->location, "send" ),
     314                                        {
     315                                                {
     316                            new NameExpr( decl->location, "receiver" ),
     317                            new UntypedExpr( decl->location, new NameExpr( decl->location, "*?" ), {  new NameExpr( decl->location, "new_req" ) } )
     318                        }
     319                                        }
     320                                )
     321                        ));
     322            #else
    287323            // Generates: new_req{ &receiver, &msg, fn };
    288324            sendBody->push_back( new ExprStmt(
     
    314350                                )
    315351                        ));
     352            #endif
    316353           
    317354            // Generates: return receiver;
     
    321358            FunctionDecl * sendOperatorFunction = new FunctionDecl(
    322359                decl->location,
    323                 "?<<?",
     360                "?|?",
    324361                {},                     // forall
    325362                {
     
    351388            // forward decls to resolve use before decl problem for '|' routines
    352389            forwardDecls.insertDecl( *actorIter, *messageIter , ast::deepCopy( sendOperatorFunction ) );
     390            // forwardDecls.push_back( ast::deepCopy( sendOperatorFunction ) );
    353391
    354392            sendOperatorFunction->stmts = sendBody;
     
    358396
    359397  public:
    360     GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     398    GenReceiveDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    361399        const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
    362400        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
     
    364402};
    365403
    366 
    367 // separate pass is needed since this pass resolves circular defn issues
    368 // generates the forward declarations of the send operator for actor routines
    369 struct FwdDeclOperator : public ast::WithDeclsToAdd<> {
     404struct GenFwdDecls : public ast::WithDeclsToAdd<> {
    370405    unordered_set<const StructDecl *> & actorStructDecls;
    371406    unordered_set<const StructDecl *>  & messageStructDecls;
    372407    FwdDeclTable & forwardDecls;
    373408
    374     // handles forward declaring the message operator
    375409    void postvisit( const StructDecl * decl ) {
    376410        list<FunctionDecl *> toAddAfter;
     
    399433
    400434  public:
    401     FwdDeclOperator( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    402         FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), forwardDecls(forwardDecls) {}
     435    GenFwdDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     436        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
     437        forwardDecls(forwardDecls) {}
    403438};
    404439
     
    426461    Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    427462        allocationDecl, actorDecl, msgDecl );
    428 
    429     // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass
    430     if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr )
    431         return;
    432 
     463       
    433464    // second pass locates all receive() routines that overload the generic receive fn
    434465    // it then generates the appropriate operator '|' send routines for the receive routines
    435     Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
     466    Pass<GenReceiveDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    436467        allocationDecl, actorDecl, msgDecl, forwardDecls );
    437468
    438469    // The third pass forward declares operator '|' send routines
    439     Pass<FwdDeclOperator>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
     470    Pass<GenFwdDecls>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
    440471}
    441472
Note: See TracChangeset for help on using the changeset viewer.