/ Check-in [3e8a07dd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Register-ify the OP_AddImm and all casting opcodes. Omit the OP_MemIncr opcode. (CVS 4683)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3e8a07dd3cc9921ad39e379576abb0b485a42202
User & Date: drh 2008-01-05 05:20:10
Context
2008-01-05
05:38
Register-ify the OP_ForceInt opcode. (CVS 4684) check-in: 32380dca user: drh tags: trunk
05:20
Register-ify the OP_AddImm and all casting opcodes. Omit the OP_MemIncr opcode. (CVS 4683) check-in: 3e8a07dd user: drh tags: trunk
04:06
Get rid of OP_Dup, OP_MemStore, OP_MemLoad, and OP_MemMove. Replace with OP_Copy, OP_SCopy, and OP_Move. Add the infrastructure for operation properties in1, in2, in3, out2, and out3 but do not yet use any of these. (CVS 4682) check-in: cc149eb9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code associated with the ANALYZE command.
    13     13   **
    14         -** @(#) $Id: analyze.c,v 1.32 2008/01/05 04:06:04 drh Exp $
           14  +** @(#) $Id: analyze.c,v 1.33 2008/01/05 05:20:10 drh Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_ANALYZE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This routine generates code that opens the sqlite_stat1 table on cursor
    21     21   ** iStatCur.
................................................................................
   151    151       }
   152    152   
   153    153       /* Do the analysis.
   154    154       */
   155    155       endOfLoop = sqlite3VdbeMakeLabel(v);
   156    156       sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
   157    157       topOfLoop = sqlite3VdbeCurrentAddr(v);
   158         -    sqlite3VdbeAddOp2(v, OP_MemIncr, 1, iMem);
          158  +    sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
   159    159       for(i=0; i<nCol; i++){
   160    160         sqlite3VdbeAddOp2(v, OP_Column, iIdxCur, i);
   161    161         sqlite3VdbeAddOp1(v, OP_SCopy, iMem+nCol+i+1);
   162    162         sqlite3VdbeAddOp1(v, OP_Ne, 0x100);
   163    163       }
   164    164       sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
   165    165       for(i=0; i<nCol; i++){
   166         -      addr = sqlite3VdbeAddOp2(v, OP_MemIncr, 1, iMem+i+1);
          166  +      addr = sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
   167    167         sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
   168    168         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
   169    169       }
   170    170       sqlite3VdbeResolveLabel(v, endOfLoop);
   171    171       sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
   172    172       sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
   173    173   
................................................................................
   196    196       sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pIdx->zName, 0);
   197    197       sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
   198    198       sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, " ", 0);
   199    199       for(i=0; i<nCol; i++){
   200    200         sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
   201    201         sqlite3VdbeAddOp1(v, OP_SCopy, iMem+i+1);
   202    202         sqlite3VdbeAddOp0(v, OP_Add);
   203         -      sqlite3VdbeAddOp1(v, OP_AddImm, -1);
          203  +      sqlite3VdbeAddOp2(v, OP_AddImm, 0, -1);
   204    204         sqlite3VdbeAddOp1(v, OP_SCopy, iMem+i+1);
   205    205         sqlite3VdbeAddOp0(v, OP_Divide);
   206    206         sqlite3VdbeAddOp0(v, OP_ToInt);
   207    207         if( i==nCol-1 ){
   208    208           sqlite3VdbeAddOp1(v, OP_Concat, nCol*2-1);
   209    209         }else{
   210    210           sqlite3VdbeAddOp1(v, OP_Copy, -1);

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.458 2008/01/05 04:06:04 drh Exp $
           25  +** $Id: build.c,v 1.459 2008/01/05 05:20:10 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
  2248   2248     addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
  2249   2249     sqlite3GenerateIndexKey(v, pIndex, iTab);
  2250   2250     if( pIndex->onError!=OE_None ){
  2251   2251       int curaddr = sqlite3VdbeCurrentAddr(v);
  2252   2252       int addr2 = curaddr+4;
  2253   2253       sqlite3VdbeChangeP2(v, curaddr-1, addr2);
  2254   2254       sqlite3VdbeAddOp1(v, OP_Rowid, iTab);
  2255         -    sqlite3VdbeAddOp1(v, OP_AddImm, 1);
         2255  +    sqlite3VdbeAddOp2(v, OP_AddImm, 0, 1);
  2256   2256       sqlite3VdbeAddOp2(v, OP_IsUnique, iIdx, addr2);
  2257   2257       sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, OE_Abort, 0,
  2258   2258                       "indexed columns are not unique", P4_STATIC);
  2259   2259       assert( db->mallocFailed || addr2==sqlite3VdbeCurrentAddr(v) );
  2260   2260     }
  2261   2261     sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, 0);
  2262   2262     sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);

