sourcepawn/compiler/sc4.c
author David Anderson <dvander@alliedmods.net>
Thu Jan 25 20:08:00 2007 +0000 (2007-01-25)
changeset 353 492a8d0d5f59
parent 200 37f529491240
child 365 d830b2b0414f
permissions -rw-r--r--
added linux support
     1 /*  Pawn compiler - code generation (unoptimized "assembler" code)
     2  *
     3  *  Copyright (c) ITB CompuPhase, 1997-2006
     4  *
     5  *  This software is provided "as-is", without any express or implied warranty.
     6  *  In no event will the authors be held liable for any damages arising from
     7  *  the use of this software.
     8  *
     9  *  Permission is granted to anyone to use this software for any purpose,
    10  *  including commercial applications, and to alter it and redistribute it
    11  *  freely, subject to the following restrictions:
    12  *
    13  *  1.  The origin of this software must not be misrepresented; you must not
    14  *      claim that you wrote the original software. If you use this software in
    15  *      a product, an acknowledgment in the product documentation would be
    16  *      appreciated but is not required.
    17  *  2.  Altered source versions must be plainly marked as such, and must not be
    18  *      misrepresented as being the original software.
    19  *  3.  This notice may not be removed or altered from any source distribution.
    20  *
    21  *  Version: $Id: sc4.c 3633 2006-08-11 16:20:18Z thiadmer $
    22  */
    23 #include <assert.h>
    24 #include <ctype.h>
    25 #include <stdio.h>
    26 #include <stdlib.h>     /* for _MAX_PATH */
    27 #include <string.h>
    28 #if defined FORTIFY
    29   #include <alloc/fortify.h>
    30 #endif
    31 #include "sc.h"
    32 
    33 static int fcurseg;     /* the file number (fcurrent) for the active segment */
    34 
    35 
    36 /* When a subroutine returns to address 0, the AMX must halt. In earlier
    37  * releases, the RET and RETN opcodes checked for the special case 0 address.
    38  * Today, the compiler simply generates a HALT instruction at address 0. So
    39  * a subroutine can savely return to 0, and then encounter a HALT.
    40  */
    41 SC_FUNC void writeleader(symbol *root)
    42 {
    43   int lbl_nostate,lbl_table;
    44   int statecount;
    45   symbol *sym;
    46   constvalue *fsa, *state, *stlist;
    47   int fsa_id,listid;
    48   char lbl_default[sNAMEMAX+1];
    49 
    50   assert(code_idx==0);
    51 
    52   begcseg();
    53   stgwrite(";program exit point\n");
    54   stgwrite("\thalt 0\n\n");
    55   code_idx+=opcodes(1)+opargs(1);       /* calculate code length */
    56 
    57   /* check whether there are any functions that have states */
    58   for (sym=root->next; sym!=NULL; sym=sym->next)
    59     if (sym->ident==iFUNCTN && (sym->usage & (uPUBLIC | uREAD))!=0 && sym->states!=NULL)
    60       break;
    61   if (sym==NULL)
    62     return;             /* no function has states, nothing to do next */
    63 
    64   /* generate an error function that is called for an undefined state */
    65   stgwrite("\n;exit point for functions called from the wrong state\n");
    66   lbl_nostate=getlabel();
    67   setlabel(lbl_nostate);
    68   stgwrite("\thalt ");
    69   outval(AMX_ERR_INVSTATE,TRUE);
    70   code_idx+=opcodes(1)+opargs(1);       /* calculate code length */
    71 
    72   /* write the "state-selectors" table with all automatons (update the
    73    * automatons structure too, as we are now assigning the address to
    74    * each automaton state-selector variable)
    75    */
    76   assert(glb_declared==0);
    77   begdseg();
    78   for (fsa=sc_automaton_tab.next; fsa!=NULL; fsa=fsa->next) {
    79     defstorage();
    80     stgwrite("0\t; automaton ");
    81     if (strlen(fsa->name)==0)
    82       stgwrite("(anonymous)");
    83     else
    84       stgwrite(fsa->name);
    85     stgwrite("\n");
    86     fsa->value=glb_declared*sizeof(cell);
    87     glb_declared++;
    88   } /* for */
    89 
    90   /* write stubs and jump tables for all state functions */
    91   begcseg();
    92   for (sym=root->next; sym!=NULL; sym=sym->next) {
    93     if (sym->ident==iFUNCTN && (sym->usage & (uPUBLIC | uREAD))!=0 && sym->states!=NULL) {
    94       stlist=sym->states->next;
    95       assert(stlist!=NULL);     /* there should be at least one state item */
    96       listid=stlist->index;
    97       assert(listid==-1 || listid>0);
    98       if (listid==-1 && stlist->next!=NULL) {
    99         /* first index is the "fallback", take the next one (if available) */
   100         stlist=stlist->next;
   101         listid=stlist->index;
   102       } /* if */
   103       if (listid==-1) {
   104         /* first index is the fallback, there is no second... */
   105         strcpy(stlist->name,"0"); /* insert dummy label number */
   106         /* this is an error, but we postpone adding the error message until the
   107          * function definition
   108          */
   109         continue;
   110       } /* if */
   111       /* generate label numbers for all statelist ids */
   112       for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
   113         assert(strlen(stlist->name)==0);
   114         strcpy(stlist->name,itoh(getlabel()));
   115       } /* for */
   116       if (strcmp(sym->name,uENTRYFUNC)==0)
   117         continue;               /* do not generate stubs for this special function */
   118       sym->addr=code_idx;       /* fix the function address now */
   119       /* get automaton id for this function */
   120       assert(listid>0);
   121       fsa_id=state_getfsa(listid);
   122       assert(fsa_id>=0);        /* automaton 0 exists */
   123       fsa=automaton_findid(fsa_id);
   124       /* count the number of states actually used; at the sane time, check
   125        * whether there is a default state function
   126        */
   127       statecount=0;
   128       strcpy(lbl_default,itoh(lbl_nostate));
   129       for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
   130         if (stlist->index==-1) {
   131           assert(strlen(stlist->name)<sizeof lbl_default);
   132           strcpy(lbl_default,stlist->name);
   133         } else {
   134           statecount+=state_count(stlist->index);
   135         } /* if */
   136       } /* for */
   137       /* generate a stub entry for the functions */
   138       stgwrite("\tload.pri ");
   139       outval(fsa->value,FALSE);
   140       stgwrite("\t; ");
   141       stgwrite(sym->name);
   142       stgwrite("\n");
   143       code_idx+=opcodes(1)+opargs(1);   /* calculate code length */
   144       lbl_table=getlabel();
   145       ffswitch(lbl_table);
   146       /* generate the jump table */
   147       setlabel(lbl_table);
   148       ffcase(statecount,lbl_default,TRUE);
   149       for (state=sc_state_tab.next; state!=NULL; state=state->next) {
   150         if (state->index==fsa_id) {
   151           /* find the label for this list id */
   152           for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
   153             if (stlist->index!=-1 && state_inlist(stlist->index,(int)state->value)) {
   154               ffcase(state->value,stlist->name,FALSE);
   155               break;
   156             } /* if */
   157           } /* for */
   158           if (stlist==NULL && strtol(lbl_default,NULL,16)==lbl_nostate)
   159             error(230,state->name,sym->name);  /* unimplemented state, no fallback */
   160         } /* if (state belongs to automaton of function) */
   161       } /* for (state) */
   162       stgwrite("\n");
   163     } /* if (is function, used & having states) */
   164   } /* for (sym) */
   165 }
   166 
   167 /*  writetrailer
   168  *  Not much left of this once important function.
   169  *
   170  *  Global references: pc_stksize       (referred to only)
   171  *                     sc_dataalign     (referred to only)
   172  *                     code_idx         (altered)
   173  *                     glb_declared     (altered)
   174  */
   175 SC_FUNC void writetrailer(void)
   176 {
   177   assert(sc_dataalign % opcodes(1) == 0);   /* alignment must be a multiple of
   178                                              * the opcode size */
   179   assert(sc_dataalign!=0);
   180 
   181   /* pad code to align data segment */
   182   if ((code_idx % sc_dataalign)!=0) {
   183     begcseg();
   184     while ((code_idx % sc_dataalign)!=0)
   185       nooperation();
   186   } /* if */
   187 
   188   /* pad data segment to align the stack and the heap */
   189   assert(litidx==0);            /* literal queue should have been emptied */
   190   assert(sc_dataalign % sizeof(cell) == 0);
   191   if (((glb_declared*sizeof(cell)) % sc_dataalign)!=0) {
   192     begdseg();
   193     defstorage();
   194     while (((glb_declared*sizeof(cell)) % sc_dataalign)!=0) {
   195       stgwrite("0 ");
   196       glb_declared++;
   197     } /* while */
   198   } /* if */
   199 
   200   stgwrite("\nSTKSIZE ");       /* write stack size (align stack top) */
   201   outval(pc_stksize - (pc_stksize % sc_dataalign), TRUE);
   202 }
   203 
   204 /*
   205  *  Start (or restart) the CODE segment.
   206  *
   207  *  In fact, the code and data segment specifiers are purely informational;
   208  *  the "DUMP" instruction itself already specifies that the following values
   209  *  should go to the data segment. All other instructions go to the code
   210  *  segment.
   211  *
   212  *  Global references: curseg
   213  *                     fcurrent
   214  */
   215 SC_FUNC void begcseg(void)
   216 {
   217   if (sc_status!=statSKIP && (curseg!=sIN_CSEG || fcurrent!=fcurseg)) {
   218     stgwrite("\n");
   219     stgwrite("CODE ");
   220     outval(fcurrent,FALSE);
   221     stgwrite("\t; ");
   222     outval(code_idx,TRUE);
   223     curseg=sIN_CSEG;
   224     fcurseg=fcurrent;
   225   } /* endif */
   226 }
   227 
   228 /*
   229  *  Start (or restart) the DATA segment.
   230  *
   231  *  Global references: curseg
   232  */
   233 SC_FUNC void begdseg(void)
   234 {
   235   if (sc_status!=statSKIP && (curseg!=sIN_DSEG || fcurrent!=fcurseg)) {
   236     stgwrite("\n");
   237     stgwrite("DATA ");
   238     outval(fcurrent,FALSE);
   239     stgwrite("\t; ");
   240     outval((glb_declared-litidx)*sizeof(cell),TRUE);
   241     curseg=sIN_DSEG;
   242     fcurseg=fcurrent;
   243   } /* if */
   244 }
   245 
   246 SC_FUNC void setline(int chkbounds)
   247 {
   248   if (sc_asmfile) {
   249     stgwrite("\t; line ");
   250     outval(fline,TRUE);
   251   } /* if */
   252   if ((sc_debug & sSYMBOLIC)!=0 || chkbounds && (sc_debug & sCHKBOUNDS)!=0) {
   253     /* generate a "break" (start statement) opcode rather than a "line" opcode
   254      * because earlier versions of Small/Pawn have an incompatible version of the
   255      * line opcode
   256      */
   257     stgwrite("\tbreak\t; ");
   258     outval(code_idx,TRUE);
   259     code_idx+=opcodes(1);
   260   } /* if */
   261 }
   262 
   263 SC_FUNC void setfiledirect(char *name)
   264 {
   265   if (sc_status==statFIRST && sc_listing) {
   266     assert(name!=NULL);
   267     pc_writeasm(outf,"#file ");
   268     pc_writeasm(outf,name);
   269     pc_writeasm(outf,"\n");
   270   } /* if */
   271 }
   272 
   273 SC_FUNC void setlinedirect(int line)
   274 {
   275   if (sc_status==statFIRST && sc_listing) {
   276     char string[40];
   277     sprintf(string,"#line %d\n",line);
   278     pc_writeasm(outf,string);
   279   } /* if */
   280 }
   281 
   282 /*  setlabel
   283  *
   284  *  Post a code label (specified as a number), on a new line.
   285  */
   286 SC_FUNC void setlabel(int number)
   287 {
   288   assert(number>=0);
   289   stgwrite("l.");
   290   stgwrite((char *)itoh(number));
   291   /* To assist verification of the assembled code, put the address of the
   292    * label as a comment. However, labels that occur inside an expression
   293    * may move (through optimization or through re-ordering). So write the
   294    * address only if it is known to accurate.
   295    */
   296   if (!staging) {
   297     stgwrite("\t\t; ");
   298     outval(code_idx,FALSE);
   299   } /* if */
   300   stgwrite("\n");
   301 }
   302 
   303 /* Write a token that signifies the start or end of an expression or special
   304  * statement. This allows several simple optimizations by the peephole
   305  * optimizer.
   306  */
   307 SC_FUNC void markexpr(optmark type,const char *name,cell offset)
   308 {
   309   switch (type) {
   310   case sEXPR:
   311     stgwrite("\t;$exp\n");
   312     break;
   313   case sPARM:
   314     stgwrite("\t;$par\n");
   315     break;
   316   case sLDECL:
   317     assert(name!=NULL);
   318     stgwrite("\t;$lcl ");
   319     stgwrite(name);
   320     stgwrite(" ");
   321     outval(offset,TRUE);
   322     break;
   323   default:
   324     assert(0);
   325   } /* switch */
   326 }
   327 
   328 /*  startfunc   - declare a CODE entry point (function start)
   329  *
   330  *  Global references: funcstatus  (referred to only)
   331  */
   332 SC_FUNC void startfunc(char *fname)
   333 {
   334   stgwrite("\tproc");
   335   if (sc_asmfile) {
   336     char symname[2*sNAMEMAX+16];
   337     funcdisplayname(symname,fname);
   338     stgwrite("\t; ");
   339     stgwrite(symname);
   340   } /* if */
   341   stgwrite("\n");
   342   code_idx+=opcodes(1);
   343 }
   344 
   345 /*  endfunc
   346  *
   347  *  Declare a CODE ending point (function end)
   348  */
   349 SC_FUNC void endfunc(void)
   350 {
   351   stgwrite("\n");       /* skip a line */
   352 }
   353 
   354 /*  alignframe
   355  *
   356  *  Aligns the frame (and the stack) of the current function to a multiple
   357  *  of the specified byte count. Two caveats: the alignment ("numbytes") should
   358  *  be a power of 2, and this alignment must be done right after the frame
   359  *  is set up (before the first variable is declared)
   360  */
   361 SC_FUNC void alignframe(int numbytes)
   362 {
   363   #if !defined NDEBUG
   364     /* "numbytes" should be a power of 2 for this code to work */
   365     int i,count=0;
   366     for (i=0; i<sizeof numbytes*8; i++)
   367       if (numbytes & (1 << i))
   368         count++;
   369     assert(count==1);
   370   #endif
   371 
   372   stgwrite("\tlctrl 4\n");      /* get STK in PRI */
   373   stgwrite("\tconst.alt ");     /* get ~(numbytes-1) in ALT */
   374   outval(~(numbytes-1),TRUE);
   375   stgwrite("\tand\n");          /* PRI = STK "and" ~(numbytes-1) */
   376   stgwrite("\tsctrl 4\n");      /* set the new value of STK ... */
   377   stgwrite("\tsctrl 5\n");      /* ... and FRM */
   378   code_idx+=opcodes(5)+opargs(4);
   379 }
   380 
   381 /*  rvalue
   382  *
   383  *  Generate code to get the value of a symbol into "primary".
   384  */
   385 SC_FUNC void rvalue(value *lval)
   386 {
   387   symbol *sym;
   388 
   389   sym=lval->sym;
   390   if (lval->ident==iARRAYCELL) {
   391     /* indirect fetch, address already in PRI */
   392     stgwrite("\tload.i\n");
   393     code_idx+=opcodes(1);
   394   } else if (lval->ident==iARRAYCHAR) {
   395     /* indirect fetch of a character from a pack, address already in PRI */
   396     stgwrite("\tlodb.i ");
   397     outval(sCHARBITS/8,TRUE);   /* read one or two bytes */
   398     code_idx+=opcodes(1)+opargs(1);
   399   } else if (lval->ident==iREFERENCE) {
   400     /* indirect fetch, but address not yet in PRI */
   401     assert(sym!=NULL);
   402     assert(sym->vclass==sLOCAL);/* global references don't exist in Pawn */
   403     if (sym->vclass==sLOCAL)
   404       stgwrite("\tlref.s.pri ");
   405     else
   406       stgwrite("\tlref.pri ");
   407     outval(sym->addr,TRUE);
   408     markusage(sym,uREAD);
   409     code_idx+=opcodes(1)+opargs(1);
   410   } else {
   411     /* direct or stack relative fetch */
   412     assert(sym!=NULL);
   413     if (sym->vclass==sLOCAL)
   414       stgwrite("\tload.s.pri ");
   415     else
   416       stgwrite("\tload.pri ");
   417     outval(sym->addr,TRUE);
   418     markusage(sym,uREAD);
   419     code_idx+=opcodes(1)+opargs(1);
   420   } /* if */
   421 }
   422 
   423 /* Get the address of a symbol into the primary or alternate register (used
   424  * for arrays, and for passing arguments by reference).
   425  */
   426 SC_FUNC void address(symbol *sym,regid reg)
   427 {
   428   assert(sym!=NULL);
   429   assert(reg==sPRI || reg==sALT);
   430   /* the symbol can be a local array, a global array, or an array
   431    * that is passed by reference.
   432    */
   433   if (sym->ident==iREFARRAY || sym->ident==iREFERENCE) {
   434     /* reference to a variable or to an array; currently this is
   435      * always a local variable */
   436     switch (reg) {
   437     case sPRI:
   438       stgwrite("\tload.s.pri ");
   439       break;
   440     case sALT:
   441       stgwrite("\tload.s.alt ");
   442       break;
   443     } /* switch */
   444   } else {
   445     /* a local array or local variable */
   446     switch (reg) {
   447     case sPRI:
   448       if (sym->vclass==sLOCAL)
   449         stgwrite("\taddr.pri ");
   450       else
   451         stgwrite("\tconst.pri ");
   452       break;
   453     case sALT:
   454       if (sym->vclass==sLOCAL)
   455         stgwrite("\taddr.alt ");
   456       else
   457         stgwrite("\tconst.alt ");
   458       break;
   459     } /* switch */
   460   } /* if */
   461   outval(sym->addr,TRUE);
   462   markusage(sym,uREAD);
   463   code_idx+=opcodes(1)+opargs(1);
   464 }
   465 
   466 /*  store
   467  *
   468  *  Saves the contents of "primary" into a memory cell, either directly
   469  *  or indirectly (at the address given in the alternate register).
   470  */
   471 SC_FUNC void store(value *lval)
   472 {
   473   symbol *sym;
   474 
   475   sym=lval->sym;
   476   if (lval->ident==iARRAYCELL) {
   477     /* store at address in ALT */
   478     stgwrite("\tstor.i\n");
   479     code_idx+=opcodes(1);
   480   } else if (lval->ident==iARRAYCHAR) {
   481     /* store at address in ALT */
   482     stgwrite("\tstrb.i ");
   483     outval(sCHARBITS/8,TRUE);   /* write one or two bytes */
   484     code_idx+=opcodes(1)+opargs(1);
   485   } else if (lval->ident==iREFERENCE) {
   486     assert(sym!=NULL);
   487     if (sym->vclass==sLOCAL)
   488       stgwrite("\tsref.s.pri ");
   489     else
   490       stgwrite("\tsref.pri ");
   491     outval(sym->addr,TRUE);
   492     code_idx+=opcodes(1)+opargs(1);
   493   } else {
   494     assert(sym!=NULL);
   495     markusage(sym,uWRITTEN);
   496     if (sym->vclass==sLOCAL)
   497       stgwrite("\tstor.s.pri ");
   498     else
   499       stgwrite("\tstor.pri ");
   500     outval(sym->addr,TRUE);
   501     code_idx+=opcodes(1)+opargs(1);
   502   } /* if */
   503 }
   504 
   505 /* Get a cell from a fixed address in memory */
   506 SC_FUNC void loadreg(cell address,regid reg)
   507 {
   508   assert(reg==sPRI || reg==sALT);
   509   if (reg==sPRI)
   510     stgwrite("\tload.pri ");
   511   else
   512     stgwrite("\tload.alt ");
   513   outval(address,TRUE);
   514   code_idx+=opcodes(1)+opargs(1);
   515 }
   516 
   517 /* Store a cell into a fixed address in memory */
   518 SC_FUNC void storereg(cell address,regid reg)
   519 {
   520   assert(reg==sPRI || reg==sALT);
   521   if (reg==sPRI)
   522     stgwrite("\tstor.pri ");
   523   else
   524     stgwrite("\tstor.alt ");
   525   outval(address,TRUE);
   526   code_idx+=opcodes(1)+opargs(1);
   527 }
   528 
   529 /* source must in PRI, destination address in ALT. The "size"
   530  * parameter is in bytes, not cells.
   531  */
   532 SC_FUNC void memcopy(cell size)
   533 {
   534   stgwrite("\tmovs ");
   535   outval(size,TRUE);
   536 
   537   code_idx+=opcodes(1)+opargs(1);
   538 }
   539 
   540 /* Address of the source must already have been loaded in PRI
   541  * "size" is the size in bytes (not cells).
   542  */
   543 SC_FUNC void copyarray(symbol *sym,cell size)
   544 {
   545   assert(sym!=NULL);
   546   /* the symbol can be a local array, a global array, or an array
   547    * that is passed by reference.
   548    */
   549   if (sym->ident==iREFARRAY) {
   550     /* reference to an array; currently this is always a local variable */
   551     assert(sym->vclass==sLOCAL);        /* symbol must be stack relative */
   552     stgwrite("\tload.s.alt ");
   553   } else {
   554     /* a local or global array */
   555     if (sym->vclass==sLOCAL)
   556       stgwrite("\taddr.alt ");
   557     else
   558       stgwrite("\tconst.alt ");
   559   } /* if */
   560   outval(sym->addr,TRUE);
   561   markusage(sym,uWRITTEN);
   562 
   563   code_idx+=opcodes(1)+opargs(1);
   564   memcopy(size);
   565 }
   566 
   567 SC_FUNC void fillarray(symbol *sym,cell size,cell value)
   568 {
   569   ldconst(value,sPRI);  /* load value in PRI */
   570 
   571   assert(sym!=NULL);
   572   /* the symbol can be a local array, a global array, or an array
   573    * that is passed by reference.
   574    */
   575   if (sym->ident==iREFARRAY) {
   576     /* reference to an array; currently this is always a local variable */
   577     assert(sym->vclass==sLOCAL);        /* symbol must be stack relative */
   578     stgwrite("\tload.s.alt ");
   579   } else {
   580     /* a local or global array */
   581     if (sym->vclass==sLOCAL)
   582       stgwrite("\taddr.alt ");
   583     else
   584       stgwrite("\tconst.alt ");
   585   } /* if */
   586   outval(sym->addr,TRUE);
   587   markusage(sym,uWRITTEN);
   588 
   589   assert(size>0);
   590   stgwrite("\tfill ");
   591   outval(size,TRUE);
   592 
   593   code_idx+=opcodes(2)+opargs(2);
   594 }
   595 
   596 SC_FUNC void stradjust(regid reg)
   597 {
   598   assert(reg==sPRI);
   599   stgwrite("\tstradjust.pri\n");
   600   code_idx+=opcodes(1);
   601 }
   602 
   603 /* Instruction to get an immediate value into the primary or the alternate
   604  * register
   605  */
   606 SC_FUNC void ldconst(cell val,regid reg)
   607 {
   608   assert(reg==sPRI || reg==sALT);
   609   switch (reg) {
   610   case sPRI:
   611     if (val==0) {
   612       stgwrite("\tzero.pri\n");
   613       code_idx+=opcodes(1);
   614     } else {
   615       stgwrite("\tconst.pri ");
   616       outval(val, TRUE);
   617       code_idx+=opcodes(1)+opargs(1);
   618     } /* if */
   619     break;
   620   case sALT:
   621     if (val==0) {
   622       stgwrite("\tzero.alt\n");
   623       code_idx+=opcodes(1);
   624     } else {
   625       stgwrite("\tconst.alt ");
   626       outval(val, TRUE);
   627       code_idx+=opcodes(1)+opargs(1);
   628     } /* if */
   629     break;
   630   } /* switch */
   631 }
   632 
   633 /* Copy value in alternate register to the primary register */
   634 SC_FUNC void moveto1(void)
   635 {
   636   stgwrite("\tmove.pri\n");
   637   code_idx+=opcodes(1)+opargs(0);
   638 }
   639 
   640 /* Push primary or the alternate register onto the stack
   641  */
   642 SC_FUNC void pushreg(regid reg)
   643 {
   644   assert(reg==sPRI || reg==sALT);
   645   switch (reg) {
   646   case sPRI:
   647     stgwrite("\tpush.pri\n");
   648     break;
   649   case sALT:
   650     stgwrite("\tpush.alt\n");
   651     break;
   652   } /* switch */
   653   code_idx+=opcodes(1);
   654 }
   655 
   656 /*
   657  *  Push a constant value onto the stack
   658  */
   659 SC_FUNC void pushval(cell val)
   660 {
   661   stgwrite("\tpush.c ");
   662   outval(val, TRUE);
   663   code_idx+=opcodes(1)+opargs(1);
   664 }
   665 
   666 /* Pop stack into the primary or the alternate register
   667  */
   668 SC_FUNC void popreg(regid reg)
   669 {
   670   assert(reg==sPRI || reg==sALT);
   671   switch (reg) {
   672   case sPRI:
   673     stgwrite("\tpop.pri\n");
   674     break;
   675   case sALT:
   676     stgwrite("\tpop.alt\n");
   677     break;
   678   } /* switch */
   679   code_idx+=opcodes(1);
   680 }
   681 
   682 /*
   683  * Generate an array
   684  */
   685 SC_FUNC void genarray(int dims, int _autozero)
   686 {
   687   if (_autozero) {
   688     stgwrite("\tgenarray.z ");
   689   } else {
   690     stgwrite("\tgenarray ");
   691   }
   692   outval(dims, TRUE);
   693   code_idx+=opcodes(1)+opargs(1);
   694 }
   695 
   696 /*
   697  *  swap the top-of-stack with the value in primary register
   698  */
   699 SC_FUNC void swap1(void)
   700 {
   701   stgwrite("\tswap.pri\n");
   702   code_idx+=opcodes(1);
   703 }
   704 
   705 /* Switch statements
   706  * The "switch" statement generates a "case" table using the "CASE" opcode.
   707  * The case table contains a list of records, each record holds a comparison
   708  * value and a label to branch to on a match. The very first record is an
   709  * exception: it holds the size of the table (excluding the first record) and
   710  * the label to branch to when none of the values in the case table match.
   711  * The case table is sorted on the comparison value. This allows more advanced
   712  * abstract machines to sift the case table with a binary search.
   713  */
   714 SC_FUNC void ffswitch(int label)
   715 {
   716   stgwrite("\tswitch ");
   717   outval(label,TRUE);           /* the label is the address of the case table */
   718   code_idx+=opcodes(1)+opargs(1);
   719 }
   720 
   721 SC_FUNC void ffcase(cell value,char *labelname,int newtable)
   722 {
   723   if (newtable) {
   724     stgwrite("\tcasetbl\n");
   725     code_idx+=opcodes(1);
   726   } /* if */
   727   stgwrite("\tcase ");
   728   outval(value,FALSE);
   729   stgwrite(" ");
   730   stgwrite(labelname);
   731   stgwrite("\n");
   732   code_idx+=opcodes(0)+opargs(2);
   733 }
   734 
   735 /*
   736  *  Call specified function
   737  */
   738 SC_FUNC void ffcall(symbol *sym,const char *label,int numargs)
   739 {
   740   char symname[2*sNAMEMAX+16];
   741 
   742   assert(sym!=NULL);
   743   assert(sym->ident==iFUNCTN);
   744   if (sc_asmfile)
   745     funcdisplayname(symname,sym->name);
   746   if ((sym->usage & uNATIVE)!=0) {
   747     /* reserve a SYSREQ id if called for the first time */
   748     assert(label==NULL);
   749     if (sc_status==statWRITE && (sym->usage & uREAD)==0 && sym->addr>=0)
   750       sym->addr=ntv_funcid++;
   751     stgwrite("\tsysreq.c ");
   752     outval(sym->addr,FALSE);
   753     if (sc_asmfile) {
   754       stgwrite("\t; ");
   755       stgwrite(symname);
   756     } /* if */
   757     stgwrite("\n"); /* write on a separate line, to mark a sequence point for the peephole optimizer */
   758     stgwrite("\tstack ");
   759     outval((numargs+1)*sizeof(cell), TRUE);
   760     code_idx+=opcodes(2)+opargs(2);
   761   } else {
   762     /* normal function */
   763     stgwrite("\tcall ");
   764     if (label!=NULL) {
   765       stgwrite("l.");
   766       stgwrite(label);
   767     } else {
   768       stgwrite(sym->name);
   769     } /* if */
   770     if (sc_asmfile
   771         && (label!=NULL || !isalpha(sym->name[0]) && sym->name[0]!='_'  && sym->name[0]!=sc_ctrlchar))
   772     {
   773       stgwrite("\t; ");
   774       stgwrite(symname);
   775     } /* if */
   776     stgwrite("\n");
   777     code_idx+=opcodes(1)+opargs(1);
   778   } /* if */
   779 }
   780 
   781 /*  Return from function
   782  *
   783  *  Global references: funcstatus  (referred to only)
   784  */
   785 SC_FUNC void ffret(int remparams)
   786 {
   787   if (remparams)
   788     stgwrite("\tretn\n");
   789   else
   790     stgwrite("\tret\n");
   791   code_idx+=opcodes(1);
   792 }
   793 
   794 SC_FUNC void ffabort(int reason)
   795 {
   796   stgwrite("\thalt ");
   797   outval(reason,TRUE);
   798   code_idx+=opcodes(1)+opargs(1);
   799 }
   800 
   801 SC_FUNC void ffbounds(cell size)
   802 {
   803   if ((sc_debug & sCHKBOUNDS)!=0) {
   804     stgwrite("\tbounds ");
   805     outval(size,TRUE);
   806     code_idx+=opcodes(1)+opargs(1);
   807   } /* if */
   808 }
   809 
   810 /*
   811  *  Jump to local label number (the number is converted to a name)
   812  */
   813 SC_FUNC void jumplabel(int number)
   814 {
   815   stgwrite("\tjump ");
   816   outval(number,TRUE);
   817   code_idx+=opcodes(1)+opargs(1);
   818 }
   819 
   820 /*
   821  *   Define storage (global and static variables)
   822  */
   823 SC_FUNC void defstorage(void)
   824 {
   825   stgwrite("dump ");
   826 }
   827 
   828 /*
   829  *  Inclrement/decrement stack pointer. Note that this routine does
   830  *  nothing if the delta is zero.
   831  */
   832 SC_FUNC void modstk(int delta)
   833 {
   834   if (delta) {
   835     stgwrite("\tstack ");
   836     outval(delta, TRUE);
   837     code_idx+=opcodes(1)+opargs(1);
   838   } /* if */
   839 }
   840 
   841 /* set the stack to a hard offset from the frame */
   842 SC_FUNC void setstk(cell value)
   843 {
   844   stgwrite("\tlctrl 5\n");      /* get FRM in PRI */
   845   assert(value<=0);             /* STK should always become <= FRM */
   846   if (value<0) {
   847     stgwrite("\tadd.c ");
   848     outval(value, TRUE);        /* add (negative) offset */
   849     code_idx+=opcodes(1)+opargs(1);
   850     // ??? write zeros in the space between STK and the value in PRI (the new stk)
   851     //     get value of STK in ALT
   852     //     zero PRI
   853     //     need new FILL opcode that takes a variable size
   854   } /* if */
   855   stgwrite("\tsctrl 4\n");      /* store in STK */
   856   code_idx+=opcodes(2)+opargs(2);
   857 }
   858 
   859 SC_FUNC void modheap(int delta)
   860 {
   861   if (delta) {
   862     stgwrite("\theap ");
   863     outval(delta, TRUE);
   864     code_idx+=opcodes(1)+opargs(1);
   865   } /* if */
   866 }
   867 
   868 SC_FUNC void modheap_i()
   869 {
   870   stgwrite("\ttracker.pop.setheap\n");
   871   code_idx+=opcodes(1);
   872 }
   873 
   874 SC_FUNC void setheap_save(cell value)
   875 {
   876   assert(value);
   877   stgwrite("\ttracker.push.c ");
   878   outval(value, TRUE);
   879   code_idx+=opcodes(1)+opargs(1);
   880 }
   881 
   882 SC_FUNC void setheap_pri(void)
   883 {
   884   stgwrite("\theap ");          /* ALT = HEA++ */
   885   outval(sizeof(cell), TRUE);
   886   stgwrite("\tstor.i\n");       /* store PRI (default value) at address ALT */
   887   stgwrite("\tmove.pri\n");     /* move ALT to PRI: PRI contains the address */
   888   code_idx+=opcodes(3)+opargs(1);
   889 }
   890 
   891 SC_FUNC void setheap(cell value)
   892 {
   893   stgwrite("\tconst.pri ");     /* load default value in PRI */
   894   outval(value, TRUE);
   895   code_idx+=opcodes(1)+opargs(1);
   896   setheap_pri();
   897 }
   898 
   899 /*
   900  *  Convert a cell number to a "byte" address; i.e. double or quadruple
   901  *  the primary register.
   902  */
   903 SC_FUNC void cell2addr(void)
   904 {
   905   #if PAWN_CELL_SIZE==16
   906     stgwrite("\tshl.c.pri 1\n");
   907   #elif PAWN_CELL_SIZE==32
   908     stgwrite("\tshl.c.pri 2\n");
   909   #elif PAWN_CELL_SIZE==64
   910     stgwrite("\tshl.c.pri 3\n");
   911   #else
   912     #error Unsupported cell size
   913   #endif
   914   code_idx+=opcodes(1)+opargs(1);
   915 }
   916 
   917 /*
   918  *  Double or quadruple the alternate register.
   919  */
   920 SC_FUNC void cell2addr_alt(void)
   921 {
   922   #if PAWN_CELL_SIZE==16
   923     stgwrite("\tshl.c.alt 1\n");
   924   #elif PAWN_CELL_SIZE==32
   925     stgwrite("\tshl.c.alt 2\n");
   926   #elif PAWN_CELL_SIZE==64
   927     stgwrite("\tshl.c.alt 3\n");
   928   #else
   929     #error Unsupported cell size
   930   #endif
   931   code_idx+=opcodes(1)+opargs(1);
   932 }
   933 
   934 /*
   935  *  Convert "distance of addresses" to "number of cells" in between.
   936  *  Or convert a number of packed characters to the number of cells (with
   937  *  truncation).
   938  */
   939 SC_FUNC void addr2cell(void)
   940 {
   941   #if PAWN_CELL_SIZE==16
   942     stgwrite("\tshr.c.pri 1\n");
   943   #elif PAWN_CELL_SIZE==32
   944     stgwrite("\tshr.c.pri 2\n");
   945   #elif PAWN_CELL_SIZE==64
   946     stgwrite("\tshr.c.pri 3\n");
   947   #else
   948     #error Unsupported cell size
   949   #endif
   950   code_idx+=opcodes(1)+opargs(1);
   951 }
   952 
   953 /* Convert from character index to byte address. This routine does
   954  * nothing if a character has the size of a byte.
   955  */
   956 SC_FUNC void char2addr(void)
   957 {
   958   #if sCHARBITS==16
   959     stgwrite("\tshl.c.pri 1\n");
   960     code_idx+=opcodes(1)+opargs(1);
   961   #endif
   962 }
   963 
   964 /* Align PRI (which should hold a character index) to an address.
   965  * The first character in a "pack" occupies the highest bits of
   966  * the cell. This is at the lower memory address on Big Endian
   967  * computers and on the higher address on Little Endian computers.
   968  * The ALIGN.pri/alt instructions must solve this machine dependence;
   969  * that is, on Big Endian computers, ALIGN.pri/alt shuold do nothing
   970  * and on Little Endian computers they should toggle the address.
   971  *
   972  * NOTE: For Source Pawn, this is fliped.  It will do nothing on Little-Endian.
   973  */
   974 SC_FUNC void charalign(void)
   975 {
   976 #if 0	/* TEMPORARILY DISABLED BECAUSE WE DON'T USE BIG ENDIAN */
   977   stgwrite("\talign.pri ");
   978   outval(sCHARBITS/8,TRUE);
   979   code_idx+=opcodes(1)+opargs(1);
   980 #endif
   981 }
   982 
   983 /*
   984  *  Add a constant to the primary register.
   985  */
   986 SC_FUNC void addconst(cell value)
   987 {
   988   if (value!=0) {
   989     stgwrite("\tadd.c ");
   990     outval(value,TRUE);
   991     code_idx+=opcodes(1)+opargs(1);
   992   } /* if */
   993 }
   994 
   995 /*
   996  *  signed multiply of primary and secundairy registers (result in primary)
   997  */
   998 SC_FUNC void os_mult(void)
   999 {
  1000   stgwrite("\tsmul\n");
  1001   code_idx+=opcodes(1);
  1002 }
  1003 
  1004 /*
  1005  *  signed divide of alternate register by primary register (quotient in
  1006  *  primary; remainder in alternate)
  1007  */
  1008 SC_FUNC void os_div(void)
  1009 {
  1010   stgwrite("\tsdiv.alt\n");
  1011   code_idx+=opcodes(1);
  1012 }
  1013 
  1014 /*
  1015  *  modulus of (alternate % primary), result in primary (signed)
  1016  */
  1017 SC_FUNC void os_mod(void)
  1018 {
  1019   stgwrite("\tsdiv.alt\n");
  1020   stgwrite("\tmove.pri\n");     /* move ALT to PRI */
  1021   code_idx+=opcodes(2);
  1022 }
  1023 
  1024 /*
  1025  *  Add primary and alternate registers (result in primary).
  1026  */
  1027 SC_FUNC void ob_add(void)
  1028 {
  1029   stgwrite("\tadd\n");
  1030   code_idx+=opcodes(1);
  1031 }
  1032 
  1033 /*
  1034  *  subtract primary register from alternate register (result in primary)
  1035  */
  1036 SC_FUNC void ob_sub(void)
  1037 {
  1038   stgwrite("\tsub.alt\n");
  1039   code_idx+=opcodes(1);
  1040 }
  1041 
  1042 /*
  1043  *  arithmic shift left alternate register the number of bits
  1044  *  given in the primary register (result in primary).
  1045  *  There is no need for a "logical shift left" routine, since
  1046  *  logical shift left is identical to arithmic shift left.
  1047  */
  1048 SC_FUNC void ob_sal(void)
  1049 {
  1050   stgwrite("\txchg\n");
  1051   stgwrite("\tshl\n");
  1052   code_idx+=opcodes(2);
  1053 }
  1054 
  1055 /*
  1056  *  arithmic shift right alternate register the number of bits
  1057  *  given in the primary register (result in primary).
  1058  */
  1059 SC_FUNC void os_sar(void)
  1060 {
  1061   stgwrite("\txchg\n");
  1062   stgwrite("\tsshr\n");
  1063   code_idx+=opcodes(2);
  1064 }
  1065 
  1066 /*
  1067  *  logical (unsigned) shift right of the alternate register by the
  1068  *  number of bits given in the primary register (result in primary).
  1069  */
  1070 SC_FUNC void ou_sar(void)
  1071 {
  1072   stgwrite("\txchg\n");
  1073   stgwrite("\tshr\n");
  1074   code_idx+=opcodes(2);
  1075 }
  1076 
  1077 /*
  1078  *  inclusive "or" of primary and alternate registers (result in primary)
  1079  */
  1080 SC_FUNC void ob_or(void)
  1081 {
  1082   stgwrite("\tor\n");
  1083   code_idx+=opcodes(1);
  1084 }
  1085 
  1086 /*
  1087  *  "exclusive or" of primary and alternate registers (result in primary)
  1088  */
  1089 SC_FUNC void ob_xor(void)
  1090 {
  1091   stgwrite("\txor\n");
  1092   code_idx+=opcodes(1);
  1093 }
  1094 
  1095 /*
  1096  *  "and" of primary and secundairy registers (result in primary)
  1097  */
  1098 SC_FUNC void ob_and(void)
  1099 {
  1100   stgwrite("\tand\n");
  1101   code_idx+=opcodes(1);
  1102 }
  1103 
  1104 /*
  1105  *  test ALT==PRI; result in primary register (1 or 0).
  1106  */
  1107 SC_FUNC void ob_eq(void)
  1108 {
  1109   stgwrite("\teq\n");
  1110   code_idx+=opcodes(1);
  1111 }
  1112 
  1113 /*
  1114  *  test ALT!=PRI
  1115  */
  1116 SC_FUNC void ob_ne(void)
  1117 {
  1118   stgwrite("\tneq\n");
  1119   code_idx+=opcodes(1);
  1120 }
  1121 
  1122 /* The abstract machine defines the relational instructions so that PRI is
  1123  * on the left side and ALT on the right side of the operator. For example,
  1124  * SLESS sets PRI to either 1 or 0 depending on whether the expression
  1125  * "PRI < ALT" is true.
  1126  *
  1127  * The compiler generates comparisons with ALT on the left side of the
  1128  * relational operator and PRI on the right side. The XCHG instruction
  1129  * prefixing the relational operators resets this. We leave it to the
  1130  * peephole optimizer to choose more compact instructions where possible.
  1131  */
  1132 
  1133 /* Relational operator prefix for chained relational expressions. The
  1134  * "suffix" code restores the stack.
  1135  * For chained relational operators, the goal is to keep the comparison
  1136  * result "so far" in PRI and the value of the most recent operand in
  1137  * ALT, ready for a next comparison.
  1138  * The "prefix" instruction pushed the comparison result (PRI) onto the
  1139  * stack and moves the value of ALT into PRI. If there is a next comparison,
  1140  * PRI can now serve as the "left" operand of the relational operator.
  1141  */
  1142 SC_FUNC void relop_prefix(void)
  1143 {
  1144   stgwrite("\tpush.pri\n");
  1145   stgwrite("\tmove.pri\n");
  1146   code_idx+=opcodes(2);
  1147 }
  1148 
  1149 SC_FUNC void relop_suffix(void)
  1150 {
  1151   stgwrite("\tswap.alt\n");
  1152   stgwrite("\tand\n");
  1153   stgwrite("\tpop.alt\n");
  1154   code_idx+=opcodes(3);
  1155 }
  1156 
  1157 /*
  1158  *  test ALT<PRI (signed)
  1159  */
  1160 SC_FUNC void os_lt(void)
  1161 {
  1162   stgwrite("\txchg\n");
  1163   stgwrite("\tsless\n");
  1164   code_idx+=opcodes(2);
  1165 }
  1166 
  1167 /*
  1168  *  test ALT<=PRI (signed)
  1169  */
  1170 SC_FUNC void os_le(void)
  1171 {
  1172   stgwrite("\txchg\n");
  1173   stgwrite("\tsleq\n");
  1174   code_idx+=opcodes(2);
  1175 }
  1176 
  1177 /*
  1178  *  test ALT>PRI (signed)
  1179  */
  1180 SC_FUNC void os_gt(void)
  1181 {
  1182   stgwrite("\txchg\n");
  1183   stgwrite("\tsgrtr\n");
  1184   code_idx+=opcodes(2);
  1185 }
  1186 
  1187 /*
  1188  *  test ALT>=PRI (signed)
  1189  */
  1190 SC_FUNC void os_ge(void)
  1191 {
  1192   stgwrite("\txchg\n");
  1193   stgwrite("\tsgeq\n");
  1194   code_idx+=opcodes(2);
  1195 }
  1196 
  1197 /*
  1198  *  logical negation of primary register
  1199  */
  1200 SC_FUNC void lneg(void)
  1201 {
  1202   stgwrite("\tnot\n");
  1203   code_idx+=opcodes(1);
  1204 }
  1205 
  1206 /*
  1207  *  two's complement primary register
  1208  */
  1209 SC_FUNC void neg(void)
  1210 {
  1211   stgwrite("\tneg\n");
  1212   code_idx+=opcodes(1);
  1213 }
  1214 
  1215 /*
  1216  *  one's complement of primary register
  1217  */
  1218 SC_FUNC void invert(void)
  1219 {
  1220   stgwrite("\tinvert\n");
  1221   code_idx+=opcodes(1);
  1222 }
  1223 
  1224 /*
  1225  *  nop
  1226  */
  1227 SC_FUNC void nooperation(void)
  1228 {
  1229   stgwrite("\tnop\n");
  1230   code_idx+=opcodes(1);
  1231 }
  1232 
  1233 
  1234 /*  increment symbol
  1235  */
  1236 SC_FUNC void inc(value *lval)
  1237 {
  1238   symbol *sym;
  1239 
  1240   sym=lval->sym;
  1241   if (lval->ident==iARRAYCELL) {
  1242     /* indirect increment, address already in PRI */
  1243     stgwrite("\tinc.i\n");
  1244     code_idx+=opcodes(1);
  1245   } else if (lval->ident==iARRAYCHAR) {
  1246     /* indirect increment of single character, address already in PRI */
  1247     stgwrite("\tpush.pri\n");
  1248     stgwrite("\tpush.alt\n");
  1249     stgwrite("\tmove.alt\n");   /* copy address */
  1250     stgwrite("\tlodb.i ");      /* read from PRI into PRI */
  1251     outval(sCHARBITS/8,TRUE);   /* read one or two bytes */
  1252     stgwrite("\tinc.pri\n");
  1253     stgwrite("\tstrb.i ");      /* write PRI to ALT */
  1254     outval(sCHARBITS/8,TRUE);   /* write one or two bytes */
  1255     stgwrite("\tpop.alt\n");
  1256     stgwrite("\tpop.pri\n");
  1257     code_idx+=opcodes(8)+opargs(2);
  1258   } else if (lval->ident==iREFERENCE) {
  1259     assert(sym!=NULL);
  1260     stgwrite("\tpush.pri\n");
  1261     /* load dereferenced value */
  1262     assert(sym->vclass==sLOCAL);    /* global references don't exist in Pawn */
  1263     if (sym->vclass==sLOCAL)
  1264       stgwrite("\tlref.s.pri ");
  1265     else
  1266       stgwrite("\tlref.pri ");
  1267     outval(sym->addr,TRUE);
  1268     /* increment */
  1269     stgwrite("\tinc.pri\n");
  1270     /* store dereferenced value */
  1271     if (sym->vclass==sLOCAL)
  1272       stgwrite("\tsref.s.pri ");
  1273     else
  1274       stgwrite("\tsref.pri ");
  1275     outval(sym->addr,TRUE);
  1276     stgwrite("\tpop.pri\n");
  1277     code_idx+=opcodes(5)+opargs(2);
  1278   } else {
  1279     /* local or global variable */
  1280     assert(sym!=NULL);
  1281     if (sym->vclass==sLOCAL)
  1282       stgwrite("\tinc.s ");
  1283     else
  1284       stgwrite("\tinc ");
  1285     outval(sym->addr,TRUE);
  1286     code_idx+=opcodes(1)+opargs(1);
  1287   } /* if */
  1288 }
  1289 
  1290 /*  decrement symbol
  1291  *
  1292  *  in case of an integer pointer, the symbol must be incremented by 2.
  1293  */
  1294 SC_FUNC void dec(value *lval)
  1295 {
  1296   symbol *sym;
  1297 
  1298   sym=lval->sym;
  1299   if (lval->ident==iARRAYCELL) {
  1300     /* indirect decrement, address already in PRI */
  1301     stgwrite("\tdec.i\n");
  1302     code_idx+=opcodes(1);
  1303   } else if (lval->ident==iARRAYCHAR) {
  1304     /* indirect decrement of single character, address already in PRI */
  1305     stgwrite("\tpush.pri\n");
  1306     stgwrite("\tpush.alt\n");
  1307     stgwrite("\tmove.alt\n");   /* copy address */
  1308     stgwrite("\tlodb.i ");      /* read from PRI into PRI */
  1309     outval(sCHARBITS/8,TRUE);   /* read one or two bytes */
  1310     stgwrite("\tdec.pri\n");
  1311     stgwrite("\tstrb.i ");      /* write PRI to ALT */
  1312     outval(sCHARBITS/8,TRUE);   /* write one or two bytes */
  1313     stgwrite("\tpop.alt\n");
  1314     stgwrite("\tpop.pri\n");
  1315     code_idx+=opcodes(8)+opargs(2);
  1316   } else if (lval->ident==iREFERENCE) {
  1317     assert(sym!=NULL);
  1318     stgwrite("\tpush.pri\n");
  1319     /* load dereferenced value */
  1320     assert(sym->vclass==sLOCAL);    /* global references don't exist in Pawn */
  1321     if (sym->vclass==sLOCAL)
  1322       stgwrite("\tlref.s.pri ");
  1323     else
  1324       stgwrite("\tlref.pri ");
  1325     outval(sym->addr,TRUE);
  1326     /* decrement */
  1327     stgwrite("\tdec.pri\n");
  1328     /* store dereferenced value */
  1329     if (sym->vclass==sLOCAL)
  1330       stgwrite("\tsref.s.pri ");
  1331     else
  1332       stgwrite("\tsref.pri ");
  1333     outval(sym->addr,TRUE);
  1334     stgwrite("\tpop.pri\n");
  1335     code_idx+=opcodes(5)+opargs(2);
  1336   } else {
  1337     /* local or global variable */
  1338     assert(sym!=NULL);
  1339     if (sym->vclass==sLOCAL)
  1340       stgwrite("\tdec.s ");
  1341     else
  1342       stgwrite("\tdec ");
  1343     outval(sym->addr,TRUE);
  1344     code_idx+=opcodes(1)+opargs(1);
  1345   } /* if */
  1346 }
  1347 
  1348 /*
  1349  *  Jumps to "label" if PRI != 0
  1350  */
  1351 SC_FUNC void jmp_ne0(int number)
  1352 {
  1353   stgwrite("\tjnz ");
  1354   outval(number,TRUE);
  1355   code_idx+=opcodes(1)+opargs(1);
  1356 }
  1357 
  1358 /*
  1359  *  Jumps to "label" if PRI == 0
  1360  */
  1361 SC_FUNC void jmp_eq0(int number)
  1362 {
  1363   stgwrite("\tjzer ");
  1364   outval(number,TRUE);
  1365   code_idx+=opcodes(1)+opargs(1);
  1366 }
  1367 
  1368 /* write a value in hexadecimal; optionally adds a newline */
  1369 SC_FUNC void outval(cell val,int newline)
  1370 {
  1371   stgwrite(itoh(val));
  1372   if (newline)
  1373     stgwrite("\n");
  1374 }