Changeset cffe626 in git for modules/modgen


Ignore:
Timestamp:
Jan 27, 2000, 1:40:55 PM (24 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
Children:
1bf317c89085ef09163635ecfe77c4da1ebc1045
Parents:
dd10b142c1fd713fe44c4cac2ad1ef9c53b47868
Message:
New format of enter_id()
Added example section
clean grammar and proc_setup
Added initialisation of system_type


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

Legend:

Unmodified
Added
Removed
  • modules/modgen/creat_top.cc

    rdd10b1 rcffe626  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: creat_top.cc,v 1.3 2000-01-17 08:32:25 krueger Exp $ */
     4/* $Id: creat_top.cc,v 1.4 2000-01-27 12:39:59 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    3232void write_enter_id(FILE *fp)
    3333{
    34   fprintf(fp, "void enter_id(char *name, char *value)\n");
    35   fprintf(fp, "{\n  idhdl h;\n\n");
    36   fprintf(fp, "  h = enterid(mstrdup(name),0, STRING_CMD, &IDROOT, FALSE);\n");
     34  fprintf(fp, "idhdl enter_id(char *name, char *value, idtyp t)\n");
     35  fprintf(fp, "{\n");
     36  fprintf(fp, "  idhdl h;\n");
     37  fprintf(fp, "\n");
     38  fprintf(fp, "  h=enterid(mstrdup(name),0, t, &IDROOT, FALSE);\n");
    3739  fprintf(fp, "  if(h!=NULL) {\n");
    38   fprintf(fp, "     IDSTRING(h) = mstrdup(value);\n");
    39   fprintf(fp, "  }\n}\n\n");
     40  fprintf(fp, "     switch(t) {\n");
     41  fprintf(fp, "       case STRING_CMD: IDSTRING(h) = mstrdup(value);break\n");
     42  fprintf(fp, "       case PACKAGE_CMD: break;\n");
     43  fprintf(fp, "     }\n");
     44  fprintf(fp, "  }\n");
     45  fprintf(fp, "  return(h);\n");
     46  fprintf(fp, "}\n");
    4047}
    4148
     
    4855  fprintf(fp, "extern \"C\"\n");
    4956  fprintf(fp, "int mod_init(int(*iiAddCproc)())\n{\n");
    50   fprintf(fp, "  idhdl h;\n\n");
     57  fprintf(fp, "  idhdl h;\n");
     58  fprintf(fp, "  idhdl helphdl = enter_id(\"help\", NULL, PACKAGE_CMD);\n");
     59  fprintf(fp, "  idhdl examplehdl = enter_id(\"example\", NULL, PACKAGE_CMD);\n\n");
    5160}
    5261
  • modules/modgen/grammar.y

    rdd10b1 rcffe626  
    11/*
    2  * $Id: grammar.y,v 1.4 2000-01-21 09:23:20 krueger Exp $
     2 * $Id: grammar.y,v 1.5 2000-01-27 12:40:54 krueger Exp $
    33 */
    44
     
    1111#include <string.h>
    1212#include <limits.h>
     13
     14#include <mod2.h>
     15#include <tok.h>
    1316
    1417#include "modgen.h"
     
    5255/*%token PROCEND*/
    5356%token PROCDECLTOK
     57%token EXAMPLETOK
    5458
    5559/* BISON Declarations */
     
    9599        }
    96100
    97 line:
    98         expr ';'
    99         {
    100           printf("EXPRESSION\n");
    101         }
    102         | procdecl
    103 ;
    104 
    105101sect1: expr ';'
    106102       | sect1 expr ';'
     
    110106sect1end: SECTEND
    111107        {
     108          memset(&procedure_decl, 0, sizeof(procdef));
    112109          printf("End of section %d\n", sectnum-1);
    113110        }
     
    116113expr:   NAME '=' MSTRINGTOK
    117114        { var_token vt;
    118           switch(sectnum) {
    119               case 1: /* pass 1: */
    120                 if( (vt=checkvar($1, VAR_STRING)) ) {
    121                   enter_id(module_def.fmtfp, $1, $3, yylineno,
    122                            module_def.filename);
     115          void (*write_cmd)(moddefv module, var_token type = VAR_NONE,
     116                            idtyp t, void *arg1 = NULL, void *arg2 = NULL);
     117         
     118          switch(sectnum) {
     119              case 1: /* pass 1: */
     120                if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) {
     121                  if(write_cmd!=0)
     122                    write_cmd(&module_def, vt, STRING_CMD, $1, $3);
    123123                }
    124124                else {
     
    128128                break;
    129129              case 2: /* pass 2: procedure declaration */
    130                 if( (vt=checkvar($1, VAR_STRING)) ) {
     130                if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) {
    131131                  proc_set_var(&procedure_decl, VAR_STRING, vt, $1, $3);
    132132                }
     
    142142        | NAME '=' FILENAME
    143143        { var_token vt;
    144           switch(sectnum) {
    145               case 1: /* pass 1: */
    146                 break;
    147               case 2: /* pass 2: procedure declaration */
    148                 if( (vt=checkvar($1, VAR_FILE)) ) {
     144          void (*write_cmd)(moddefv module, var_token type = VAR_NONE,
     145                            idtyp t, void *arg1 = NULL, void *arg2 = NULL);
     146          switch(sectnum) {
     147              case 1: /* pass 1: */
     148                break;
     149              case 2: /* pass 2: procedure declaration */
     150                if( (vt=checkvar($1, VAR_FILE, &write_cmd)) ) {
    149151                  proc_set_var(&procedure_decl, VAR_FILE, vt, $1, $3);
    150152                }
     
    156158        | NAME '=' files
    157159        { var_token vt;
    158           switch(sectnum) {
    159               case 1: /* pass 1: */
    160                 break;
    161               case 2: /* pass 2: procedure declaration */
    162                 if( (vt=checkvar($1, VAR_FILES)) ) {
     160          void (*write_cmd)(moddefv module, var_token type = VAR_NONE,
     161                            idtyp t, void *arg1 = NULL, void *arg2 = NULL);
     162          switch(sectnum) {
     163              case 1: /* pass 1: */
     164                break;
     165              case 2: /* pass 2: procedure declaration */
     166                if( (vt=checkvar($1, VAR_FILES, &write_cmd)) ) {
    163167                  proc_set_var(&procedure_decl, VAR_FILES, vt, $1, &$3);
    164168                }
     
    170174        | NAME '=' NUMTOK
    171175        { var_token vt;
    172           switch(sectnum) {
    173               case 1: /* pass 1: */
    174                 break;
    175               case 2: /* pass 2: procedure declaration */
    176                 if( (vt=checkvar($1, VAR_NUM)) ) {
     176          void (*write_cmd)(moddefv module, var_token type = VAR_NONE,
     177                            idtyp t, void *arg1 = NULL, void *arg2 = NULL);
     178          switch(sectnum) {
     179              case 1: /* pass 1: */
     180                break;
     181              case 2: /* pass 2: procedure declaration */
     182                if( (vt=checkvar($1, VAR_NUM, &write_cmd)) ) {
    177183                  proc_set_var(&procedure_decl, VAR_NUM, vt, $1, &$3);
    178184                }
     
    184190        | NAME '=' BOOLTOK
    185191        { var_token vt;
    186           switch(sectnum) {
    187               case 1: /* pass 1: */
    188                 if( (vt=checkvar($1, VAR_BOOL)) ) {
     192          void (*write_cmd)(moddefv module, var_token type = VAR_NONE,
     193                            idtyp t, void *arg1 = NULL, void *arg2 = NULL);
     194          switch(sectnum) {
     195              case 1: /* pass 1: */
     196                if( (vt=checkvar($1, VAR_BOOL, &write_cmd)) ) {
    189197                  proc_set_default_var(VAR_BOOL, vt, $1, &$3);
    190198                }
     
    195203                break;
    196204              case 2: /* pass 2: procedure declaration */
    197                 if( (vt=checkvar($1, VAR_BOOL)) ) {
     205                if( (vt=checkvar($1, VAR_BOOL, &write_cmd)) ) {
    198206                  proc_set_var(&procedure_decl, VAR_BOOL, vt, $1, &$3);
    199207                }
     
    227235
    228236procdef: procdecl proccode
    229 {
    230   printf("PROCDEF:\n");
    231 }
    232 
    233         ;
    234 
    235 procdecl: procdecl3 '{'
     237        {
     238          printf("PROCDEF:\n");
     239        }
     240        | procdecl proccode procdeclexample
     241        {
     242          printf("PROCDEF mit example:\n");
     243        }
     244        ;
     245
     246procdecl: procdecl2 '{'
    236247        {
    237248          setup_proc(&module_def, &procedure_decl);
    238249        }
    239         | procdecl3 procdeclhelp '{'
     250        | procdecl2 procdeclhelp '{'
    240251        {
    241252          setup_proc(&module_def, &procedure_decl);
     
    257268        ;
    258269
    259 procdecl3: procdecl2
    260         | procdecl2 procdeclflags
    261         ;
    262 
    263270procdeclhelp: MSTRINGTOK
    264271        {
    265272          procedure_decl.help_string = strdup($1);
    266         }
    267         ;
    268 
    269 procdeclflags: expr ';'
    270         {
    271           //printf("expr-1\n");
    272         }
    273         | procdeclflags expr ';'
    274         {
    275           //printf("expr-2\n");
    276273        }
    277274        ;
     
    279276proccode: proccodeline MCODETOK
    280277          {
    281             generate_function(&procedure_decl, module_def.fmtfp);
     278            write_function_errorhandling(&procedure_decl, module_def.fmtfp);
    282279          };
    283280
     
    297294        };
    298295
    299 proccmd: '%' PROCCMD ';'
     296procdeclexample: EXAMPLETOK examplecodeline MCODETOK
     297        {
     298          printf("Example\n");
     299          if(procedure_decl.procname != NULL) {
     300            //write_example(&module_def, &procedure_decl);
     301          } else {
     302            myyyerror("example without proc-declaration at line %d\n",
     303                     yylineno);
     304          }
     305        }
     306        ;
     307
     308examplecodeline: CODEPART
     309        {
     310          printf(">>1\n");
     311          procedure_decl.example_len = strlen($1);
     312          procedure_decl.example_string = malloc(strlen($1));
     313          strncpy(procedure_decl.example_string, $1, strlen($1));
     314        }
     315        | examplecodeline CODEPART
     316        {
     317          printf(">>2\n");
     318          procedure_decl.example_len += strlen($2);
     319          procedure_decl.example_string =
     320            realloc(procedure_decl.example_string, procedure_decl.example_len);
     321          strcat(procedure_decl.example_string, $2);
     322          printf(">>2b\n");
     323        };
     324
     325proccmd: '%' NAME ';'
    300326        { cmd_token vt;
    301           void (*write_cmd)(moddefv module, procdefv pi);
     327          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    302328         
    303           if( (vt=checkcmd($2, &write_cmd)) ) {
     329          if( (vt=checkcmd($2, &write_cmd, 0)) ) {
    304330            write_cmd(&module_def, &procedure_decl);
    305331          }
    306332          else {
    307333            myyyerror("Line %d: Unknown command '%s' in section %d\n",
    308                       yylineno, $1, sectnum);
     334                      yylineno, $2, sectnum);
    309335          }
    310336          free($2);
     337        }
     338        | '%' NAME '(' ')' ';'
     339        {
     340          cmd_token vt;
     341          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
     342         
     343          if( (vt=checkcmd($2, &write_cmd, 1)) ) {
     344            write_cmd(&module_def, &procedure_decl, procedure_decl.procname);
     345          }
     346          else {
     347            myyyerror("Line %d: Unknown command '%s' in section %d\n",
     348                      yylineno, $2, sectnum);
     349          }
     350          free($2);
     351        }
     352        | '%' NAME '(' NAME ')' ';'
     353        {
     354          cmd_token vt;
     355          void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
     356         
     357          if( (vt=checkcmd($2, &write_cmd, 1)) ) {
     358            write_cmd(&module_def, &procedure_decl, $4);
     359          }
     360          else {
     361            myyyerror("Line %d: Unknown command '%s' in section %d\n",
     362                      yylineno, $2, sectnum);
     363          }
     364          free($2); free($4);
    311365        };
    312366
  • modules/modgen/main.cc

    rdd10b1 rcffe626  
    1313#include "stype.h"
    1414
     15int trace=1;
    1516/*
    1617 *    Syntax of a module file:
     
    8990  //fflush(module_def.fmtfp);
    9091  //PrintProclist(&module_def);
    91   //generate_mod(&module_def, 2);
    9292  //mod_create_makefile(&module_def);
    9393  if(module_def.fmtfp != NULL) fclose(module_def.fmtfp);
  • modules/modgen/misc.cc

    rdd10b1 rcffe626  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.4 2000-01-21 09:23:21 krueger Exp $ */
     4/* $Id: misc.cc,v 1.5 2000-01-27 12:39:59 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    5353#define SELF_CMD MAX_TOK+1
    5454
    55 void enter_id(FILE *fp, char *name, char *value);
     55extern void enter_id(FILE *fp, idtyp t, char *name, char *value,
     56                     int lineno, char *file);
     57extern void write_enter_id(FILE *fp);
     58
    5659static void  mod_write_ctext(FILE *fp, FILE *fp_in);
    5760char type_conv[MAX_TOK][32];
     
    199202{
    200203  char *name;
    201   void (*write_cmd)(moddefv module, procdefv pi);
     204  void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL);
    202205  cmd_token id;
     206  int args;
    203207} valid_cmds[] = {
    204   { "declaration",  write_function_declaration,  CMD_DECL  },
    205   { "typecheck",    write_function_typecheck,  CMD_CHECK },
    206   { "return",       write_function_return,  CMD_RETURN },
    207   { NULL,           0, CMD_NONE }
     208  { "declaration",  write_function_declaration, CMD_DECL,   0 },
     209  { "typecheck",    write_function_typecheck,   CMD_CHECK,  0 },
     210  { "return",       write_function_return,      CMD_RETURN, 1 },
     211  { NULL,           0, CMD_NONE, 0 }
    208212};
    209213
    210214cmd_token checkcmd(
    211215  char *cmdname,
    212   void (**write_cmd)(moddefv module, procdefv pi)
     216  void (**write_cmd)(moddefv module, procdefv pi, void *arg),
     217  int args
    213218  )
    214219{
     
    226231  var_type type;
    227232  var_token id;
     233  void (*write_cmd)(moddefv module, var_token type = VAR_NONE,
     234                    idtyp t, void *arg1 = NULL, void *arg2 = NULL);
    228235} valid_vars[] = {
    229   { "module",       VAR_STRING,  VAR_MODULE },
    230   { "version",      VAR_STRING,  VAR_VERSION },
    231   { "info",         VAR_STRING,  VAR_INFO },
    232   { "help",         VAR_STRING,  VAR_HELP },
     236  { "module",       VAR_STRING,  VAR_MODULE,  0 },
     237  { "version",      VAR_STRING,  VAR_VERSION, write_main_variable },
     238  { "info",         VAR_STRING,  VAR_INFO,    write_main_variable },
     239  { "help",         VAR_STRING,  VAR_HELP,    write_main_variable },
     240#if 0
    233241  { "do_typecheck", VAR_BOOL,    VAR_TYPECHECK },
    234   { "do_return",    VAR_BOOL,    VAR_RETURN },
    235   { "function",     VAR_STRING,  VAR_FUNCTION },
    236   { NULL,           VAR_UNKNOWN, VAR_NONE }
     242#endif
     243  { NULL,           VAR_UNKNOWN, VAR_NONE, 0 }
    237244};
    238245
    239246var_token checkvar(
    240247  char *varname,
    241   var_type type
     248  var_type type,
     249  void (**write_cmd)(moddefv module, var_token type,
     250                    idtyp t, void *arg1, void *arg2)
    242251  )
    243252{
     
    245254  for(i=0; valid_vars[i].name!=NULL; i++)
    246255    if((strcmp(valid_vars[i].name, varname)==0) &&
    247        (valid_vars[i].type == type) ) return valid_vars[i].id;
     256       (valid_vars[i].type == type) ) {
     257      *write_cmd = valid_vars[i].write_cmd;
     258      return valid_vars[i].id;
     259    }
    248260  return VAR_NONE;
     261}
     262
     263void write_main_variable(
     264  moddefv module,
     265  var_token type,
     266  idtyp t,
     267  void *arg1,
     268  void *arg2
     269  )
     270{
     271  enter_id(module->fmtfp, t, (char *)arg1, (char *)arg2, yylineno,
     272           module->filename);
    249273}
    250274
     
    325349
    326350/*========================================================================*/
    327 void Add2proclist(
    328   moddefv module,
    329   char *name,
    330   char *ret_val,
    331   char *ret_typname,
    332   int ret_typ
    333   )
    334 {
    335   procdef pnew;
    336   logx("Add2proclist(%s, %s)\n", name, ret_val);
    337  
    338   memset((void *)&pnew, '\0', sizeof(procdef));
    339 
    340   pnew.procname = (char *)malloc(strlen(name)+1);
    341   if(pnew.procname==NULL) printf("Error 1\n");
    342   memset(pnew.procname, '\0', strlen(name)+1);
    343   memcpy(pnew.procname, name, strlen(name));
    344 
    345   pnew.funcname = (char *)malloc(strlen(name)+1);
    346   if(pnew.funcname==NULL) printf("Error 1\n");
    347   memset(pnew.funcname, '\0', strlen(name)+1);
    348   memcpy(pnew.funcname, name, strlen(name));
    349 
    350   pnew.param = NULL;
    351   (pnew).is_static = 0;
    352   (pnew).paramcnt = 0;
    353   pnew.c_code = NULL;
    354  
    355   pnew.return_val.name = (char *)malloc(strlen(ret_val)+1);
    356   memset(pnew.return_val.name, '\0', strlen(ret_val)+1);
    357   memcpy(pnew.return_val.name, ret_val, strlen(ret_val));
    358  
    359   pnew.return_val.typname = (char *)malloc(strlen(ret_typname)+1);
    360   memset(pnew.return_val.typname, '\0', strlen(ret_typname)+1);
    361   memcpy(pnew.return_val.typname, ret_typname, strlen(ret_typname));
    362   pnew.return_val.typ = ret_typ;
    363  
    364   if(module->proccnt==0) {
    365     module->procs = (procdefv)malloc(sizeof(procdef)+1);
    366   }
    367   else {
    368     module->procs = (procdefv)realloc(module->procs,
    369                                    (module->proccnt+1)*sizeof(procdef));
    370   }
    371   if(module->procs == NULL) { printf("ERROR\n"); return; }
    372  
    373   memset((void *) &module->procs[module->proccnt], '\0', sizeof(procdef));
    374   memcpy((void *)(&(module->procs[module->proccnt])),
    375          (void *)&pnew, sizeof(procdef));
    376   (module->proccnt)++;
    377 }
    378 
    379 /*========================================================================*/
    380 void PrintProclist(
    381   moddefv module
    382   )
    383 {
    384   logx("PrintProclist()\n");
    385   int j;
    386   for(j=0; j<module->proccnt; j++) {
    387     PrintProc(&(module->procs[j]));
    388   }
    389 }
    390 
    391 /*========================================================================*/
    392 void generate_mod(
    393   moddefv module,
    394   int section
    395   )
    396 {
    397   procdefv v = NULL;
    398   cfilesv c_filelist = NULL;
    399   int proccnt;
    400   FILE *fp_h;
    401   char *filename;
    402  
     351void init_system_type()
     352{
    403353  if(strcmp(S_UNAME, "ix86-Linux") == 0) {
    404354    systyp = SYSTYP_LINUX;
     
    408358    systyp = SYSTYP_HPUX10;
    409359  }
    410   init_type_conv();
    411   printf("SYSTYP:%d\n", systyp);
     360}
     361
     362/*========================================================================*/
     363void PrintProclist(
     364  moddefv module
     365  )
     366{
     367  logx("PrintProclist()\n");
     368  int j;
     369  for(j=0; j<module->proccnt; j++) {
     370    PrintProc(&(module->procs[j]));
     371  }
     372}
     373
     374/*========================================================================*/
     375void generate_mod(
     376  moddefv module,
     377  int section
     378  )
     379{
     380  procdefv v = NULL;
     381  cfilesv c_filelist = NULL;
     382  int proccnt;
     383  FILE *fp_h;
     384  char *filename;
    412385 
    413386  switch(section) {
     
    440413  /* building entry-functions */
    441414  for(proccnt=0; proccnt<module->proccnt; proccnt++) {
    442     generate_function(&module->procs[proccnt], module->modfp);
     415    //generate_function(&module->procs[proccnt], module->modfp);
    443416    //generate_header(&module->procs[proccnt], fp_h);
    444417  }
     
    467440#if 0
    468441  if(pi->paramcnt>0) {
    469     if(pi->param[0].typ!=SELF_CMD) {
    470       switch( pi->return_val.typ) {
    471           case SELF_CMD:
    472             fprintf(module->fmtfp, "    return(%s(res", pi->funcname);
    473             for (i=0;i<pi->paramcnt; i++)
    474               fprintf(module->fmtfp, ", (%s) res%d->Data()",
    475                       type_conv[pi->param[i].typ], i);
    476             fprintf(module->fmtfp, "));\n\n");
    477            break;
    478 
    479           default:
    480             fprintf(module->fmtfp, "  res->rtyp = %s;\n", pi->return_val.typname);
    481             fprintf(module->fmtfp, "  res->data = (void *)%s(", pi->funcname);
    482             for (i=0;i<pi->paramcnt; i++) {
    483               fprintf(module->fmtfp, "(%s) res%d->Data()",
    484                       type_conv[pi->param[i].typ], i);
    485               if(i<pi->paramcnt-1) fprintf(module->fmtfp, ", ");
    486             }
    487             fprintf(module->fmtfp, ");\n  return FALSE;\n\n");
    488       }
    489      
    490       fprintf(module->fmtfp, "  mod_%s_error:\n", pi->funcname);
    491       fprintf(module->fmtfp, "    Werror(\"%s(`%%s`) is not supported\", Tok2Cmdname(tok));\n",
    492               pi->procname);
    493       fprintf(module->fmtfp, "    Werror(\"expected %s(", pi->procname);
    494       for (i=0;i<pi->paramcnt; i++) {
    495         fprintf(module->fmtfp, "'%s'", pi->param[i].name);
    496         if(i!=pi->paramcnt-1) fprintf(module->fmtfp, ",");
    497       }
    498       fprintf(module->fmtfp, ")\");\n");
    499       fprintf(module->fmtfp, "    return TRUE;");
    500     }
    501442  }
    502443  else {
     
    525466void  mod_write_header(FILE *fp, char *module, char what)
    526467{
    527 #if 0
    528   FILE *fp;
    529   char buf[BUFLEN];
    530  
    531   regex_t preg;
    532   regmatch_t   pmatch[1];
    533   size_t  nmatch = 0;
    534   char *regex = "@MODULE_NAME@";
    535 
    536   rc = regcomp(&preg, regex, REG_NOSUB);
    537   if(rc) return -1;
    538 
    539   if(!regexec(&preg, d_entry->d_name, nmatch, pmatch, REG_NOTBOL))
    540     cert_count++;
    541   regfree(&preg);
    542  
    543 #else
     468
    544469  write_header(fp, module);
    545470  fprintf(fp, "#include <stdlib.h>\n");
     
    550475  fprintf(fp, "\n");
    551476  fprintf(fp, "#include <locals.h>\n");
    552   if(what != 'h')  fprintf(fp, "#include \"%s.h\"\n", module);
     477  if(what != 'h') {
     478    fprintf(fp, "#include \"%s.h\"\n", module);
     479    write_enter_id(fp);
     480    fprintf(fp, "\n");
     481  }
    553482  fprintf(fp, "\n");
    554 
    555   fprintf(fp, "void enter_id(char *name, char *value);\n");
    556   fprintf(fp, "\n");
    557 #endif
    558483}
    559484
     
    572497
    573498/*========================================================================*/
    574 void enter_id(FILE *fp, char *name, char *value, int lineno, char *file)
    575 {
     499void enter_id(
     500  FILE *fp,
     501  idtyp t,
     502  char *name,
     503  char *value,
     504  int lineno,
     505  char *file
     506  )
     507{
     508  char tname[32];
     509 
    576510  if(lineno)
    577511    fprintf(fp, "#line %d \"%s\"\n", lineno, file);
    578   fprintf(fp, "  enter_id(\"%s\",\"%s\");\n",name, value);
     512  fprintf(fp, "  enter_id(\"%s\",\"%s\", %s);\n",name, value,
     513          decl2str(t, tname));
    579514}
    580515
  • modules/modgen/modgen.h

    rdd10b1 rcffe626  
    11/*
    2  *  $Id: modgen.h,v 1.4 2000-01-21 09:23:21 krueger Exp $
     2 *  $Id: modgen.h,v 1.5 2000-01-27 12:40:00 krueger Exp $
    33 *
    44 */
     
    1313
    1414#include <stdio.h>
     15#include <string.h>
     16#include <mod2.h>
     17#include <subexpr.h>
    1518
    1619class paramdef;
     
    5457  char *c_code;
    5558  char *help_string;
     59  long example_len;
     60  char *example_string;
    5661};
    5762
     
    95100 *
    96101 */
    97 extern cmd_token checkcmd(char *cmdname,
    98                           void(**write_cmd)(moddefv module, procdefv pi));
    99 extern var_token checkvar(char *varname, var_type type);
    100102
    101103
     
    107109
    108110extern void PrintProclist(moddefv module);
    109 extern void Add2proclist(moddefv module, char *name, char *ret_val,
    110                            char *ret_typname, int ret_typ);
    111111extern void generate_mod(moddefv module, int section);
    112112extern void mod_create_makefile(moddefv module);
    113113extern void Add2files(moddefv module, char *buff);
    114114
    115 extern void generate_function(procdefv pi, FILE *fp);
    116115extern void  mod_copy_tmp(FILE *fp_out, FILE *fp_in);
    117116extern void mod_write_header(FILE *fp, char *module, char what);
     
    133132extern int create_tmpfile(moddefv module_def);
    134133
     134/* from proc.cc */
     135extern void write_example(moddefv module, procdefv proc);
     136
    135137extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp);
    136138extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp);
    137 extern void write_function_declaration(moddefv module, procdefv pi);
    138 extern void write_function_typecheck(moddefv module, procdefv pi);
    139 extern void write_function_return(moddefv module, procdefv pi);
     139extern void write_function_declaration(moddefv module, procdefv pi, void *arg = NULL);
     140extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL);
     141extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL);
     142extern void write_function_errorhandling(procdefv pi, FILE *fp);
     143
     144/* from misc.cc */
     145extern cmd_token checkcmd(
     146  char *cmdname,
     147  void(**write_cmd)(moddefv module, procdefv pi, void *arg),
     148  int args);
     149extern var_token checkvar(
     150  char *varname, var_type type,
     151  void (**write_cmd)(moddefv module, var_token type, idtyp t,
     152                     void *arg1, void *arg2));
     153void write_main_variable(moddefv module, var_token type,
     154                         idtyp t, void *arg1, void *arg2);
    140155
    141156#endif /* _MODGEN_H */
  • modules/modgen/proc.cc

    rdd10b1 rcffe626  
    11/*
    2  * $Id: proc.cc,v 1.4 2000-01-21 13:38:52 krueger Exp $
     2 * $Id: proc.cc,v 1.5 2000-01-27 12:40:03 krueger Exp $
    33 */
    44
     
    1212#include "typmap.h"
    1313
     14extern int trace;
    1415
    1516#if 1
     
    2122
    2223extern void PrintProc(procdefv pi);
    23 void write_function(moddefv module, procdefv proc);
     24//void write_function(moddefv module, procdefv proc);
     25static void write_function_declaration(procdefv pi, FILE *fp);
    2426static void  write_procedure_header(moddefv module, procdefv pi, FILE *fmtfp);
    2527static void gen_func_param_check(FILE *fp, procdefv pi, int i);
     
    3133void setup_proc(
    3234  moddefv module,
    33   procdefv p
    34 )
    35 {
    36 
    37   if( p == NULL ) return;
    38   write_function(module, p);
    39  
    40 //  PrintProc(p);
    41   return;
    42 }
    43 
     35  procdefv proc
     36)
     37{
     38  /* if proc is NULL, just return */
     39  if( proc == NULL ) return;
     40
     41//  if(proc->funcname == NULL) proc->funcname = strdup(proc->procname);
     42  if(proc->return_val.typ == NONE) {
     43    if(proc->return_val.typname == NULL) {
     44      proc->return_val.typname = strdup("NONE");
     45    }
     46  }
     47  if(trace) printf("\tcreating '%s'...", proc->procname); fflush(stdout);
     48 
     49  /* write call to add procname to list */
     50  fprintf(module->modfp, "#line %d \"%s\"\n", proc->lineno, module->filename);
     51  fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
     52          module->name, proc->procname,
     53          proc->is_static ? "TRUE" : "FALSE",
     54          proc->procname);
     55  if(proc->help_string!=NULL) {
     56    fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(helphdl) ,");
     57    fprintf(module->modfp, " IDID(helphdl));\n");
     58    fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
     59    fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->help_string);
     60    fprintf(module->modfp, "  namespaceroot->push();\n");
     61  }
     62  fprintf(module->modfp, "\n");
     63
     64  write_procedure_header(module, proc, module->fmtfp);
     65  fprintf(module->modfp_h,
     66          "BOOLEAN mod_%s(leftv res, leftv h);\n", proc->procname);
     67  //  printf(" done\n");
     68}
     69
     70/*========================================================================*/
     71void write_example(
     72  moddefv module,
     73  procdefv proc
     74  )
     75{
     76  /* if proc is NULL, just return */
     77  if( proc == NULL ) return;
     78
     79  if(proc->example_string!=NULL) {
     80    fprintf(module->modfp, "  namespaceroot->push( IDPACKAGE(examplehdl) ,");
     81    fprintf(module->modfp, " IDID(examplehdl));\n");
     82    fprintf(module->modfp, "  enter_id(\"%s\",", proc->procname);
     83    fprintf(module->modfp, " \"%s\", STRING_CMD);\n", proc->example_string);
     84    fprintf(module->modfp, "  namespaceroot->push();\n");
     85  }
     86}
    4487/*========================================================================*/
    4588/*
     
    5396  int i;
    5497 
    55   fprintf(fp, "BOOLEAN mod_%s(leftv res, leftv h);\n", pi->funcname);
     98#if 0
    5699  switch( pi->return_val.typ) {
    57100      case SELF_CMD:
     
    68111  }
    69112  fprintf(fp, ");\n\n");
    70 }
    71 
    72 /*========================================================================*/
    73 void write_function(
    74   moddefv module,
    75   procdefv proc
    76 )
    77 {
    78   if(proc->funcname == NULL) proc->funcname = strdup(proc->procname);
    79   if(proc->return_val.typ == NONE) {
    80     //if(proc->return_val.name == NULL) proc->return_val.name = strdup("none");
    81     if(proc->return_val.typname == NULL) {
    82     proc->return_val.typname = strdup("NONE");
    83     }
    84   }
    85   printf("\tcreating '%s'...", proc->procname); fflush(stdout);
    86  
    87   fprintf(module->modfp, "#line %d \"%s\"\n", proc->lineno, module->filename);
    88   fprintf(module->modfp, "  iiAddCproc(\"%s\",\"%s\",%s, mod_%s);\n",
    89           module->name, proc->procname,
    90           proc->is_static ? "TRUE" : "FALSE",
    91           proc->funcname);
    92 
    93   write_procedure_header(module, proc, module->fmtfp);
    94 //  generate_function(proc, module->fmtfp);
    95   write_function_declaration(proc, module->modfp_h);
    96   printf(" done\n");
    97  
    98   return;
    99 }
    100 
     113#endif
     114}
     115
     116/*========================================================================*/
    101117void write_function_declaration(
    102118  moddefv module,
    103   procdefv pi
     119  procdefv pi,
     120  void *arg
    104121  )
    105122{
     
    120137void write_function_typecheck(
    121138  moddefv module,
    122   procdefv pi
     139  procdefv pi,
     140  void *arg
    123141  )
    124142{
     
    129147void write_function_return(
    130148  moddefv module,
    131   procdefv pi
    132   )
    133 {
     149  procdefv pi,
     150  void *arg
     151  )
     152{
     153  int i;
     154
     155  if(arg!=NULL) {
     156    if( pi->funcname != NULL ) free(pi->funcname);
     157    pi->funcname = strdup((char *)arg);
     158    printf("CMD: return(%s)\n", arg);
     159
     160    /* write function declaration to header file */
     161    switch( pi->return_val.typ) {
     162        case SELF_CMD:
     163          fprintf(module->modfp_h, "BOOLEAN %s(res, ", pi->funcname);
     164          break;
     165
     166        default:
     167          fprintf(module->modfp_h, "%s %s(", type_conv[pi->return_val.typ],
     168                  pi->funcname);
     169    }
     170    for (i=0;i<pi->paramcnt; i++) {
     171      fprintf(module->modfp_h, "%s res%d", type_conv[pi->param[i].typ], i);
     172      if(i<pi->paramcnt-1) fprintf(module->modfp_h, ", ");
     173    }
     174    fprintf(module->modfp_h, ");\n\n");
     175  }
     176  else  printf("CMD: return()\n");
     177
    134178  write_procedure_return(module, pi, module->fmtfp);
    135179}
     
    159203 
    160204  fprintf(fmtfp, "#line %d \"%s\"\n", pi->lineno, module->filename);
    161   fprintf(fmtfp, "BOOLEAN mod_%s(leftv res, leftv h)\n{\n", pi->funcname);
     205  fprintf(fmtfp, "BOOLEAN mod_%s(leftv res, leftv h)\n{\n", pi->procname);
    162206}
    163207
     
    191235
    192236    fprintf(fmtfp, "  if(v!=NULL) { tok = v->Typ(); goto mod_%s_error; }\n",
    193             pi->funcname);
     237            pi->procname);
    194238
    195239    fprintf(fmtfp, "\n");
     
    220264  )
    221265{
    222   fprintf(fp, "  if(v==NULL) goto mod_%s_error;\n", pi->funcname);
     266  fprintf(fp, "  if(v==NULL) goto mod_%s_error;\n", pi->procname);
    223267  fprintf(fp, "  tok = v->Typ();\n");
    224268  fprintf(fp, "  if((index=iiTestConvert(tok, %s))==0)\n",
    225269          pi->param[i].typname);
    226   fprintf(fp, "     goto mod_%s_error;\n", pi->funcname);
     270  fprintf(fp, "     goto mod_%s_error;\n", pi->procname);
    227271  fprintf(fp, "  v_save = v->next;\n");
    228272  fprintf(fp, "  v->next = NULL;\n");
    229273  fprintf(fp, "  if(iiConvert(tok, %s, index, v, res%d))\n",
    230274          pi->param[i].typname, i);
    231   fprintf(fp, "     goto mod_%s_error;\n", pi->funcname);
     275  fprintf(fp, "     goto mod_%s_error;\n", pi->procname);
    232276  fprintf(fp, "  v = v_save;\n");
    233277}
     
    250294  int i;
    251295 
    252 /*  if(pi->flags.do_return) {*/
    253     printf("\nWriting return-block\n");
     296  printf("\nWriting return-block\n");
    254297   
     298  printf("### RETURN: '%s' '%s' '%d'\n", pi->return_val.name,
     299         pi->return_val.typname, pi->return_val.typ);
     300  if(pi->funcname == NULL) {
     301    fprintf(fmtfp, "  res->rtyp = NONE;\n");
     302    fprintf(fmtfp, "  res->data = NULL;\n");
     303    fprintf(fmtfp, "  return TRUE;\n");
     304  }
     305  else
    255306    switch( pi->return_val.typ) {
    256307        case SELF_CMD:
     
    264315        case NONE:
    265316          fprintf(fmtfp, "  res->rtyp = %s;\n", pi->return_val.typname);
     317          fprintf(fmtfp, "  res->data = NULL;\n");
    266318          fprintf(fmtfp, "  return(%s(", pi->funcname);
    267319          for (i=0;i<pi->paramcnt; i++) {
     
    281333            if(i<pi->paramcnt-1) fprintf(fmtfp, ", ");
    282334          }
    283           fprintf(fmtfp, ");\n  return FALSE;\n\n");
    284     }
    285     /*}*/
     335          fprintf(fmtfp, ");\n");
     336          fprintf(fmtfp, "  if(res->data != NULL) return FALSE;\n");
     337          fprintf(fmtfp, "  else return TRUE;\n\n");
     338    }
    286339}
    287340
     
    297350#endif
    298351
    299 void generate_function(procdefv pi, FILE *fp)
     352void write_function_errorhandling(procdefv pi, FILE *fp)
    300353{
    301354  int cnt = 0, i;
     
    303356    if(pi->flags.typecheck_done) {
    304357      printf("error handling..."); fflush(stdout);
    305       fprintf(fp, "  mod_%s_error:\n", pi->funcname);
     358      fprintf(fp, "  mod_%s_error:\n", pi->procname);
    306359      fprintf(fp, "    Werror(\"%s(`%%s`) is not supported\", Tok2Cmdname(tok));\n",
    307360              pi->procname);
  • modules/modgen/proc_setup.cc

    rdd10b1 rcffe626  
    11/*
    2  * $Id: proc_setup.cc,v 1.2 2000-01-21 09:23:22 krueger Exp $
     2 * $Id: proc_setup.cc,v 1.3 2000-01-27 12:40:54 krueger Exp $
    33 */
    44
     
    3838  if( p->funcname != NULL ) free(p->funcname);
    3939  if( p->c_code != NULL ) free(p->c_code);
     40  if( p->help_string != NULL) free(p->help_string);
     41  if( p->example_string != NULL) free(p->example_string);
    4042  if( p->paramcnt>0 ) {
    4143    //free(p->param);
     
    4446  memset((void *)p, 0, sizeof(procdef));
    4547  p->procname = strdup(procname);
     48
    4649  if( ret != NULL ) {
    4750    char typname[32];
     
    5053    ret->typname = strdup(typname);
    5154    memcpy((void *)(&p->return_val), (void *)ret, sizeof(paramdef));
    52   }
     55  } else {
     56    p->return_val.name = strdup("NONE");
     57    p->return_val.typname = strdup("NONE");
     58    p->return_val.typ = NONE;
     59  }
     60 
    5361  p->lineno = lineno;
    54   p->return_val.typ = NONE;
    5562  p->flags.do_typecheck = default_do_typecheck;
    5663  p->flags.do_return = default_do_return;
     
    177184        q = (char *)varvalue;
    178185        switch(varid) {
    179             case VAR_FUNCTION:
    180               if(p->funcname != NULL) free(p->funcname);
    181               p->funcname = strdup(q);
    182               break;
    183186            case VAR_HELP:
    184187              break;
  • modules/modgen/scanner.l

    rdd10b1 rcffe626  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 /* $Id: scanner.l,v 1.4 2000-01-21 09:23:22 krueger Exp $ */
     5/* $Id: scanner.l,v 1.5 2000-01-27 12:40:55 krueger Exp $ */
    66#include <stdio.h>
    77#include <string.h>
     
    1313#include "grammar.h"
    1414
    15 /*#define DEBUG 3*/
     15#define DEBUG 3
    1616 
    1717#  define YYLP_ERR_NONE    0
     
    105105WS             [[:blank:]]+
    106106NL             \r?\n
     107WSNL           ([ \t\n\r]+)
    107108EQ             (([{WS}]+=[{WS}]+)|=)
    108109
     
    258259                  return PROCDECLTOK;
    259260                }
     261        example+{WSNL}+"{" {
     262                  printf(">>>EXAMPLE\n");
     263                  brace1 = 1; /* { */
     264                  brace2 = 0; /* ( */
     265                  brace3 = 0; /* [ */
     266                  push_state(YYSTATE, CODEBLOCK2, "CODEBLOCK2");
     267                  return EXAMPLETOK;
     268                }
    260269        .       { printf("<<<'%s' ", yytext); }
    261270
     
    328337
    329338                     pop_state();
     339#if 0
    330340                     s = t = lvalp->name = dupyytext();
    331341                     while (*yytext)
     
    335345                     }
    336346                     if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0';
     347#else
     348                     lvalp->name = yytext;
     349#endif
    337350#if DEBUG > 1
    338351                     printf("2 BRACE DOWN=%d\n", brace1);
     
    352365<PROCCMDBLOCK>{
    353366       {col}  { pop_state(); return ';'; }
     367        "("     { return '('; }
     368        ")"     { return ')'; }
    354369       {WS}    /* ignore */
    355        {NAME} { lvalp->name = strdup(yytext); return PROCCMD; }
     370       {NAME} { lvalp->name = strdup(yytext); return NAME; }
    356371       .      { printf("PCB: '%s'\n", yytext); }
    357372       }
  • modules/modgen/utils.cc

    rdd10b1 rcffe626  
    11/*
    2  * $Id: utils.cc,v 1.3 2000-01-21 09:23:22 krueger Exp $
     2 * $Id: utils.cc,v 1.4 2000-01-27 12:40:53 krueger Exp $
    33 */
    44
     
    99#include <ctype.h>
    1010#include "modgen.h"
     11
     12void init_system_type();
    1113
    1214/*========================================================================*/
     
    3638  memset(module_def->name, '\0', strlen(tmpfile)+1);
    3739  memcpy(module_def->name, tmpfile, strlen(tmpfile));
     40 
     41  init_system_type();
    3842 
    3943  return (create_tmpfile(module_def));
Note: See TracChangeset for help on using the changeset viewer.