Changeset cffe626 in git for modules/modgen
- Timestamp:
- Jan 27, 2000, 1:40:55 PM (24 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
- Children:
- 1bf317c89085ef09163635ecfe77c4da1ebc1045
- Parents:
- dd10b142c1fd713fe44c4cac2ad1ef9c53b47868
- Location:
- modules/modgen
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/modgen/creat_top.cc
rdd10b1 rcffe626 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: creat_top.cc,v 1. 3 2000-01-17 08:32:25krueger Exp $ */4 /* $Id: creat_top.cc,v 1.4 2000-01-27 12:39:59 krueger Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 32 32 void write_enter_id(FILE *fp) 33 33 { 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"); 37 39 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"); 40 47 } 41 48 … … 48 55 fprintf(fp, "extern \"C\"\n"); 49 56 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"); 51 60 } 52 61 -
modules/modgen/grammar.y
rdd10b1 rcffe626 1 1 /* 2 * $Id: grammar.y,v 1. 4 2000-01-21 09:23:20krueger Exp $2 * $Id: grammar.y,v 1.5 2000-01-27 12:40:54 krueger Exp $ 3 3 */ 4 4 … … 11 11 #include <string.h> 12 12 #include <limits.h> 13 14 #include <mod2.h> 15 #include <tok.h> 13 16 14 17 #include "modgen.h" … … 52 55 /*%token PROCEND*/ 53 56 %token PROCDECLTOK 57 %token EXAMPLETOK 54 58 55 59 /* BISON Declarations */ … … 95 99 } 96 100 97 line:98 expr ';'99 {100 printf("EXPRESSION\n");101 }102 | procdecl103 ;104 105 101 sect1: expr ';' 106 102 | sect1 expr ';' … … 110 106 sect1end: SECTEND 111 107 { 108 memset(&procedure_decl, 0, sizeof(procdef)); 112 109 printf("End of section %d\n", sectnum-1); 113 110 } … … 116 113 expr: NAME '=' MSTRINGTOK 117 114 { 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); 123 123 } 124 124 else { … … 128 128 break; 129 129 case 2: /* pass 2: procedure declaration */ 130 if( (vt=checkvar($1, VAR_STRING )) ) {130 if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) { 131 131 proc_set_var(&procedure_decl, VAR_STRING, vt, $1, $3); 132 132 } … … 142 142 | NAME '=' FILENAME 143 143 { 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)) ) { 149 151 proc_set_var(&procedure_decl, VAR_FILE, vt, $1, $3); 150 152 } … … 156 158 | NAME '=' files 157 159 { 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)) ) { 163 167 proc_set_var(&procedure_decl, VAR_FILES, vt, $1, &$3); 164 168 } … … 170 174 | NAME '=' NUMTOK 171 175 { 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)) ) { 177 183 proc_set_var(&procedure_decl, VAR_NUM, vt, $1, &$3); 178 184 } … … 184 190 | NAME '=' BOOLTOK 185 191 { 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)) ) { 189 197 proc_set_default_var(VAR_BOOL, vt, $1, &$3); 190 198 } … … 195 203 break; 196 204 case 2: /* pass 2: procedure declaration */ 197 if( (vt=checkvar($1, VAR_BOOL )) ) {205 if( (vt=checkvar($1, VAR_BOOL, &write_cmd)) ) { 198 206 proc_set_var(&procedure_decl, VAR_BOOL, vt, $1, &$3); 199 207 } … … 227 235 228 236 procdef: 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 246 procdecl: procdecl2 '{' 236 247 { 237 248 setup_proc(&module_def, &procedure_decl); 238 249 } 239 | procdecl 3procdeclhelp '{'250 | procdecl2 procdeclhelp '{' 240 251 { 241 252 setup_proc(&module_def, &procedure_decl); … … 257 268 ; 258 269 259 procdecl3: procdecl2260 | procdecl2 procdeclflags261 ;262 263 270 procdeclhelp: MSTRINGTOK 264 271 { 265 272 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");276 273 } 277 274 ; … … 279 276 proccode: proccodeline MCODETOK 280 277 { 281 generate_function(&procedure_decl, module_def.fmtfp);278 write_function_errorhandling(&procedure_decl, module_def.fmtfp); 282 279 }; 283 280 … … 297 294 }; 298 295 299 proccmd: '%' PROCCMD ';' 296 procdeclexample: 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 308 examplecodeline: 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 325 proccmd: '%' NAME ';' 300 326 { cmd_token vt; 301 void (*write_cmd)(moddefv module, procdefv pi );327 void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL); 302 328 303 if( (vt=checkcmd($2, &write_cmd )) ) {329 if( (vt=checkcmd($2, &write_cmd, 0)) ) { 304 330 write_cmd(&module_def, &procedure_decl); 305 331 } 306 332 else { 307 333 myyyerror("Line %d: Unknown command '%s' in section %d\n", 308 yylineno, $ 1, sectnum);334 yylineno, $2, sectnum); 309 335 } 310 336 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); 311 365 }; 312 366 -
modules/modgen/main.cc
rdd10b1 rcffe626 13 13 #include "stype.h" 14 14 15 int trace=1; 15 16 /* 16 17 * Syntax of a module file: … … 89 90 //fflush(module_def.fmtfp); 90 91 //PrintProclist(&module_def); 91 //generate_mod(&module_def, 2);92 92 //mod_create_makefile(&module_def); 93 93 if(module_def.fmtfp != NULL) fclose(module_def.fmtfp); -
modules/modgen/misc.cc
rdd10b1 rcffe626 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: misc.cc,v 1. 4 2000-01-21 09:23:21krueger Exp $ */4 /* $Id: misc.cc,v 1.5 2000-01-27 12:39:59 krueger Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 53 53 #define SELF_CMD MAX_TOK+1 54 54 55 void enter_id(FILE *fp, char *name, char *value); 55 extern void enter_id(FILE *fp, idtyp t, char *name, char *value, 56 int lineno, char *file); 57 extern void write_enter_id(FILE *fp); 58 56 59 static void mod_write_ctext(FILE *fp, FILE *fp_in); 57 60 char type_conv[MAX_TOK][32]; … … 199 202 { 200 203 char *name; 201 void (*write_cmd)(moddefv module, procdefv pi );204 void (*write_cmd)(moddefv module, procdefv pi, void *arg = NULL); 202 205 cmd_token id; 206 int args; 203 207 } 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 } 208 212 }; 209 213 210 214 cmd_token checkcmd( 211 215 char *cmdname, 212 void (**write_cmd)(moddefv module, procdefv pi) 216 void (**write_cmd)(moddefv module, procdefv pi, void *arg), 217 int args 213 218 ) 214 219 { … … 226 231 var_type type; 227 232 var_token id; 233 void (*write_cmd)(moddefv module, var_token type = VAR_NONE, 234 idtyp t, void *arg1 = NULL, void *arg2 = NULL); 228 235 } 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 233 241 { "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 } 237 244 }; 238 245 239 246 var_token checkvar( 240 247 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) 242 251 ) 243 252 { … … 245 254 for(i=0; valid_vars[i].name!=NULL; i++) 246 255 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 } 248 260 return VAR_NONE; 261 } 262 263 void 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); 249 273 } 250 274 … … 325 349 326 350 /*========================================================================*/ 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 351 void init_system_type() 352 { 403 353 if(strcmp(S_UNAME, "ix86-Linux") == 0) { 404 354 systyp = SYSTYP_LINUX; … … 408 358 systyp = SYSTYP_HPUX10; 409 359 } 410 init_type_conv(); 411 printf("SYSTYP:%d\n", systyp); 360 } 361 362 /*========================================================================*/ 363 void 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 /*========================================================================*/ 375 void 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; 412 385 413 386 switch(section) { … … 440 413 /* building entry-functions */ 441 414 for(proccnt=0; proccnt<module->proccnt; proccnt++) { 442 generate_function(&module->procs[proccnt], module->modfp);415 //generate_function(&module->procs[proccnt], module->modfp); 443 416 //generate_header(&module->procs[proccnt], fp_h); 444 417 } … … 467 440 #if 0 468 441 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 }501 442 } 502 443 else { … … 525 466 void mod_write_header(FILE *fp, char *module, char what) 526 467 { 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 544 469 write_header(fp, module); 545 470 fprintf(fp, "#include <stdlib.h>\n"); … … 550 475 fprintf(fp, "\n"); 551 476 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 } 553 482 fprintf(fp, "\n"); 554 555 fprintf(fp, "void enter_id(char *name, char *value);\n");556 fprintf(fp, "\n");557 #endif558 483 } 559 484 … … 572 497 573 498 /*========================================================================*/ 574 void enter_id(FILE *fp, char *name, char *value, int lineno, char *file) 575 { 499 void 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 576 510 if(lineno) 577 511 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)); 579 514 } 580 515 -
modules/modgen/modgen.h
rdd10b1 rcffe626 1 1 /* 2 * $Id: modgen.h,v 1. 4 2000-01-21 09:23:21krueger Exp $2 * $Id: modgen.h,v 1.5 2000-01-27 12:40:00 krueger Exp $ 3 3 * 4 4 */ … … 13 13 14 14 #include <stdio.h> 15 #include <string.h> 16 #include <mod2.h> 17 #include <subexpr.h> 15 18 16 19 class paramdef; … … 54 57 char *c_code; 55 58 char *help_string; 59 long example_len; 60 char *example_string; 56 61 }; 57 62 … … 95 100 * 96 101 */ 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);100 102 101 103 … … 107 109 108 110 extern void PrintProclist(moddefv module); 109 extern void Add2proclist(moddefv module, char *name, char *ret_val,110 char *ret_typname, int ret_typ);111 111 extern void generate_mod(moddefv module, int section); 112 112 extern void mod_create_makefile(moddefv module); 113 113 extern void Add2files(moddefv module, char *buff); 114 114 115 extern void generate_function(procdefv pi, FILE *fp);116 115 extern void mod_copy_tmp(FILE *fp_out, FILE *fp_in); 117 116 extern void mod_write_header(FILE *fp, char *module, char what); … … 133 132 extern int create_tmpfile(moddefv module_def); 134 133 134 /* from proc.cc */ 135 extern void write_example(moddefv module, procdefv proc); 136 135 137 extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp); 136 138 extern 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); 139 extern void write_function_declaration(moddefv module, procdefv pi, void *arg = NULL); 140 extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL); 141 extern void write_function_return(moddefv module, procdefv pi, void *arg = NULL); 142 extern void write_function_errorhandling(procdefv pi, FILE *fp); 143 144 /* from misc.cc */ 145 extern cmd_token checkcmd( 146 char *cmdname, 147 void(**write_cmd)(moddefv module, procdefv pi, void *arg), 148 int args); 149 extern 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)); 153 void write_main_variable(moddefv module, var_token type, 154 idtyp t, void *arg1, void *arg2); 140 155 141 156 #endif /* _MODGEN_H */ -
modules/modgen/proc.cc
rdd10b1 rcffe626 1 1 /* 2 * $Id: proc.cc,v 1. 4 2000-01-21 13:38:52krueger Exp $2 * $Id: proc.cc,v 1.5 2000-01-27 12:40:03 krueger Exp $ 3 3 */ 4 4 … … 12 12 #include "typmap.h" 13 13 14 extern int trace; 14 15 15 16 #if 1 … … 21 22 22 23 extern void PrintProc(procdefv pi); 23 void write_function(moddefv module, procdefv proc); 24 //void write_function(moddefv module, procdefv proc); 25 static void write_function_declaration(procdefv pi, FILE *fp); 24 26 static void write_procedure_header(moddefv module, procdefv pi, FILE *fmtfp); 25 27 static void gen_func_param_check(FILE *fp, procdefv pi, int i); … … 31 33 void setup_proc( 32 34 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 /*========================================================================*/ 71 void 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 } 44 87 /*========================================================================*/ 45 88 /* … … 53 96 int i; 54 97 55 fprintf(fp, "BOOLEAN mod_%s(leftv res, leftv h);\n", pi->funcname); 98 #if 0 56 99 switch( pi->return_val.typ) { 57 100 case SELF_CMD: … … 68 111 } 69 112 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 /*========================================================================*/ 101 117 void write_function_declaration( 102 118 moddefv module, 103 procdefv pi 119 procdefv pi, 120 void *arg 104 121 ) 105 122 { … … 120 137 void write_function_typecheck( 121 138 moddefv module, 122 procdefv pi 139 procdefv pi, 140 void *arg 123 141 ) 124 142 { … … 129 147 void write_function_return( 130 148 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 134 178 write_procedure_return(module, pi, module->fmtfp); 135 179 } … … 159 203 160 204 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); 162 206 } 163 207 … … 191 235 192 236 fprintf(fmtfp, " if(v!=NULL) { tok = v->Typ(); goto mod_%s_error; }\n", 193 pi-> funcname);237 pi->procname); 194 238 195 239 fprintf(fmtfp, "\n"); … … 220 264 ) 221 265 { 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); 223 267 fprintf(fp, " tok = v->Typ();\n"); 224 268 fprintf(fp, " if((index=iiTestConvert(tok, %s))==0)\n", 225 269 pi->param[i].typname); 226 fprintf(fp, " goto mod_%s_error;\n", pi-> funcname);270 fprintf(fp, " goto mod_%s_error;\n", pi->procname); 227 271 fprintf(fp, " v_save = v->next;\n"); 228 272 fprintf(fp, " v->next = NULL;\n"); 229 273 fprintf(fp, " if(iiConvert(tok, %s, index, v, res%d))\n", 230 274 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); 232 276 fprintf(fp, " v = v_save;\n"); 233 277 } … … 250 294 int i; 251 295 252 /* if(pi->flags.do_return) {*/ 253 printf("\nWriting return-block\n"); 296 printf("\nWriting return-block\n"); 254 297 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 255 306 switch( pi->return_val.typ) { 256 307 case SELF_CMD: … … 264 315 case NONE: 265 316 fprintf(fmtfp, " res->rtyp = %s;\n", pi->return_val.typname); 317 fprintf(fmtfp, " res->data = NULL;\n"); 266 318 fprintf(fmtfp, " return(%s(", pi->funcname); 267 319 for (i=0;i<pi->paramcnt; i++) { … … 281 333 if(i<pi->paramcnt-1) fprintf(fmtfp, ", "); 282 334 } 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 } 286 339 } 287 340 … … 297 350 #endif 298 351 299 void generate_function(procdefv pi, FILE *fp)352 void write_function_errorhandling(procdefv pi, FILE *fp) 300 353 { 301 354 int cnt = 0, i; … … 303 356 if(pi->flags.typecheck_done) { 304 357 printf("error handling..."); fflush(stdout); 305 fprintf(fp, " mod_%s_error:\n", pi-> funcname);358 fprintf(fp, " mod_%s_error:\n", pi->procname); 306 359 fprintf(fp, " Werror(\"%s(`%%s`) is not supported\", Tok2Cmdname(tok));\n", 307 360 pi->procname); -
modules/modgen/proc_setup.cc
rdd10b1 rcffe626 1 1 /* 2 * $Id: proc_setup.cc,v 1. 2 2000-01-21 09:23:22krueger Exp $2 * $Id: proc_setup.cc,v 1.3 2000-01-27 12:40:54 krueger Exp $ 3 3 */ 4 4 … … 38 38 if( p->funcname != NULL ) free(p->funcname); 39 39 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); 40 42 if( p->paramcnt>0 ) { 41 43 //free(p->param); … … 44 46 memset((void *)p, 0, sizeof(procdef)); 45 47 p->procname = strdup(procname); 48 46 49 if( ret != NULL ) { 47 50 char typname[32]; … … 50 53 ret->typname = strdup(typname); 51 54 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 53 61 p->lineno = lineno; 54 p->return_val.typ = NONE;55 62 p->flags.do_typecheck = default_do_typecheck; 56 63 p->flags.do_return = default_do_return; … … 177 184 q = (char *)varvalue; 178 185 switch(varid) { 179 case VAR_FUNCTION:180 if(p->funcname != NULL) free(p->funcname);181 p->funcname = strdup(q);182 break;183 186 case VAR_HELP: 184 187 break; -
modules/modgen/scanner.l
rdd10b1 rcffe626 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 /* $Id: scanner.l,v 1. 4 2000-01-21 09:23:22krueger Exp $ */5 /* $Id: scanner.l,v 1.5 2000-01-27 12:40:55 krueger Exp $ */ 6 6 #include <stdio.h> 7 7 #include <string.h> … … 13 13 #include "grammar.h" 14 14 15 /*#define DEBUG 3*/ 15 #define DEBUG 3 16 16 17 17 # define YYLP_ERR_NONE 0 … … 105 105 WS [[:blank:]]+ 106 106 NL \r?\n 107 WSNL ([ \t\n\r]+) 107 108 EQ (([{WS}]+=[{WS}]+)|=) 108 109 … … 258 259 return PROCDECLTOK; 259 260 } 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 } 260 269 . { printf("<<<'%s' ", yytext); } 261 270 … … 328 337 329 338 pop_state(); 339 #if 0 330 340 s = t = lvalp->name = dupyytext(); 331 341 while (*yytext) … … 335 345 } 336 346 if(s-t>2 && *(s-1)=='}' && *(s-2)=='%') *(s-2)='\0'; 347 #else 348 lvalp->name = yytext; 349 #endif 337 350 #if DEBUG > 1 338 351 printf("2 BRACE DOWN=%d\n", brace1); … … 352 365 <PROCCMDBLOCK>{ 353 366 {col} { pop_state(); return ';'; } 367 "(" { return '('; } 368 ")" { return ')'; } 354 369 {WS} /* ignore */ 355 {NAME} { lvalp->name = strdup(yytext); return PROCCMD; }370 {NAME} { lvalp->name = strdup(yytext); return NAME; } 356 371 . { printf("PCB: '%s'\n", yytext); } 357 372 } -
modules/modgen/utils.cc
rdd10b1 rcffe626 1 1 /* 2 * $Id: utils.cc,v 1. 3 2000-01-21 09:23:22krueger Exp $2 * $Id: utils.cc,v 1.4 2000-01-27 12:40:53 krueger Exp $ 3 3 */ 4 4 … … 9 9 #include <ctype.h> 10 10 #include "modgen.h" 11 12 void init_system_type(); 11 13 12 14 /*========================================================================*/ … … 36 38 memset(module_def->name, '\0', strlen(tmpfile)+1); 37 39 memcpy(module_def->name, tmpfile, strlen(tmpfile)); 40 41 init_system_type(); 38 42 39 43 return (create_tmpfile(module_def));
Note: See TracChangeset
for help on using the changeset viewer.