Changeset d76127 in git


Ignore:
Timestamp:
May 1, 2000, 9:17:32 PM (23 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'spielwiese', 'f6c3dc58b0df4bd712574325fe76d0626174ad97')
Children:
8c8a76ef1d90b953025a5f8cefe0723f9fe5cb82
Parents:
172cdfc80c3ad17a576a439c847fa830ffac37e6
Message:
Major rewrite of section of module definition and added new commands


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

Legend:

Unmodified
Added
Removed
  • modules/modgen/grammar.y

    r172cdf rd76127  
    11/*
    2  * $Id: grammar.y,v 1.12 2000-04-17 07:21:24 krueger Exp $
     2 * $Id: grammar.y,v 1.13 2000-05-01 19:14:48 krueger Exp $
    33 */
    44
     
    2323extern int yylineno;
    2424extern int do_create_makefile;
     25extern char *sectname[];
    2526 
    2627extern int init_modgen(moddef *module_def, char *filename);
     
    5758
    5859%token SECTEND
     60/* SECT2: Singular procedure declaration */
     61%token SECT2START
    5962%token SECT2END
     63/* SECT3: procedure declaration */
     64%token SECT3START
    6065%token SECT3END
     66/* SECT4: C/C++ text */
     67%token SECT4START
     68%token SECT4END
     69
    6170/*%token PROCEND*/
    6271%token PROCDECLTOK
     
    7483%token <name> MCODETOK
    7584%token <name> CODEPART
     85%token <name> CMTPART
    7686%token <name> PROCCMD
    7787%token <name> ANYTOK
     
    8595%nonassoc '='
    8696%%
    87 goal: part1 sect2 sect2end code
    88         {
    89           if(trace)printf("Finish modules\n");
     97goal: part1 sect3 sect3end sect4
     98      {
     99          if(trace)printf("Finish modules 1\n");
    90100          return 0;
    91         }
     101      }
     102      | part1 sect3full sect4
     103      {
     104          if(trace)printf("Finish modules 2\n");
     105          return 0;
     106      }
     107      | part1 sect2full sect3full sect4
     108      {
     109          if(trace)printf("Finish modules 3\n");
     110          return 0;
     111      }
     112      | part1 sect3full sect2full sect4
     113      {
     114          if(trace)printf("Finish modules 4\n");
     115          return 0;
     116      }
    92117;
    93118
     
    134159        {
    135160          memset(&procedure_decl, 0, sizeof(procdef));
    136           if(debug>2)printf("End of section %d\n", sectnum-1);
     161          if(debug>2)printf("End of section 1 (new=%d)\n", sectnum);
    137162        }
    138163        ;
     
    158183                }
    159184                break;
    160               case 2: /* pass 2: procedure declaration */
     185              case 3: /* pass 3: procedure declaration */
    161186                if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) {
    162187                  proc_set_var(&procedure_decl, VAR_STRING, vt, $1, $3.string);
     
    182207                Add2files(&module_def, $3);
    183208                break;
    184               case 2: /* pass 2: procedure declaration */
     209              case 3: /* pass 3: procedure declaration */
    185210                if( (vt=checkvar($1, VAR_FILE, &write_cmd)) ) {
    186211                  proc_set_var(&procedure_decl, VAR_FILE, vt, $1, $3);
     
    200225              case 1: /* pass 1: */
    201226                break;
    202               case 2: /* pass 2: procedure declaration */
     227              case 3: /* pass 3: procedure declaration */
    203228                if( (vt=checkvar($1, VAR_FILES, &write_cmd)) ) {
    204229                  proc_set_var(&procedure_decl, VAR_FILES, vt, $1, &$3);
     
    218243              case 1: /* pass 1: */
    219244                break;
    220               case 2: /* pass 2: procedure declaration */
     245              case 3: /* pass 3: procedure declaration */
    221246                if( (vt=checkvar($1, VAR_NUM, &write_cmd)) ) {
    222247                  proc_set_var(&procedure_decl, VAR_NUM, vt, $1, &$3);
     
    244269                }
    245270                break;
    246               case 2: /* pass 2: procedure declaration */
     271              case 3: /* pass 3: procedure declaration */
    247272                if( (vt=checkvar($1, VAR_BOOL, &write_cmd)) ) {
    248273                  proc_set_var(&procedure_decl, VAR_BOOL, vt, $1, &$3);
     
    271296;
    272297
    273 sect2:  procdef
    274         | sect2 procdef
    275         ;
     298sect2full: SECT2START sect2 sect2end;
     299
     300sect2: procdefsg
     301       | sect2 procdefsg
     302       ;
    276303
    277304sect2end: SECT2END
     305{
     306          if(debug>2)printf("End of section 'Singular' 2 (%d)\n",
     307                            sectnum);
     308};
     309
     310
     311sect3full: SECT3START sect3 sect3end;
     312
     313sect3:  procdef
     314        | sect3 procdef
     315        ;
     316
     317sect3end: SECT3END
    278318        {
    279319          write_finish_functions(&module_def, &procedure_decl);
    280           if(debug>2)printf("End of section %d\n", sectnum-1);
     320          if(debug>2)printf("End of section 'procedures' 3 (%d)\n",
     321                            sectnum);
    281322        }
    282323        ;
     
    284325/*
    285326 */
    286 procdef: procdecl proccode
    287         {
    288           if(debug>2)printf("PROCDEF:\n");
     327procdefsg: procdeclsg proccode
     328        {
     329          if(debug>2)printf("SG-PROCDEF:\n");
    289330        }
    290331        | procdecl proccode procdeclexample
    291332        {
    292           if(debug>2)printf("PROCDEF mit example:\n");
     333          if(debug>2)printf("SG-PROCDEF mit example:\n");
    293334          fflush(module_def.fmtfp);
    294335        }
    295         ;
    296 
    297 procdecl: procdecl2 '{'
     336;
     337
     338procdeclsg: procdeclsg2 '{'
    298339        {
    299340          setup_proc(&module_def, &procedure_decl);
    300341        }
    301         | procdecl2 procdeclhelp '{'
     342        | procdeclsg2 procdeclhelp '{'
    302343        {
    303344          setup_proc(&module_def, &procedure_decl);
     
    305346        ;
    306347
    307 procdecl1: PROCDECLTOK NAME
    308         {
    309           init_proc(&procedure_decl, $2, NULL, yylineno, LANG_SINGULAR);
    310           free($2);
    311           if(write_singular_procedures(&module_def, &procedure_decl))
    312             return(myyyerror("Error while creating bin-file\n"));
    313         }
    314         | STATICTOK PROCDECLTOK NAME
    315         {
    316           init_proc(&procedure_decl, $3, NULL, yylineno, LANG_SINGULAR);
    317           procedure_decl.is_static = TRUE;
    318           free($3);
    319           if(write_singular_procedures(&module_def, &procedure_decl))
    320             return(myyyerror("Error while creating bin-file\n"));
    321         };
    322 
    323 procdecl2: procdecl1 '(' sgtypelist ')'
    324         | funcdecl1
    325         | funcdecl1 '(' ')'
    326         | funcdecl1 '(' typelist ')'
     348procdeclsg2: procdecl1 '(' sgtypelist ')'
     349         {
     350           write_singular_parameter(&module_def, yylineno, "list", "#");
     351           procedure_decl.lineno_other = yylineno;
     352         }
    327353        | procdecl1
    328354         {
     
    337363        ;
    338364
    339 funcdecl1: NAME
    340         {
    341           if(debug>2)printf("funcdecl1-1\n");
    342           init_proc(&procedure_decl, $1, NULL, yylineno);
    343           free($1);
    344         }
    345         | VARTYPETOK NAME
     365procdecl1: PROCDECLTOK NAME
     366        {
     367          init_proc(&procedure_decl, $2, NULL, yylineno, LANG_SINGULAR);
     368          free($2);
     369          if(write_singular_procedures(&module_def, &procedure_decl))
     370            return(myyyerror("Error while creating bin-file\n"));
     371        }
     372        | STATICTOK PROCDECLTOK NAME
     373        {
     374          init_proc(&procedure_decl, $3, NULL, yylineno, LANG_SINGULAR);
     375          procedure_decl.is_static = TRUE;
     376          free($3);
     377          if(write_singular_procedures(&module_def, &procedure_decl))
     378            return(myyyerror("Error while creating bin-file\n"));
     379        };
     380
     381procdef: procdecl proccode
     382        {
     383          if(debug>2)printf("PROCDEF:\n");
     384        }
     385        | procdecl proccode procdeclexample
     386        {
     387          if(debug>2)printf("PROCDEF mit example:\n");
     388          fflush(module_def.fmtfp);
     389        }
     390        ;
     391
     392procdecl: procdecl2 '{'
     393        {
     394          setup_proc(&module_def, &procedure_decl);
     395        }
     396        | procdecl2 procdeclhelp '{'
     397        {
     398          setup_proc(&module_def, &procedure_decl);
     399        }
     400        ;
     401
     402procdecl2: funcdecl1
     403        | funcdecl1 '(' ')'
     404        | funcdecl1 '(' typelist ')';
     405
     406funcdecl1: VARTYPETOK NAME
    346407        {
    347408          if(debug>2)printf("funcdecl1-2\n");
    348409          init_proc(&procedure_decl, $2, &$1, yylineno);
    349410          free($2);
    350         }
    351         | STATICTOK NAME
    352         {
    353           if(debug>2)printf("funcdecl1-3\n");
    354           init_proc(&procedure_decl, $2, NULL, yylineno);
    355           free($2);
    356           procedure_decl.is_static = TRUE;
    357411        }
    358412        | STATICTOK VARTYPETOK NAME
     
    382436proccodeline: CODEPART
    383437        {
     438          printf(">>>>(%d) %s<<<<\n", procedure_decl.flags.start_of_code, $1);
    384439          write_codeline(&module_def, &procedure_decl, $1, yylineno-1);
    385440        }
    386441        | proccodeline CODEPART
    387442        {
     443          printf(">>>>(%d) %s<<<<\n", procedure_decl.flags.start_of_code, $2);
     444          write_codeline(&module_def, &procedure_decl, $2);
     445        }
     446        | proccodeline CMTPART
     447        {
     448          printf(">>>>(%d) %s<<<<\n", procedure_decl.flags.start_of_code, $2);
    388449          write_codeline(&module_def, &procedure_decl, $2);
    389450        }
     
    445506                          yylineno, $2, sectnum));
    446507                break;
     508
     509              case CMD_DECL:
     510              case CMD_CHECK:
     511                procedure_decl.flags.auto_header = 0;
     512              case CMD_NODECL:
     513                write_cmd(&module_def, &procedure_decl);
     514                break;
     515
    447516              default:
     517                write_function_header(&module_def, &procedure_decl);
    448518                write_cmd(&module_def, &procedure_decl);
    449519          }
     
    465535                break;
    466536              default:
    467                 write_cmd(&module_def, &procedure_decl,
    468                           procedure_decl.procname);
     537                write_function_header(&module_def, &procedure_decl);
     538              case CMD_DECL:
     539              case CMD_CHECK:
     540                write_cmd(&module_def, &procedure_decl);
    469541          }
    470542          free($2);
     
    485557                break;
    486558              default:
     559                write_function_header(&module_def, &procedure_decl);
     560              case CMD_DECL:
     561              case CMD_CHECK:
    487562                write_cmd(&module_def, &procedure_decl, $4);
    488563          }
     
    504579                break;
    505580              default:
     581                write_function_header(&module_def, &procedure_decl);
     582              case CMD_DECL:
     583              case CMD_CHECK:
    506584                write_cmd(&module_def, &procedure_decl, $4);
    507585          }
     
    523601                break;
    524602              default:
     603                write_function_header(&module_def, &procedure_decl);
     604              case CMD_DECL:
     605              case CMD_CHECK:
    525606                write_cmd(&module_def, &procedure_decl, $4);
    526607          }
     
    607688        ;
    608689
    609 code:  codeline SECT3END
    610         {
    611           fprintf(module_def.modfp, "%s", $1);
    612         }
    613 ;
     690sect4:  SECT4START codeline SECT4END
     691        {
     692          fprintf(module_def.modfp, "'%s'", $2);
     693        };
    614694
    615695codeline: CODEPART
  • modules/modgen/misc.cc

    r172cdf rd76127  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: misc.cc,v 1.9 2000-03-30 06:35:45 krueger Exp $ */
     4/* $Id: misc.cc,v 1.10 2000-05-01 19:17:32 krueger Exp $ */
    55/*
    66* ABSTRACT: lib parsing
     
    187187} valid_cmds[] = {
    188188  { "declaration",  write_function_declaration, CMD_DECL,   CMDT_SINGLE, 0 },
     189  { "error",        write_function_error,       CMD_ERROR,  CMDT_ANY,    0 },
     190  { "nodeclaration",write_function_nodecl,      CMD_NODECL, CMDT_SINGLE, 0 },
    189191  { "typecheck",    write_function_typecheck,   CMD_CHECK,  CMDT_SINGLE, 0 },
    190   { "return",       write_function_result,      CMD_RETURN, CMDT_EQ,     0 },
    191   { "return",       write_function_return,      CMD_RETURN, CMDT_SINGLE, 1 },
     192//{ "return",       write_function_result,      CMD_RETURN, CMDT_EQ,     0 },
     193//{ "return",       write_function_return,      CMD_RETURN, CMDT_SINGLE, 1 },
    192194  { "return",       write_function_return,      CMD_RETURN, CMDT_0,     1 },
    193195  { "return",       write_function_return,      CMD_RETURN, CMDT_ANY,   1 },
     
    225227                    idtyp t, void *arg1 = NULL, void *arg2 = NULL);
    226228} valid_vars[] = {
    227   { "module",       VAR_STRING,  VAR_MODULE,  0 },
     229  { "help",         VAR_STRING,  VAR_HELP,    write_main_variable },
     230  { "info",         VAR_STRING,  VAR_INFO,    write_main_variable },
     231  { "package",      VAR_STRING,  VAR_MODULE,  0 },
    228232  { "version",      VAR_STRING,  VAR_VERSION, write_main_variable },
    229   { "info",         VAR_STRING,  VAR_INFO,    write_main_variable },
    230   { "help",         VAR_STRING,  VAR_HELP,    write_main_variable },
    231 #if 0
    232   { "do_typecheck", VAR_BOOL,    VAR_TYPECHECK },
    233 #endif
    234233  { NULL,           VAR_UNKNOWN, VAR_NONE, 0 }
    235234};
     
    280279  printf(")\n");
    281280  if(pi->return_val.typ!=0)
    282     printf("\treturn = %s (%s)\n", pi->return_val.name, pi->return_val.typname);
     281    printf("\treturn = %s (%s)\n", pi->return_val.name,
     282           pi->return_val.typname);
    283283  printf("{%s}\n", pi->c_code);
    284284}
     
    443443           
    444444        default:
    445           fprintf(module->fmtfp, "  res->rtyp = %s;\n", pi->return_val.typname);
    446           fprintf(module->fmtfp, "  res->data = (void *)%s();\n", pi->funcname);
     445          fprintf(module->fmtfp, "  res->rtyp = %s;\n",
     446                  pi->return_val.typname);
     447          fprintf(module->fmtfp, "  res->data = (void *)%s();\n",
     448                  pi->funcname);
    447449          fprintf(module->fmtfp, "  return FALSE;");
    448450    }
     
    521523{
    522524  strcpy(type_conv[NONE], "none");
    523   strcpy(type_conv[NONE], "void");
     525//  strcpy(type_conv[NONE], "void");
    524526  strcpy(type_conv[INT_CMD], "int");
    525527  strcpy(type_conv[RING_CMD], "ring");
  • modules/modgen/modgen.h

    r172cdf rd76127  
    11/*
    2  *  $Id: modgen.h,v 1.11 2000-03-30 06:36:10 krueger Exp $
     2 *  $Id: modgen.h,v 1.12 2000-05-01 19:14:48 krueger Exp $
    33 *
    44 */
     
    3333class procflags {
    3434  public:
     35  char start_of_code;
    3536  char declaration_done;
    3637  char typecheck_done;
    37  
     38
     39  char auto_header;
     40  char do_declaration;
    3841  char do_typecheck;
    3942  char do_return;
     
    110113
    111114typedef enum { CMD_NONE, CMD_BADSYNTAX, CMD_DECL, CMD_CHECK, CMD_RETURN,
    112                CMD_SINGULAR
     115               CMD_SINGULAR, CMD_ERROR, CMD_NODECL
    113116} cmd_token;
    114117
     
    127130extern int debug;
    128131extern int trace;
     132extern int xyz;
    129133
    130134extern int IsCmd(char *n, int & tok);
     
    173177
    174178/* from proc.cc */
     179extern void write_function_header(moddefv module, procdefv proc);
    175180extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp);
    176181extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp);
    177182extern void write_function_declaration(moddefv module, procdefv pi, void *arg = NULL);
     183extern void write_function_nodecl(moddefv module, procdefv pi, void *arg = NULL);
     184extern void write_function_error(moddefv module, procdefv pi, void *arg = NULL);
    178185extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL);
    179186extern void write_function_result(moddefv module, procdefv pi, void *arg = NULL);
  • modules/modgen/proc.cc

    r172cdf rd76127  
    11/*
    2  * $Id: proc.cc,v 1.12 2000-03-30 06:35:45 krueger Exp $
     2 * $Id: proc.cc,v 1.13 2000-05-01 19:14:48 krueger Exp $
    33 */
    44
     
    8080
    8181/*========================================================================*/
     82void write_function_header(
     83  moddefv module,
     84  procdefv proc
     85  )
     86{
     87  if(!proc->flags.auto_header) return;
     88  if(!proc->flags.start_of_code) return;
     89
     90  if(debug>4) {
     91    printf("write_function_header: auto=%d\n", proc->flags.auto_header);
     92    printf("write_function_header: declaration: do=%d, done=%d\n",
     93           proc->flags.do_declaration,
     94           proc->flags.declaration_done);
     95    printf("write_function_header: typecheck: do=%d, done=%d\n",
     96           proc->flags.do_typecheck,
     97           proc->flags.typecheck_done);
     98  }
     99 
     100  if(proc->flags.do_declaration && !proc->flags.declaration_done)
     101    write_function_declaration(module, proc, module->fmtfp);
     102
     103  if(proc->flags.do_typecheck && !proc->flags.typecheck_done)
     104    write_function_typecheck(module, proc, module->fmtfp);
     105}
     106
     107/*========================================================================*/
    82108/*
    83109 * write declaration of function to file pointed by 'fp', usualy the
     
    116142{
    117143  int i;
     144  if(debug>4) printf("write_function_declaration: do=%d, done=%d\n",
     145                     pi->flags.do_declaration, pi->flags.declaration_done);
     146  if(pi->flags.declaration_done) return;
     147  if(!pi->flags.do_declaration) return;
    118148  if(pi->paramcnt>0) {
    119149    fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
    120150    fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
    121     fprintf(module->fmtfp, "  leftv v = h, v_save;\n");
    122     fprintf(module->fmtfp, "  int tok = NONE, index = 0;\n");
     151    fprintf(module->fmtfp, "  leftv __v = __h, __v_save;\n");
     152    fprintf(module->fmtfp, "  int __tok = NONE, __index = 0;\n");
    123153    for (i=0;i<pi->paramcnt; i++) {
    124154      fprintf(module->fmtfp,
    125               "  sleftv s%s; leftv z%s = &s%s;\n", pi->param[i].varname,
     155              "  sleftv __s%s; leftv __z%s = &__s%s;\n", pi->param[i].varname,
    126156              pi->param[i].varname, pi->param[i].varname);
    127157      fprintf(module->fmtfp, "  %s %s;\n", type_conv[pi->param[i].typ],
     
    131161    fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
    132162    fprintf(module->fmtfp, "\n");
    133     pi->flags.declaration_done = 1;
    134   }
     163  }
     164  pi->flags.declaration_done = 1;
     165}
     166
     167/*========================================================================*/
     168void write_function_nodecl(
     169  moddefv module,
     170  procdefv pi,
     171  void *arg
     172  )
     173{
     174  pi->flags.do_declaration = 0;
     175  pi->flags.do_typecheck = 0;
     176  pi->flags.auto_header = 0;
     177}
     178
     179/*========================================================================*/
     180void write_function_error(
     181  moddefv module,
     182  procdefv pi,
     183  void *arg
     184  )
     185{
     186  int i;
     187
     188  fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
     189  fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
     190  fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
     191  fprintf(module->fmtfp, "\n");
    135192}
    136193
     
    142199  )
    143200{
     201  if(debug>4) printf("write_function_typecheck: do=%d, done=%d\n",
     202                     pi->flags.do_typecheck, pi->flags.typecheck_done);
     203  if(pi->flags.typecheck_done) return;
     204  if(!pi->flags.do_typecheck) return;
     205
    144206  fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
    145207  fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
     
    178240    switch( pi->return_val.typ) {
    179241        case SELF_CMD:
    180           fprintf(module->modfp_h, "BOOLEAN %s(res, ", pi->funcname);
     242          fprintf(module->modfp_h, "BOOLEAN %s(__res, ", pi->funcname);
    181243          break;
    182244
     
    192254    fprintf(module->modfp_h, ");\n\n");
    193255  }
    194   else  if(debug>2)printf("CMD: return()\n");
    195 
     256  else {
     257    if(debug>2)printf("CMD: return()\n");
     258  }
     259 
    196260  fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename);
    197261  write_procedure_return(module, pi, module->fmtfp);
     
    243307 
    244308  fprintf(fmtfp, "#line %d \"%s\"\n", pi->lineno, module->filename);
    245   fprintf(fmtfp, "BOOLEAN mod_%s(leftv res, leftv h)\n{\n", pi->procname);
     309  fprintf(fmtfp, "BOOLEAN mod_%s(leftv __res, leftv __h)\n{\n", pi->procname);
    246310}
    247311
     
    274338    for (i=0;i<pi->paramcnt; i++) gen_func_param_check(fmtfp, pi, i);
    275339
    276     fprintf(fmtfp, "  if(v!=NULL) { tok = v->Typ(); goto mod_%s_error; }\n",
     340    fprintf(fmtfp,
     341            "  if(__v!=NULL) { __tok = __v->Typ(); goto mod_%s_error; }\n",
    277342            pi->procname);
    278343
     
    315380  fprintf(module->modfp, "#line %d \"%s.cc\"\n", modlineno++, module->name);
    316381  if(trace)printf("  done.\n");fflush(stdout);
    317   fclose(module->fmtfp);
    318   fclose(module->fmtfp2);
    319   fclose(module->fmtfp3);
     382  fclose(module->fmtfp); module->fmtfp = NULL;
     383  fclose(module->fmtfp2); module->fmtfp2 = NULL;
     384  fclose(module->fmtfp3); module->fmtfp3 = NULL;
    320385  return;
    321386}
     
    329394  )
    330395{
    331   fprintf(fp, "  if(v==NULL) goto mod_%s_error;\n", pi->procname);
    332   fprintf(fp, "  tok = v->Typ();\n");
    333   fprintf(fp, "  if((index=iiTestConvert(tok, %s))==0)\n",
     396  fprintf(fp, "  if(__v==NULL) goto mod_%s_error;\n", pi->procname);
     397  fprintf(fp, "  __tok = __v->Typ();\n");
     398  fprintf(fp, "  if((__index=iiTestConvert(__tok, %s))==0)\n",
    334399          pi->param[i].typname);
    335400  fprintf(fp, "     goto mod_%s_error;\n", pi->procname);
    336   fprintf(fp, "  v_save = v->next;\n");
    337   fprintf(fp, "  v->next = NULL;\n");
    338   fprintf(fp, "  if(iiConvert(tok, %s, index, v, z%s))\n",
     401  fprintf(fp, "  __v_save = __v->next;\n");
     402  fprintf(fp, "  __v->next = NULL;\n");
     403  fprintf(fp, "  if(iiConvert(__tok, %s, __index, __v, __z%s))\n",
    339404          pi->param[i].typname, pi->param[i].varname);
    340405  fprintf(fp, "     goto mod_%s_error;\n", pi->procname);
    341   fprintf(fp, "  v = v_save;\n");
    342   fprintf(fp, "  %s = (%s)z%s->Data();\n", pi->param[i].varname,
     406  fprintf(fp, "  __v = __v_save;\n");
     407  fprintf(fp, "  %s = (%s)__z%s->Data();\n", pi->param[i].varname,
    343408          type_conv[pi->param[i].typ], pi->param[i].varname);
    344409 
     
    368433  fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name);
    369434  if(pi->funcname == NULL) {
    370     if(!pi->flags.result_done) fprintf(fmtfp, "  res->data = NULL;\n");
    371     fprintf(fmtfp, "  res->rtyp = %s;\n", pi->return_val.typname);
     435    if(!pi->flags.result_done) fprintf(fmtfp, "  __res->data = NULL;\n");
     436    fprintf(fmtfp, "  __res->rtyp = %s;\n", pi->return_val.typname);
    372437    //fprintf(fmtfp, "  res->rtyp = NONE;\n");
    373438    //fprintf(fmtfp, "  res->data = NULL;\n");
     
    377442    switch( pi->return_val.typ) {
    378443        case SELF_CMD:
    379           fprintf(fmtfp, "    return(%s(res", pi->funcname);
     444          fprintf(fmtfp, "    return(%s(__res", pi->funcname);
    380445          for (i=0;i<pi->paramcnt; i++)
    381             fprintf(fmtfp, ", (%s) %s->Data()",
     446            fprintf(fmtfp, ", (%s) __%s->Data()",
    382447                    type_conv[pi->param[i].typ], pi->param[i].varname);
    383448          fprintf(fmtfp, "));\n\n");
     
    389454          fprintf(fmtfp, "  return(%s(", pi->funcname);
    390455          for (i=0;i<pi->paramcnt; i++) {
    391             fprintf(fmtfp, "(%s) %s->Data()",
     456            fprintf(fmtfp, "(%s) __%s->Data()",
    392457                    type_conv[pi->param[i].typ], pi->param[i].varname);
    393458            if(i<pi->paramcnt-1) fprintf(fmtfp, ", ");
     
    551616
    552617      case LANG_C:
     618        write_function_header(module, proc);
    553619        if(lineno>=0) {
    554620          fprintf(module->fmtfp, "#line %d \"%s\"\n",
  • modules/modgen/proc_setup.cc

    r172cdf rd76127  
    11/*
    2  * $Id: proc_setup.cc,v 1.5 2000-03-30 06:35:45 krueger Exp $
     2 * $Id: proc_setup.cc,v 1.6 2000-05-01 19:14:49 krueger Exp $
    33 */
    44
     
    6363  p->language = language;
    6464  p->lineno = lineno;
     65  p->flags.auto_header = 1;
     66 
     67  p->flags.do_declaration = 1;
     68  p->flags.declaration_done = 0;
    6569  p->flags.do_typecheck = default_do_typecheck;
     70  p->flags.typecheck_done = 0;
    6671  p->flags.do_return = default_do_return;
    67   p->flags.declaration_done = 0;
    68   p->flags.typecheck_done = 0;
    6972 
    7073  return 0;
  • modules/modgen/scanner.l

    r172cdf rd76127  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 /* $Id: scanner.l,v 1.11 2000-04-17 07:21:24 krueger Exp $ */
     5/* $Id: scanner.l,v 1.12 2000-05-01 19:14:49 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
     
    4040
    4141  extern int sectnum;
     42  static int oldsectnum = 1;
    4243  extern moddef module_def;
    43 
     44  extern procdef procedure_decl;
     45
     46  char *sectname[] = { "sect -0", "section 1",
     47                       "Singular", "procedures", "C-part"
     48  };
     49 
    4450  struct _states {
    4551    char name[32];
     
    5662  void switch_state(int state, int new_state, char *name);
    5763  void pop_state();
     64  int return_sect_token(int passed, int old_sect, int new_sect);
    5865  extern int init_modgen(moddef *module_def, char *filename);
    5966 
     
    123130%x module
    124131%x COMMENT
     132%x COMMENTB
    125133%x STRING
    126134%x SECT2
    127135%x SECT3
     136%x SECT4
    128137%x PROCDECL
    129138%x EXAMPLE
     
    142151       static int quote  = 0;  /* " */
    143152
    144 <COMMENT,STRING,INITIAL><<EOF>>   {
     153<COMMENT,COMMENTB,STRING,INITIAL><<EOF>>   {
    145154          printf( "EOF encountered inside an action\n");
    146155          printf("ERRRRROOOOORRR\n");
    147156                 }
     157
     158<INITIAL,SECT2,SECT3,SECT4>{
     159        ^"%Singular".* {
     160                  int passed = (oldsectnum == sectnum) ? 0 : 1;
     161                  int old_sect = sectnum;
     162
     163                  oldsectnum = sectnum;
     164                  sectnum = 2;
     165                  if(!passed) yyless(0);
     166                  else push_state(YYSTATE, SECT2, "SECT2");
     167                  return(return_sect_token(passed, old_sect, sectnum));
     168                }
     169        "%Singular".* {
     170                  int passed = (oldsectnum == sectnum) ? 0 : 1;
     171                  int old_sect = sectnum;
     172
     173                  oldsectnum = sectnum;
     174                  sectnum = 2;
     175                  if(!passed) yyless(0);
     176                  else push_state(YYSTATE, SECT2, "SECT2");
     177                  return(return_sect_token(passed, old_sect, sectnum));
     178                }
     179        ^"%procedures".* {
     180                  int passed = (oldsectnum == sectnum) ? 0 : 1;
     181                  int old_sect = sectnum;
     182
     183                  oldsectnum = sectnum;
     184                  sectnum = 3;
     185                  if(!passed) yyless(0);
     186                  else push_state(YYSTATE, SECT3, "SECT3");
     187                  return(return_sect_token(passed, old_sect, sectnum));
     188                }
     189        "%procedures".* {
     190                  int passed = (oldsectnum == sectnum) ? 0 : 1;
     191                  int old_sect = sectnum;
     192
     193                  oldsectnum = sectnum;
     194                  sectnum = 3;
     195                  if(!passed) yyless(0);
     196                  else push_state(YYSTATE, SECT3, "SECT3");
     197                  return(return_sect_token(passed, old_sect, sectnum));
     198                }
     199        ^"%C".* {
     200                  int passed = (oldsectnum == sectnum) ? 0 : 1;
     201                  int old_sect = sectnum;
     202
     203                  oldsectnum = sectnum;
     204                  sectnum = 4;
     205                  if(!passed) yyless(0);
     206                  else push_state(YYSTATE, SECT4, "SECT4");
     207                  return(return_sect_token(passed, old_sect, sectnum));
     208                }
     209        "%C".* {
     210                  int passed = (oldsectnum == sectnum) ? 0 : 1;
     211                  int old_sect = sectnum;
     212
     213                  oldsectnum = sectnum;
     214                  sectnum = 4;
     215                  if(!passed) yyless(0);
     216                  else push_state(YYSTATE, SECT4, "SECT4-2");
     217                  return(return_sect_token(passed, old_sect, sectnum));
     218                }
     219              }
     220
    148221
    149222<INITIAL>{
     
    174247                  push_state(YYSTATE, STRING, "string");
    175248                }
    176         ^"%%".* {
    177                   sectnum = 2;
    178 #if DEBUG
    179                   printf("Goto section %d\n", sectnum);
    180 #endif
    181                   push_state(YYSTATE, SECT2, "SECT2");
    182                   /*line_directive_out( (FILE *) 0, 1 );*/
    183                   return SECTEND;
    184                 }
     249
    185250        ^{NAME} {
    186251                  lvalp->name = strdup(yytext);
     
    192257                }
    193258           }
     259
    194260<CODEBLOCK>{
    195261            ^"%}".*{NL} {
     
    244310
    245311<SECT2>{
    246         ^"%%".* {
    247                   sectnum = 3;
    248 #if DEBUG
    249                   printf("Goto section %d\n", sectnum);
    250 #endif
    251                   switch_state(YYSTATE, SECT3, "SECT3");
    252                   /*yyterminate();*/
    253                   /*line_directive_out( (FILE *) 0, 1 );*/
    254                   return SECT2END;
    255                 }
    256312        {NL}    { yylineno++; }
    257313        {WS}    /* ignore */
     
    266322                  return PROCDECLTOK;
    267323                }
     324        example {
     325#if DEBUG > 1
     326                  printf(">>>EXAMPLE\n");
     327#endif
     328                  brace1 = 0; /* { */
     329                  brace2 = 0; /* ( */
     330                  brace3 = 0; /* [ */
     331                    push_state(YYSTATE, EXAMPLE, "EXAMPLE");
     332                        return EXAMPLETOK;
     333                }
     334            static  { return STATICTOK; }
     335        .       { printf("SG(%d) <<<'%s' ", yylineno, yytext); }
     336       }
     337
     338<SECT3>{
     339        {NL}    { yylineno++; }
     340        {WS}    /* ignore */
     341        ;       /* ignore */
     342        "/*"      push_state(YYSTATE, COMMENT, "COMMENT"); yymore();
     343        "//".*{NL}  ++yylineno; ACTION_ECHO;
    268344        example {
    269345#if DEBUG > 1
     
    300376                   }
    301377                 }
    302         .       { printf("<<<'%s' ", yytext); }
     378        .       { printf("PR(%d) <<<'%s' ", yylineno, yytext); }
    303379       }
    304380
     
    313389}
    314390
    315 <SECT3>{
     391<SECT4>{
    316392        {NL}    { yylineno++; }
    317393        .*(\n?) { lvalp->name = yytext; return CODEPART; }
     
    319395        <<EOF>>  { sectnum = 0;
    320396                   iseof=1;
    321                    return SECT3END;
     397                   return SECT4END;
    322398                   /*yyterminate();*/
    323399                 }
     
    374450       }
    375451
     452<COMMENTB>{
     453        "*/"          { ACTION_ECHO;
     454                        pop_state();
     455                        lvalp->name = yytext;
     456                        return CMTPART;
     457                        yymore();
     458                      }
     459        "*"           yymore();
     460        {NL}          { yylineno++; yymore(); }
     461        .             { yymore(); }
     462          }
     463
    376464<CODEBLOCK2>{
    377465         "/*"      push_state(YYSTATE, COMMENT, "COMMENT"); yymore();
     
    406494                 }
    407495         {NL}    { yylineno++; lvalp->name = yytext; return CODEPART; }
    408          "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK"); return '%'; }
    409          .       { yymore(); }
     496         "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK");
     497               procedure_decl.flags.start_of_code = 1;
     498               return '%'; }
     499         " " { yymore(); }
     500         .   { yymore(); procedure_decl.flags.start_of_code = 1; }
    410501
    411502       }
     
    505596}
    506597
     598int return_sect_token(
     599  int passed,
     600  int old_sect,
     601  int new_sect
     602  )
     603{
     604  if(passed) {
     605#if DEBUG
     606    printf("Go to section '%s' (%d)\n", sectname[new_sect], new_sect);
     607#endif
     608    switch(new_sect) {
     609        case 2: return SECT2START;
     610        case 3: return SECT3START;
     611        case 4: return SECT4START;
     612        default: return SECTEND;
     613    }
     614  } else {
     615#if DEBUG
     616    printf("End of section '%s' (%d)\n", sectname[old_sect], old_sect);
     617#endif
     618    switch(old_sect) {
     619        case 2: return SECT2END;
     620        case 3: return SECT3END;
     621        case 4: return SECT4END;
     622        default: return SECTEND;
     623    }
     624  }
     625}
     626
    507627void add_action(char *new_text)
    508628{
     
    518638      printf("3>%s<#\n", new_text);
    519639      break;
     640    case 4:
     641      printf("4>%s<#\n", new_text);
     642      break;
    520643  }
    521644}
  • modules/modgen/utils.cc

    r172cdf rd76127  
    11/*
    2  * $Id: utils.cc,v 1.8 2000-03-30 06:35:46 krueger Exp $
     2 * $Id: utils.cc,v 1.9 2000-05-01 19:14:49 krueger Exp $
    33 */
    44
     
    123123  vprintf(fmt, ap);
    124124  va_end(ap);
    125   return 1;
     125  return 2;
    126126}
Note: See TracChangeset for help on using the changeset viewer.