Changes to src/delete.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** in order to generate code for DELETE FROM statements.
    14     14   **
    15         -** $Id: delete.c,v 1.149 2008/01/05 04:06:04 drh Exp $
           15  +** $Id: delete.c,v 1.150 2008/01/05 05:20:10 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Look up every table that is named in pSrc.  If any table is not found,
    21     21   ** add an error message to pParse->zErrMsg and return NULL.  If all tables
    22     22   ** are found, return a pointer to the last table.
................................................................................
   286    286         /* If counting rows deleted, just count the total number of
   287    287         ** entries in the table. */
   288    288         int addr2;
   289    289         if( !isView ){
   290    290           sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
   291    291         }
   292    292         sqlite3VdbeAddOp2(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
   293         -      addr2 = sqlite3VdbeAddOp2(v, OP_MemIncr, 1, memCnt);
          293  +      addr2 = sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
   294    294         sqlite3VdbeAddOp2(v, OP_Next, iCur, addr2);
   295    295         sqlite3VdbeAddOp1(v, OP_Close, iCur);
   296    296       }
   297    297       if( !isView ){
   298    298         sqlite3VdbeAddOp2(v, OP_Clear, pTab->tnum, iDb);
   299    299         if( !pParse->nested ){
   300    300           sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
................................................................................
   317    317       if( pWInfo==0 ) goto delete_from_cleanup;
   318    318   
   319    319       /* Remember the rowid of every item to be deleted.
   320    320       */
   321    321       sqlite3VdbeAddOp2(v, IsVirtual(pTab) ? OP_VRowid : OP_Rowid, iCur, iRowid);
   322    322       sqlite3VdbeAddOp1(v, OP_FifoWrite, iRowid);
   323    323       if( db->flags & SQLITE_CountRows ){
   324         -      sqlite3VdbeAddOp2(v, OP_MemIncr, 1, memCnt);
          324  +      sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
   325    325       }
   326    326   
   327    327       /* End the database scan loop.
   328    328       */
   329    329       sqlite3WhereEnd(pWInfo);
   330    330   
   331    331       /* Open the pseudo-table used to store OLD if there are triggers.

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.331 2008/01/05 04:06:04 drh Exp $
           15  +** $Id: expr.c,v 1.332 2008/01/05 05:20:10 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
  2123   2123         int dest;
  2124   2124         assert( TK_ISNULL==OP_IsNull );
  2125   2125         assert( TK_NOTNULL==OP_NotNull );
  2126   2126         sqlite3VdbeAddOp1(v, OP_Integer, 1);
  2127   2127         sqlite3ExprCode(pParse, pExpr->pLeft, 0);
  2128   2128         dest = sqlite3VdbeCurrentAddr(v) + 2;
  2129   2129         sqlite3VdbeAddOp2(v, op, 1, dest);
  2130         -      sqlite3VdbeAddOp1(v, OP_AddImm, -1);
         2130  +      sqlite3VdbeAddOp2(v, OP_AddImm, 0, -1);
  2131   2131         stackChng = 0;
  2132   2132         break;
  2133   2133       }
  2134   2134       case TK_AGG_FUNCTION: {
  2135   2135         AggInfo *pInfo = pExpr->pAggInfo;
  2136   2136         if( pInfo==0 ){
  2137   2137           sqlite3ErrorMsg(pParse, "misuse of aggregate: %T",
................................................................................
  2238   2238           sqlite3VdbeAddOp2(v, OP_NotExists, pExpr->iTable, iAddr);
  2239   2239           sqlite3VdbeAddOp2(v, OP_Goto, pExpr->iTable, iLabel);
  2240   2240         }else{
  2241   2241           sqlite3VdbeAddOp4(v, OP_MakeRecord, 1, 0, 0,
  2242   2242                                &affinity, 1);   /* addr + 4 */
  2243   2243           sqlite3VdbeAddOp2(v, OP_Found, pExpr->iTable, iLabel);
  2244   2244         }
  2245         -      sqlite3VdbeAddOp1(v, OP_AddImm, -1);                     /* addr + 6 */
         2245  +      sqlite3VdbeAddOp2(v, OP_AddImm, 0, -1);                  /* addr + 6 */
  2246   2246         sqlite3VdbeResolveLabel(v, iLabel);
  2247   2247   
  2248   2248         break;
  2249   2249       }
  2250   2250   #endif
  2251   2251       case TK_BETWEEN: {
  2252   2252         Expr *pLeft = pExpr->pLeft;

Changes to src/insert.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle INSERT statements in SQLite.
    14     14   **
    15         -** $Id: insert.c,v 1.212 2008/01/05 04:06:04 drh Exp $
           15  +** $Id: insert.c,v 1.213 2008/01/05 05:20:10 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Set P4 of the most recently inserted opcode to a column affinity
    21     21   ** string for index pIdx. A column affinity string has one character
    22     22   ** for each column in the table, according to the affinity of the column:
................................................................................
   818    818                               appendFlag);
   819    819       }
   820    820     }
   821    821   
   822    822     /* Update the count of rows that are inserted
   823    823     */
   824    824     if( (db->flags & SQLITE_CountRows)!=0 ){
   825         -    sqlite3VdbeAddOp2(v, OP_MemIncr, 1, iCntMem);
          825  +    sqlite3VdbeAddOp2(v, OP_AddImm, iCntMem, 1);
   826    826     }
   827    827   
   828    828     if( triggers_exist ){
   829    829       /* Code AFTER triggers */
   830    830       if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_AFTER, pTab,
   831    831             newIdx, -1, onError, endOfLoop, 0, 0) ){
   832    832         goto insert_cleanup;

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.159 2008/01/05 04:06:04 drh Exp $
           14  +** $Id: pragma.c,v 1.160 2008/01/05 05:20:10 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include <ctype.h>
    18     18   
    19     19   /* Ignore this whole file if pragmas are disabled
    20     20   */
    21     21   #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
................................................................................
   491    491       if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
   492    492         iLimit = 0x7fffffff;
   493    493       }
   494    494       sqlite3BeginWriteOperation(pParse, 0, iDb);
   495    495       sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
   496    496       addr = sqlite3VdbeAddOp2(v, OP_IncrVacuum, iDb, 0);
   497    497       sqlite3VdbeAddOp2(v, OP_Callback, 0, 0);
   498         -    sqlite3VdbeAddOp2(v, OP_MemIncr, -1, 1);
          498  +    sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
   499    499       sqlite3VdbeAddOp2(v, OP_IfMemPos, 1, addr);
   500    500       sqlite3VdbeJumpHere(v, addr);
   501    501     }else
   502    502   #endif
   503    503   
   504    504   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
   505    505     /*
................................................................................
   901    901           if( pTab->pIndex==0 ) continue;
   902    902           addr = sqlite3VdbeAddOp2(v, OP_IfMemPos, 1, 0);
   903    903           sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
   904    904           sqlite3VdbeJumpHere(v, addr);
   905    905           sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
   906    906           sqlite3VdbeAddOp2(v, OP_Integer, 0, 2);
   907    907           loopTop = sqlite3VdbeAddOp2(v, OP_Rewind, 1, 0);
   908         -        sqlite3VdbeAddOp2(v, OP_MemIncr, 1, 2);
          908  +        sqlite3VdbeAddOp2(v, OP_AddImm, 2, 1);
   909    909           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   910    910             int jmp2;
   911    911             static const VdbeOpList idxErr[] = {
   912         -            { OP_MemIncr,    -1,  1,  0},
          912  +            { OP_AddImm,      1, -1,  0},
   913    913               { OP_String8,     0,  0,  0},    /* 1 */
   914    914               { OP_Rowid,       1,  0,  0},
   915    915               { OP_String8,     0,  0,  0},    /* 3 */
   916    916               { OP_String8,     0,  0,  0},    /* 4 */
   917    917               { OP_Concat,      2,  0,  0},
   918    918               { OP_Callback,    1,  0,  0},
   919    919             };
