Changeset b6e51b in git for modules


Ignore:
Timestamp:
Sep 27, 2006, 7:46:28 PM (18 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
1e35790dc0937f1166846848cf844b2811aa49f0
Parents:
2245326a4cf500727c77d96a854a05d93f0cd772
Message:
*krueger: arith-change


git-svn-id: file:///usr/local/Singular/svn/trunk@9432 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
modules/modgen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • modules/modgen/creat_top.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: creat_top.cc,v 1.24 2006-06-25 16:06:19 motsak Exp $ */
     4/* $Id: creat_top.cc,v 1.25 2006-09-27 17:46:27 Singular Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    122122  fprintf(fp, "#line @d \"%s.cc\"\n", module->name);
    123123  fprintf(fp, "extern \"C\" {\n");
     124#if 0
    124125  fprintf(fp, "int mod_init(\n  int (*iiAddCproc)(");
    125126#if 1
     
    128129#endif
    129130  fprintf(fp, ")\n  )\n{\n");
     131#else
     132  fprintf(fp, "int mod_init(\n  SModulFunctions* psModulFunctions");
     133  fprintf(fp, "\n  )\n{\n");
     134#endif
    130135  fprintf(fp, "  idhdl h;\n");
    131136  fprintf(fp, "  char * tempstr;\n");
  • modules/modgen/main.cc

    r224532 rb6e51b  
    6060moddef module_def;
    6161
     62extern int iiInitArithmetic();
    6263int init_modgen(
    6364  moddefv module_def,
     
    159160  }
    160161 
     162  iiInitArithmetic();
    161163  if(init_modgen(&module_def, argv[optind])) return 1;
    162164  init_type_conv();
  • modules/modgen/misc.cc

    r224532 rb6e51b  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.25 2006-04-06 19:37:00 anne Exp $ */
     4/* $Id: misc.cc,v 1.26 2006-09-27 17:46:27 Singular Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    3535#endif
    3636
     37typedef struct {
     38  unsigned long nCmdUsed;      /**< number of commands used */
     39  unsigned long nCmdAllocated; /**< number of commands-slots allocated */
     40  unsigned long nLastIdentifier;
     41  cmdnames *sCmds;             /**< array of existing commands */
     42
     43#ifndef GENTABLE
     44  struct sValCmd1 *psValCmd1;
     45  struct sValCmd2 *psValCmd2;
     46  struct sValCmd3 *psValCmd3;
     47  struct sValCmdM *psValCmdM;
     48#endif /* GENTABLE */
     49} SArithBase;
     50
     51
     52/*---------------------------------------------------------------------*
     53 * File scope Variables (Variables share by several functions in
     54 *                       the same file )
     55 *
     56 *---------------------------------------------------------------------*/
     57static SArithBase sArithBase;  /**< Base entry for arithmetic */
     58
    3759char *DYNAinclude[] = {
    3860   "",
     
    5476#define SELF_CMD MAX_TOK+1
    5577
     78/*---------------------------------------------------------------------*
     79 * Extern Functions declarations
     80 *
     81 *---------------------------------------------------------------------*/
     82static int _gentable_sort_cmds(const void *a, const void *b);
     83extern int iiArithRemoveCmd(char *szName);
     84extern int iiArithAddCmd(char *szName, short nAlias, short nTokval,
     85                         short nToktype, short nPos=-1);
    5686extern void enter_id(FILE *fp, idtyp t, char *name, char *value,
    5787                     int lineno, char *file);
     
    78108  int an=1;
    79109  int i,v;
    80   int en=LAST_IDENTIFIER;
     110  int en=sArithBase.nLastIdentifier;
    81111 
    82112  if( strcmp(n, "SELF") == 0) {
     
    92122  }
    93123 
    94   loop
     124  for(an=0; an<sArithBase.nCmdUsed; )
    95125  {
    96126    if(an>=en-1)
    97127    {
    98       if (strcmp(n, cmds[an].name) == 0)
     128      if (strcmp(n, sArithBase.sCmds[an].name) == 0)
    99129      {
    100130        i=an;
    101131        break;
    102132      }
    103       else if (strcmp(n, cmds[en].name) == 0)
     133      else if ((an!=en) && (strcmp(n, sArithBase.sCmds[en].name) == 0))
    104134      {
    105135        i=en;
     
    112142    }
    113143    i=(an+en)/2;
    114     v=strcmp(n,cmds[i].name);
     144    if (*n < *(sArithBase.sCmds[i].name))
     145    {
     146      en=i-1;
     147    }
     148    else if (*n > *(sArithBase.sCmds[i].name))
     149    {
     150      an=i+1;
     151    }
     152    else
     153    {
     154      v=strcmp(n,sArithBase.sCmds[i].name);
    115155    if(v<0)
    116156    {
    117       en=i;
     157        en=i-1;
    118158    }
    119159    else if(v>0)
    120160    {
    121       an=i;
     161        an=i+1;
    122162    }
    123163    else /*v==0*/
     
    126166    }
    127167  }
    128   lastreserved=cmds[i].name;
    129   tok=cmds[i].tokval;
    130   if(cmds[i].alias==2)
    131   {
     168  }
     169  lastreserved=sArithBase.sCmds[i].name;
     170  tok=sArithBase.sCmds[i].tokval;
     171  if(sArithBase.sCmds[i].alias==2)
     172    {
    132173    if(trace)printf("outdated identifier `%s` used - please change your code",
    133     cmds[i].name);
    134     cmds[i].alias=1;
    135   }
    136 #if 0
    137   if (!expected_parms)
    138   {
    139     switch (tok)
    140     {
    141       case IDEAL_CMD:
    142       case INT_CMD:
    143       case INTVEC_CMD:
    144       case MAP_CMD:
    145       case MATRIX_CMD:
    146       case MODUL_CMD:
    147       case POLY_CMD:
    148       case PROC_CMD:
    149       case RING_CMD:
    150       case STRING_CMD:
    151         cmdtok = tok;
    152         break;
    153     }
    154   }
    155 #endif
     174    sArithBase.sCmds[i].name);
     175    sArithBase.sCmds[i].alias=1;
     176  }
     177
    156178  logx("IsCmd: [%d] %s\n", tok, n);
    157179 
    158   if( (cmds[i].toktype==ROOT_DECL) ||
    159       (cmds[i].toktype==ROOT_DECL_LIST) ||
    160       (cmds[i].toktype==RING_DECL) ||
    161       (cmds[i].toktype==IDEAL_CMD) ||
    162       (cmds[i].toktype==INTMAT_CMD) ||
    163       (cmds[i].toktype==MODUL_CMD) ||
    164       (cmds[i].toktype==MATRIX_CMD))// ||
    165 //      ((cmds[i].toktype>=DRING_CMD) && (cmds[i].toktype<=VECTOR_CMD)))
    166     return cmds[i].toktype;
     180  if( (sArithBase.sCmds[i].toktype==ROOT_DECL) ||
     181      (sArithBase.sCmds[i].toktype==ROOT_DECL_LIST) ||
     182      (sArithBase.sCmds[i].toktype==RING_DECL) ||
     183      (sArithBase.sCmds[i].toktype==IDEAL_CMD) ||
     184      (sArithBase.sCmds[i].toktype==INTMAT_CMD) ||
     185      (sArithBase.sCmds[i].toktype==MODUL_CMD) ||
     186      (sArithBase.sCmds[i].toktype==MATRIX_CMD))// ||
     187//      ((csArithBase.sCds[i].toktype>=DRING_CMD) && (cmds[i].toktype<=VECTOR_CMD)))
     188    return sArithBase.sCmds[i].toktype;
    167189  return 0;
    168190}
     191
    169192
    170193char * decl2str(int n, char *name)
     
    434457    printf("->%s, %s\n", module->procs[proccnt].procname,
    435458           module->procs[proccnt].funcname);
    436     fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
     459    fprintf(module->modfp, "  psModulFunctions->iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
    437460            module->name, module->procs[proccnt].procname,
    438461            module->procs[proccnt].is_static ? "TRUE" : "FALSE",
     
    616639
    617640/*========================================================================*/
     641/*---------------------------------------------------------------------*/
     642/**
     643 * @brief compares to entry of cmdsname-list
     644
     645 @param[in] a   
     646 @param[in] b   
     647
     648 @return <ReturnValue>
     649**/
     650/*---------------------------------------------------------------------*/
     651static int _gentable_sort_cmds(
     652  const void *a,
     653  const void *b
     654  )
     655{
     656  cmdnames *pCmdL = (cmdnames*)a;
     657  cmdnames *pCmdR = (cmdnames*)b;
     658 
     659  if(a==NULL || b==NULL)             return 0;
     660
     661  /* empty entries goes to the end of the list for later reuse */
     662  if(pCmdL->name==NULL) return 1;
     663  if(pCmdR->name==NULL) return -1;
     664 
     665  /* $INVALID$ must come first */
     666  if(strcmp(pCmdL->name, "$INVALID$")==0) return -1;
     667  if(strcmp(pCmdR->name, "$INVALID$")==0) return  1;
     668 
     669  /* tokval=-1 are reserved names at the end */
     670  if( (pCmdL->tokval==-1) && pCmdR->tokval==-1)
     671    return strcmp(pCmdL->name, pCmdR->name);
     672
     673  /* pCmdL->tokval==-1, pCmdL goes at the end */
     674  if(pCmdL->tokval==-1) return 1;
     675  /* pCmdR->tokval==-1, pCmdR goes at the end */
     676  if(pCmdR->tokval==-1) return -1;
     677
     678  return strcmp(pCmdL->name, pCmdR->name);
     679}
     680
     681/*---------------------------------------------------------------------*/
     682/**
     683 * @brief initialisation of arithmetic structured data
     684
     685 @retval 0 on success
     686
     687**/
     688/*---------------------------------------------------------------------*/
     689int iiInitArithmetic()
     690{
     691  int i;
     692  //printf("iiInitArithmetic()\n");
     693#ifndef GENTABLE
     694  memset(&sArithBase, 0, sizeof(sArithBase));
     695  iiInitCmdName();
     696  /* fix last-identifier */
     697#endif   /* !GENTABLE */
     698}
     699
     700int iiArithFindCmd(const char *szName)
     701{
     702  int an=0;
     703  int i = 0,v = 0;
     704#ifndef GENTABLE
     705  int en=sArithBase.nLastIdentifier;
     706
     707  for(an=0; an<sArithBase.nCmdUsed; ) {
     708    if(an>=en-1) {
     709      if (strcmp(szName, sArithBase.sCmds[an].name) == 0) {
     710        //Print("RET-an=%d %s\n", an, sArithBase.sCmds[an].name);
     711        return an;
     712      } else if (strcmp(szName, sArithBase.sCmds[en].name) == 0)
     713      {
     714        //Print("RET-en=%d %s\n", en, sArithBase.sCmds[en].name);
     715        return en;
     716      }
     717      else
     718      {
     719        //Print("RET- 1\n");
     720        return -1;
     721      }
     722    }
     723    i=(an+en)/2;
     724    if (*szName < *(sArithBase.sCmds[i].name)) {
     725      en=i-1;
     726    }
     727    else if (*szName > *(sArithBase.sCmds[i].name))
     728    {
     729      an=i+1;
     730    }
     731    else
     732    {
     733      v=strcmp(szName,sArithBase.sCmds[i].name);
     734      if(v<0)
     735      {
     736        en=i-1;
     737      }
     738      else if(v>0)
     739      {
     740        an=i+1;
     741      }
     742      else /*v==0*/
     743      {
     744        //Print("RET-i=%d %s\n", i, sArithBase.sCmds[i].name);
     745        return i;
     746      }
     747    }
     748  }
     749  //if(i>=0 && i<sArithBase.nCmdUsed)
     750  //  return i;
     751  //Print("RET-2\n");
     752  return -2;
     753#else
     754  return 0;
     755#endif
     756}
     757
     758int iiArithAddCmd(
     759  char *szName,
     760  short nAlias,
     761  short nTokval,
     762  short nToktype,
     763  short nPos
     764  )
     765{
     766  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
     767  //       nTokval, nToktype, nPos);
     768  if(nPos>=0) {
     769    if(nPos>=sArithBase.nCmdAllocated) return -1;
     770    if(szName!=NULL) sArithBase.sCmds[nPos].name    = strdup(szName);
     771    else sArithBase.sCmds[nPos].name = NULL;
     772    sArithBase.sCmds[nPos].alias   = nAlias;
     773    sArithBase.sCmds[nPos].tokval  = nTokval;
     774    sArithBase.sCmds[nPos].toktype = nToktype;
     775    sArithBase.nCmdUsed++;
     776    //if(nTokval>0) sArithBase.nLastIdentifier++;
     777  } else {
     778    if(szName==NULL) return -1;
     779    int nIndex = iiArithFindCmd(szName);
     780    if(nIndex>=0) {
     781      printf("'%s' already exists at %d\n", szName, nIndex);
     782      return -1;
     783    }
     784   
     785    if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated) {
     786      /* needs to create new slots */
     787      unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
     788      sArithBase.sCmds = (cmdnames *)realloc(sArithBase.sCmds, nSize);
     789      if(sArithBase.sCmds==NULL) return -1;
     790      sArithBase.nCmdAllocated++;
     791    }
     792    /* still free slots available */
     793    sArithBase.sCmds[sArithBase.nCmdUsed].name    = strdup(szName);
     794    sArithBase.sCmds[sArithBase.nCmdUsed].alias   = nAlias;
     795    sArithBase.sCmds[sArithBase.nCmdUsed].tokval  = nTokval;
     796    sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
     797    sArithBase.nCmdUsed++;
     798
     799    qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
     800          (&_gentable_sort_cmds));
     801    for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
     802        sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--) {
     803      if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
     804    }
     805    //Print("L=%d\n", sArithBase.nLastIdentifier);
     806  }
     807  return 0;
     808}
     809
  • modules/modgen/proc.cc

    r224532 rb6e51b  
    11/*
    2  * $Id: proc.cc,v 1.25 2006-06-25 16:19:16 motsak Exp $
     2 * $Id: proc.cc,v 1.26 2006-09-27 17:46:28 Singular Exp $
    33 */
    44
     
    5353        /* write call to add procname to list */
    5454        fprintf(module->modfp,
    55                 "  iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n",
     55                "  psModulFunctions->iiAddCproc(currPack->libname,\"%s\",%s, mod_%s);\n",
    5656                proc->procname,
    5757                proc->is_static ? "TRUE" : "FALSE",
     
    524524/*========================================================================*/
    525525void write_help(
    526   moddefv module,
     526  moddefv pModule,
    527527  procdefv pi
    528528  )
     
    530530  unsigned int i;
    531531  if(pi->help_string!=NULL) {
    532     fprintf(module->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
    533             module->filename);
    534     fprintf(module->fmtfp2, "  enter_id(\"%s_help\",", pi->procname);
    535     fprintf(module->fmtfp2, " \"");
     532    fprintf(pModule->fmtfp2, "#line %d \"%s\"\n", pi->lineno_other,
     533            pModule->filename);
     534    fprintf(pModule->fmtfp2, "  enter_id(\"%s_help\",", pi->procname);
     535    fprintf(pModule->fmtfp2, " \"");
    536536    for(i=0; i<strlen(pi->help_string); i++) {
    537         if(pi->help_string[i]=='\n') fprintf(module->fmtfp2,"\\n");
    538         else fprintf(module->fmtfp2,"%c", pi->help_string[i]);
    539     }
    540     fprintf(module->fmtfp2, "\", STRING_CMD);\n\n", pi->help_string);
     537        if(pi->help_string[i]=='\n') fprintf(pModule->fmtfp2,"\\n");
     538        else fprintf(pModule->fmtfp2,"%c", pi->help_string[i]);
     539    }
     540    fprintf(pModule->fmtfp2, "\", STRING_CMD);\n\n", pi->help_string);
    541541  }
    542542}
  • modules/modgen/scanner.cc

    r224532 rb6e51b  
    33
    44/* Scanner skeleton version:
    5  * $Header: /exports/cvsroot-2/cvsroot/modules/modgen/scanner.cc,v 1.2 2006-06-23 15:41:38 Singular Exp $
     5 * $Header: /exports/cvsroot-2/cvsroot/modules/modgen/scanner.cc,v 1.3 2006-09-27 17:46:28 Singular Exp $
    66 */
    77
     
    703703*  Computer Algebra System SINGULAR     *
    704704****************************************/
    705 /* $Id: scanner.cc,v 1.2 2006-06-23 15:41:38 Singular Exp $ */
     705/* $Id: scanner.cc,v 1.3 2006-09-27 17:46:28 Singular Exp $ */
    706706#include <stdio.h>
    707707#include <string.h>
Note: See TracChangeset for help on using the changeset viewer.