home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume2 / basic / part4 / bs2 / mkop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.2 KB  |  45 lines

  1. /* mkop.c -- make operator function for bs.
  2.  *
  3.  *    USAGE: op name type oper tag
  4.  *
  5.  * where:    name: name of function generated.
  6.  *        type: data type of operation.
  7.  *        oper: operator for operation.
  8.  *        tag: structure tag name.
  9.  *
  10.  * This will only work with T_INT and T_DBL operators, T_CHR operations
  11.  * do not boil down to a simple operation.
  12.  */
  13. #include <stdio.h>
  14.  
  15. main(argc,argv)
  16. char **argv;
  17. int argc;
  18. {
  19.     char *name,*type,*oper,*tag;
  20.  
  21.     if(argc != 5) {
  22.     fprintf(stderr,"arg count\n");
  23.     exit(1);
  24.     }
  25.     name = argv[1]; type = argv[2]; oper = argv[3]; tag = argv[4];
  26.  
  27.     printf("_%s(l,p)\n",name);
  28.     printf("int (*l[])(),p;\n");
  29.     printf("{\n");
  30.     printf("    union value rg1,rg2,result;\n");
  31.     printf("\n");
  32.     printf("    switch(status&XMODE) {\n");
  33.     printf("    case M_READ: dtype = T_%s;\n",type);
  34.     printf("    case M_EXECUTE:\n");
  35.     printf("        rg2 = pop();\n");
  36.     printf("        rg1 = pop();\n");
  37.     printf("        result.%s = rg1.%s %s rg2.%s;\n",tag,tag,oper,tag);
  38.     printf("        push(result);\n");
  39.     printf("    case M_FIXUP:\n");
  40.     printf("    case M_COMPILE: return(p);\n");
  41.     printf("    default: STerror(\"%s\");\n",name);
  42.     printf("    }\n");
  43.     printf("}\n");
  44. }
  45.