................................................................................
   927    927           }
   928    928           sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
   929    929           sqlite3VdbeJumpHere(v, loopTop);
   930    930           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   931    931             static const VdbeOpList cntIdx[] = {
   932    932                { OP_Integer,      0,  3,  0},
   933    933                { OP_Rewind,       0,  0,  0},  /* 1 */
   934         -             { OP_MemIncr,      1,  3,  0},
          934  +             { OP_AddImm,       3,  1,  0},
   935    935                { OP_Next,         0,  0,  0},  /* 3 */
   936    936                { OP_SCopy,        2,  0,  0},
   937    937                { OP_SCopy,        3,  0,  0},
   938    938                { OP_Eq,           0,  0,  0},  /* 6 */
   939         -             { OP_MemIncr,     -1,  1,  0},
          939  +             { OP_AddImm,       1, -1,  0},
   940    940                { OP_String8,      0,  0,  0},  /* 8 */
   941    941                { OP_String8,      0,  0,  0},  /* 9 */
   942    942                { OP_Concat,       0,  0,  0},
   943    943                { OP_Callback,     1,  0,  0},
   944    944             };
   945    945             if( pIdx->tnum==0 ) continue;
   946    946             addr = sqlite3VdbeAddOp2(v, OP_IfMemPos, 1, 0);

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.385 2008/01/05 04:06:04 drh Exp $
           15  +** $Id: select.c,v 1.386 2008/01/05 05:20:10 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
   391    391     sqlite3VdbeAddOp2(v, OP_Sequence, pOrderBy->iECursor, 0);
   392    392     sqlite3VdbeAddOp2(v, OP_Pull, pOrderBy->nExpr + 1, 0);
   393    393     sqlite3VdbeAddOp2(v, OP_MakeRecord, pOrderBy->nExpr + 2, 0);
   394    394     sqlite3VdbeAddOp2(v, OP_IdxInsert, pOrderBy->iECursor, 0);
   395    395     if( pSelect->iLimit>=0 ){
   396    396       int addr1, addr2;
   397    397       addr1 = sqlite3VdbeAddOp2(v, OP_IfMemZero, pSelect->iLimit+1, 0);
   398         -    sqlite3VdbeAddOp2(v, OP_MemIncr, -1, pSelect->iLimit+1);
          398  +    sqlite3VdbeAddOp2(v, OP_AddImm, pSelect->iLimit+1, -1);
   399    399       addr2 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
   400    400       sqlite3VdbeJumpHere(v, addr1);
   401    401       sqlite3VdbeAddOp2(v, OP_Last, pOrderBy->iECursor, 0);
   402    402       sqlite3VdbeAddOp2(v, OP_Delete, pOrderBy->iECursor, 0);
   403    403       sqlite3VdbeJumpHere(v, addr2);
   404    404       pSelect->iLimit = -1;
   405    405     }
