示例#1
0
文件: cfg.cpp 项目: h87kg/pyston
    void doReturn(AST_expr* value) {
        assert(value);
        CFGBlock *rtn_dest = getReturn();
        if (rtn_dest != NULL) {
            push_back(makeAssign("#rtnval", value));

            AST_Jump *j = makeJump();
            j->target = rtn_dest;
            curblock->connectTo(rtn_dest);
            push_back(j);
        } else {
            AST_Return *node = new AST_Return();
            node->value = value;
            node->col_offset = value->col_offset;
            node->lineno = value->lineno;
            push_back(node);
        }
        curblock = NULL;
    }
示例#2
0
Instruction Instruction::makeFork(Instruction* ptr, uint32_t offset) {
  Instruction i = makeJump(ptr, offset);
  i.OpCode = FORK_OP;
  return i;
}
示例#3
0
int bestMJalt(PGAME orgGame, PGAME game, int d, int f, int returnScore){
    
    int i;
    int bestIndex = 0;
    int bestIndexScore = 0;
    
    
    
    for(i = 0; i < game->mjCount && d > 0; i++){
        
        
        GAME newGame;
        
        memcpy(&newGame, game, sizeof(GAME));
        
        if (newGame.canJ) {
            makeJump(i, &newGame);
        }else{
            makeMove(i, &newGame);
        }
        
        changeTurn(&newGame);
        cleanUp(&newGame);
        
        findJumpersForGame(&newGame);
        
        if (!newGame.canJ) {
            findMoversForGame(&newGame);
        }
        
        
        int tempScore;
                
        if(f > 0 && d > 0){
            tempScore = bestMJalt(orgGame, &newGame, d-1, f, 1);
        }        
        
        if(tempScore > bestIndexScore){
            bestIndexScore = tempScore;
            bestIndex = i;
            
        }else{
            
            if(tempScore == bestIndexScore && returnScore == 0){
                if(rand()%2 == 0){
                    bestIndexScore = tempScore;
                    bestIndex = i;
                }                
            }
            
        }

        
        
    }
    
    
    if(game->turn != orgGame->turn)
    bestIndexScore = -bestIndexScore;
    
    if(returnScore)
    return bestIndexScore;
    
    return bestIndex;
}
示例#4
0
int bestMJ(PGAME orgGame, PGAME game, int d, int f){

    int i;
    int bestIndex = 0;
    int bestIndexScore = 0;
    
    
    
    for(i = 0; i < game->mjCount && d > 0; i++){
        
            
        GAME newGame;
        
        memcpy(&newGame, game, sizeof(GAME));
        
        if (newGame.canJ) {
            makeJump(i, &newGame);
        }else{
            makeMove(i, &newGame);
        }
        
        changeTurn(&newGame);
        cleanUp(&newGame);
        
        findJumpersForGame(&newGame);
        
        if (!newGame.canJ) {
            findMoversForGame(&newGame);
        }
        
        
        int tempScore = scoreGames(orgGame, &newGame);
       
        if(tempScore > bestIndexScore){
            bestIndexScore = tempScore;
            bestIndex = i;
            f++;

        }else{
            
            if(tempScore == bestIndexScore){
                if(rand()%2 == 0){
                    bestIndexScore = tempScore;
                    bestIndex = i;
                }
                f++;

            }else{
                f--;

            }
            
        }
        
        
        
        if(f > 0 && d > 0){
            bestMJ(orgGame, &newGame, d-1, f);
        }
        
        
    }

    return bestIndex;
}