................................................................................
   412    412     Vdbe *v,          /* Generate code into this VM */
   413    413     Select *p,        /* The SELECT statement being coded */
   414    414     int iContinue,    /* Jump here to skip the current record */
   415    415     int nPop          /* Number of times to pop stack when jumping */
   416    416   ){
   417    417     if( p->iOffset>=0 && iContinue!=0 ){
   418    418       int addr;
   419         -    sqlite3VdbeAddOp2(v, OP_MemIncr, -1, p->iOffset);
          419  +    sqlite3VdbeAddOp2(v, OP_AddImm, p->iOffset, -1);
   420    420       addr = sqlite3VdbeAddOp2(v, OP_IfMemNeg, p->iOffset, 0);
   421    421       if( nPop>0 ){
   422    422         sqlite3VdbeAddOp2(v, OP_Pop, nPop, 0);
   423    423       }
   424    424       sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
   425    425       VdbeComment((v, "skip OFFSET records"));
   426    426       sqlite3VdbeJumpHere(v, addr);
................................................................................
   699    699       }
   700    700   #endif
   701    701     }
   702    702   
   703    703     /* Jump to the end of the loop if the LIMIT is reached.
   704    704     */
   705    705     if( p->iLimit>=0 && pOrderBy==0 ){
   706         -    sqlite3VdbeAddOp2(v, OP_MemIncr, -1, p->iLimit);
          706  +    sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
   707    707       sqlite3VdbeAddOp2(v, OP_IfMemZero, p->iLimit, iBreak);
   708    708     }
   709    709     return 0;
   710    710   }
   711    711   
   712    712   /*
   713    713   ** Given an expression list, generate a KeyInfo structure that records
................................................................................
   830    830         break;
   831    831       }
   832    832     }
   833    833   
   834    834     /* Jump to the end of the loop when the LIMIT is reached
   835    835     */
   836    836     if( p->iLimit>=0 ){
   837         -    sqlite3VdbeAddOp2(v, OP_MemIncr, -1, p->iLimit);
          837  +    sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
   838    838       sqlite3VdbeAddOp2(v, OP_IfMemZero, p->iLimit, brk);
   839    839     }
   840    840   
   841    841     /* The bottom of the loop
   842    842     */
   843    843     sqlite3VdbeResolveLabel(v, cont);
   844    844     sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);

Changes to src/update.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle UPDATE statements.
    14     14   **
    15         -** $Id: update.c,v 1.159 2008/01/05 04:06:04 drh Exp $
           15  +** $Id: update.c,v 1.160 2008/01/05 05:20:10 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   #ifndef SQLITE_OMIT_VIRTUALTABLE
    20     20   /* Forward declaration */
    21     21   static void updateVirtualTable(
    22     22     Parse *pParse,       /* The parsing context */
................................................................................
   502    502       */
   503    503       sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRowid, 1, -1, 0);
   504    504     }
   505    505   
   506    506     /* Increment the row counter 
   507    507     */
   508    508     if( db->flags & SQLITE_CountRows && !pParse->trigStack){
   509         -    sqlite3VdbeAddOp2(v, OP_MemIncr, 1, memCnt);
          509  +    sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
   510    510     }
   511    511   
   512    512     /* If there are triggers, close all the cursors after each iteration
   513    513     ** through the loop.  The fire the after triggers.
   514    514     */
   515    515     if( triggers_exist ){
   516    516       sqlite3VdbeAddOp2(v, OP_Goto, 0, iBeginAfterTrigger);

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.680 2008/01/05 04:06:04 drh Exp $
           46  +** $Id: vdbe.c,v 1.681 2008/01/05 05:20:10 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
  1596   1596     pTos--;
  1597   1597     Release(pTos);
  1598   1598     pTos->u.i = a;
  1599   1599     pTos->flags = MEM_Int;
  1600   1600     break;
  1601   1601   }
  1602   1602   
  1603         -/* Opcode: AddImm  P1 * *
         1603  +/* Opcode: AddImm  P1 P2 * * *
  1604   1604   ** 
  1605         -** Add the value P1 to whatever is on top of the stack.  The result
  1606         -** is always an integer.
         1605  +** Add P2 the value in register P1.
         1606  +** The result is always an integer.
  1607   1607   **
  1608         -** To force the top of the stack to be an integer, just add 0.
         1608  +** To force any register to be an integer, just add 0.
  1609   1609   */
  1610         -case OP_AddImm: {            /* no-push */
  1611         -  assert( pTos>=p->aStack );
  1612         -  sqlite3VdbeMemIntegerify(pTos);
  1613         -  pTos->u.i += pOp->p1;
         1610  +case OP_AddImm: {            /* no-push, in1 */
         1611  +  nPop = 0;
         1612  +  sqlite3VdbeMemIntegerify(pIn1);
         1613  +  pIn1->u.i += pOp->p2;
  1614   1614     break;
  1615   1615   }
  1616   1616   
  1617   1617   /* Opcode: ForceInt P1 P2 *
  1618   1618   **
  1619   1619   ** Convert the top of the stack into an integer.  If the current top of
  1620   1620   ** the stack is not numeric (meaning that is is a NULL or a string that
................................................................................
  1679   1679     }else{
  1680   1680       Release(pMem);
  1681   1681       pMem->flags = MEM_Int;
  1682   1682     }
  1683   1683     break;
  1684   1684   }
  1685   1685   
  1686         -/* Opcode: RealAffinity P1 * *
         1686  +/* Opcode: RealAffinity P1 * * * *
  1687   1687   **
  1688   1688   ** If register P1 holds an integer convert it to a real value.
  1689   1689   **
  1690   1690   ** This opcode is used when extracting information from a column that
  1691   1691   ** has REAL affinity.  Such column values may still be stored as
  1692   1692   ** integers, for space efficiency, but after extraction we want them
  1693   1693   ** to have only a real value.
  1694   1694   */
  1695         -case OP_RealAffinity: {                  /* no-push */
  1696         -  assert( pOp->p1>=0 && pOp->p1<=p->nMem );
  1697         -  if( pOp->p1==0 ){
  1698         -    if( pTos->flags & MEM_Int ){
  1699         -      sqlite3VdbeMemRealify(pTos);
  1700         -    }
  1701         -  }else{
  1702         -    Mem *pX = &p->aMem[pOp->p1];
  1703         -    if( pX->flags & MEM_Int ){
  1704         -      sqlite3VdbeMemRealify(pX);
  1705         -    }
         1695  +case OP_RealAffinity: {                  /* no-push, in1 */
         1696  +  nPop = 0;
         1697  +  if( pIn1->flags & MEM_Int ){
         1698  +    sqlite3VdbeMemRealify(pIn1);
  1706   1699     }
  1707   1700     break;
  1708   1701   }
  1709   1702   
  1710   1703   #ifndef SQLITE_OMIT_CAST
  1711         -/* Opcode: ToText * * *
         1704  +/* Opcode: ToText P1 * * * *
  1712   1705   **
  1713         -** Force the value on the top of the stack to be text.
         1706  +** Force the value in register P1 to be text.
  1714   1707   ** If the value is numeric, convert it to a string using the
  1715   1708   ** equivalent of printf().  Blob values are unchanged and
  1716   1709   ** are afterwards simply interpreted as text.
  1717   1710   **
  1718   1711   ** A NULL value is not changed by this routine.  It remains NULL.
  1719   1712   */
  1720         -case OP_ToText: {                  /* same as TK_TO_TEXT, no-push */
  1721         -  assert( pTos>=p->aStack );
  1722         -  if( pTos->flags & MEM_Null ) break;
         1713  +case OP_ToText: {                  /* same as TK_TO_TEXT, no-push, in1 */
         1714  +  nPop = 0;
         1715  +  if( pIn1->flags & MEM_Null ) break;
  1723   1716     assert( MEM_Str==(MEM_Blob>>3) );
  1724         -  pTos->flags |= (pTos->flags&MEM_Blob)>>3;
  1725         -  applyAffinity(pTos, SQLITE_AFF_TEXT, encoding);
  1726         -  rc = ExpandBlob(pTos);
  1727         -  assert( pTos->flags & MEM_Str );
  1728         -  pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob);
         1717  +  pIn1->flags |= (pIn1->flags&MEM_Blob)>>3;
         1718  +  applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
         1719  +  rc = ExpandBlob(pIn1);
         1720  +  assert( pIn1->flags & MEM_Str );
         1721  +  pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Blob);
  1729   1722     break;
  1730   1723   }
  1731   1724   
  1732         -/* Opcode: ToBlob * * *
         1725  +/* Opcode: ToBlob P1 * * * *
  1733   1726   **
  1734         -** Force the value on the top of the stack to be a BLOB.
         1727  +** Force the value in register P1 to be a BLOB.
  1735   1728   ** If the value is numeric, convert it to a string first.
  1736   1729   ** Strings are simply reinterpreted as blobs with no change
  1737   1730   ** to the underlying data.
  1738   1731   **
  1739   1732   ** A NULL value is not changed by this routine.  It remains NULL.
  1740   1733   */
  1741         -case OP_ToBlob: {                  /* same as TK_TO_BLOB, no-push */
  1742         -  assert( pTos>=p->aStack );
  1743         -  if( pTos->flags & MEM_Null ) break;
  1744         -  if( (pTos->flags & MEM_Blob)==0 ){
  1745         -    applyAffinity(pTos, SQLITE_AFF_TEXT, encoding);
  1746         -    assert( pTos->flags & MEM_Str );
  1747         -    pTos->flags |= MEM_Blob;
         1734  +case OP_ToBlob: {                  /* same as TK_TO_BLOB, no-push, in1 */
         1735  +  nPop = 0;
         1736  +  if( pIn1->flags & MEM_Null ) break;
         1737  +  if( (pIn1->flags & MEM_Blob)==0 ){
         1738  +    applyAffinity(pIn1, SQLITE_AFF_TEXT, encoding);
         1739  +    assert( pIn1->flags & MEM_Str );
         1740  +    pIn1->flags |= MEM_Blob;
  1748   1741     }
  1749         -  pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Str);
         1742  +  pIn1->flags &= ~(MEM_Int|MEM_Real|MEM_Str);
  1750   1743     break;
  1751   1744   }
  1752   1745   
  1753         -/* Opcode: ToNumeric * * *
         1746  +/* Opcode: ToNumeric P1 * * * *
  1754   1747   **
  1755         -** Force the value on the top of the stack to be numeric (either an
         1748  +** Force the value in register P1 to be numeric (either an
  1756   1749   ** integer or a floating-point number.)
  1757   1750   ** If the value is text or blob, try to convert it to an using the
  1758   1751   ** equivalent of atoi() or atof() and store 0 if no such conversion 
  1759   1752   ** is possible.
  1760   1753   **
  1761   1754   ** A NULL value is not changed by this routine.  It remains NULL.
  1762   1755   */
  1763         -case OP_ToNumeric: {                  /* same as TK_TO_NUMERIC, no-push */
  1764         -  assert( pTos>=p->aStack );
  1765         -  if( (pTos->flags & (MEM_Null|MEM_Int|MEM_Real))==0 ){
  1766         -    sqlite3VdbeMemNumerify(pTos);
         1756  +case OP_ToNumeric: {                  /* same as TK_TO_NUMERIC, no-push, in1 */
         1757  +  nPop = 0;
         1758  +  if( (pIn1->flags & (MEM_Null|MEM_Int|MEM_Real))==0 ){
         1759  +    sqlite3VdbeMemNumerify(pIn1);
  1767   1760     }
  1768   1761     break;
  1769   1762   }
  1770   1763   #endif /* SQLITE_OMIT_CAST */
  1771   1764   
  1772         -/* Opcode: ToInt * * *
         1765  +/* Opcode: ToInt P1 * * * *
  1773   1766   **
  1774         -** Force the value on the top of the stack to be an integer.  If
         1767  +** Force the value in register P1 be an integer.  If
  1775   1768   ** The value is currently a real number, drop its fractional part.
  1776   1769   ** If the value is text or blob, try to convert it to an integer using the
  1777   1770   ** equivalent of atoi() and store 0 if no such conversion is possible.
  1778   1771   **
  1779   1772   ** A NULL value is not changed by this routine.  It remains NULL.
  1780   1773   */
  1781         -case OP_ToInt: {                  /* same as TK_TO_INT, no-push */
  1782         -  assert( pTos>=p->aStack );
  1783         -  if( (pTos->flags & MEM_Null)==0 ){
  1784         -    sqlite3VdbeMemIntegerify(pTos);
         1774  +case OP_ToInt: {                  /* same as TK_TO_INT, no-push, in1 */
         1775  +  nPop = 0;
         1776  +  if( (pIn1->flags & MEM_Null)==0 ){
         1777  +    sqlite3VdbeMemIntegerify(pIn1);
  1785   1778     }
  1786   1779     break;
  1787   1780   }
  1788   1781   
  1789   1782   #ifndef SQLITE_OMIT_CAST
  1790         -/* Opcode: ToReal * * *
         1783  +/* Opcode: ToReal P1 * * * *
  1791   1784   **
  1792         -** Force the value on the top of the stack to be a floating point number.
         1785  +** Force the value in register P1 to be a floating point number.
  1793   1786   ** If The value is currently an integer, convert it.
  1794   1787   ** If the value is text or blob, try to convert it to an integer using the
  1795   1788   ** equivalent of atoi() and store 0 if no such conversion is possible.
  1796   1789   **
  1797   1790   ** A NULL value is not changed by this routine.  It remains NULL.
  1798   1791   */
  1799         -case OP_ToReal: {                  /* same as TK_TO_REAL, no-push */
  1800         -  assert( pTos>=p->aStack );
  1801         -  if( (pTos->flags & MEM_Null)==0 ){
  1802         -    sqlite3VdbeMemRealify(pTos);
         1792  +case OP_ToReal: {                  /* same as TK_TO_REAL, no-push, in1 */
         1793  +  nPop = 0;
         1794  +  if( (pIn1->flags & MEM_Null)==0 ){
         1795  +    sqlite3VdbeMemRealify(pIn1);
  1803   1796     }
  1804   1797     break;
  1805   1798   }
  1806   1799   #endif /* SQLITE_OMIT_CAST */
  1807   1800   
  1808   1801   /* Opcode: Eq P1 P2 P4
  1809   1802   **
................................................................................
  4751   4744     if( pMem->u.i<pNew->u.i){
  4752   4745       pMem->u.i = pNew->u.i;
  4753   4746     }
  4754   4747     break;
  4755   4748   }
  4756   4749   #endif /* SQLITE_OMIT_AUTOINCREMENT */
  4757   4750   
  4758         -/* Opcode: MemIncr P1 P2 *
  4759         -**
  4760         -** Increment the integer valued memory cell P2 by the value in P1.
  4761         -**
  4762         -** It is illegal to use this instruction on a memory cell that does
  4763         -** not contain an integer.  An assertion fault will result if you try.
  4764         -*/
  4765         -case OP_MemIncr: {        /* no-push */
  4766         -  int i = pOp->p2;
  4767         -  Mem *pMem;
  4768         -  assert( i>0 && i<=p->nMem );
  4769         -  pMem = &p->aMem[i];
  4770         -  assert( pMem->flags==MEM_Int );
  4771         -  pMem->u.i += pOp->p1;
  4772         -  break;
  4773         -}
  4774         -
  4775   4751   /* Opcode: IfMemPos P1 P2 *
  4776   4752   **
  4777   4753   ** If the value of memory cell P1 is 1 or greater, jump to P2.
  4778   4754   **
  4779   4755   ** It is illegal to use this instruction on a memory cell that does
  4780   4756   ** not contain an integer.  An assertion fault will result if you try.
  4781   4757   */

Changes to src/vdbeaux.c.

   351    351       int i;
   352    352       VdbeOpList const *pIn = aOp;
   353    353       for(i=0; i<nOp; i++, pIn++){
   354    354         int p2 = pIn->p2;
   355    355         VdbeOp *pOut = &p->aOp[i+addr];
   356    356         pOut->opcode = pIn->opcode;
   357    357         pOut->p1 = pIn->p1;
   358         -      pOut->p2 = p2<0 ? addr + ADDR(p2) : p2;
          358  +      if( p2<0 && sqlite3VdbeOpcodeHasProperty(pOut->opcode, OPFLG_JUMP) ){
          359  +        pOut->p2 = addr + ADDR(p2);
          360  +      }else{
          361  +        pOut->p2 = p2;
          362  +      }
   359    363         pOut->p3 = pIn->p3;
   360    364         pOut->p4type = P4_NOTUSED;
   361    365         pOut->p4.p = 0;
   362    366         pOut->p5 = 0;
   363    367   #ifdef SQLITE_DEBUG
   364    368         if( sqlite3_vdbe_addop_trace ){
   365    369           sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);