Ejemplo n.º 1
0
void exec(Pystat stat){
    Arg arg0 = stat->args[0];
    Arg arg1 = stat->args[1];
    switch(stat->op){
        case Y_PUSH: {
            exec_push(arg0.ival, pc+1); // num_objects
            break;
        }
        case Y_GOTO: {
            exec_goto(arg0.ival); // absolute line
            break;
        }
        case Y_POP: {
            exec_pop();
            break;
        }
        case Y_NEW: {
            exec_new(arg0.ival); // obj size
            break;
        }
        case Y_NEWS: {
            exec_news(arg0.ival); // obj size
            break;
        }
        case Y_LDC: {
            exec_ldc(arg0.ival);
            break;
        }
        case Y_LDI: {
            exec_ldi(arg0.ival);
            break;
        }
        case Y_LDR: {
            exec_ldr(arg0.rval);
            break;
        }
        case Y_LDS: {
            exec_lds(arg0.sval);
            break;
        }
        case Y_LOD: {
            exec_lod(arg0.ival); // oid
            break;
        }
        case Y_GLOD: {
            exec_glod(arg0.ival); // oid
            break;
        }
        case Y_CAT: {
            exec_cat(arg0.ival, arg1.ival); // num fields, record/array size
            break;
        }
        case Y_LDA: {
            exec_lda(arg0.ival); // oid
            break;
        }
        case Y_GLDA: {
            exec_glda(arg0.ival); // oid
            break;
        }
        case Y_FDA: {
            exec_fda(arg0.ival); // field offset
            break;
        }
        case Y_EIL: {
            exec_eil(arg0.ival); // field size, embedded
            break;
        }
        case Y_SIL: {
            exec_sil(arg0.ival); // field size, on stack
            break;
        }
        case Y_IXA: {
            exec_ixa(arg0.ival); // elem size
            break;
        }
        case Y_STO: {
            exec_sto(arg0.ival); // oid
            break;
        }
        case Y_GSTO: {
            exec_gsto(arg0.ival); // oid
            break;
        }
        case Y_IST: {
            exec_ist(); // indirect store
            break;
        }
        case Y_JMF: {
            exec_jmf(arg0.ival); // offset
            break;
        }
        case Y_JMP: {
            exec_jmp(arg0.ival); // offset
            break;
        }
        case Y_EQU: {
            exec_equ(); // for all types of objects
            break;
        }
        case Y_NEQ: {
            exec_neq(); // for all types of objects
            break;
        }
        case Y_IGT: {
            exec_igt();
            break;
        }
        case Y_IGE: {
            exec_ige();
            break;
        }
        case Y_ILT: {
            exec_ilt();
            break;
        }
        case Y_ILE: {
            exec_ile();
            break;
        }
        case Y_RGT: {
            exec_rgt();
            break;
        }
        case Y_RGE: {
            exec_rge();
            break;
        }
        case Y_RLT: {
            exec_rlt();
            break;
        }
        case Y_RLE: {
            exec_rle();
            break;
        }
        case Y_SGT: {
            exec_sgt();
            break;
        }
        case Y_SGE: {
            exec_sge();
            break;
        }
        case Y_SLT: {
            exec_slt();
            break;
        }
        case Y_SLE: {
            exec_sle();
            break;
        }
        case Y_IPLUS: {
            exec_iplus();
            break;
        }
        case Y_IMINUS: {
            exec_iminus();
            break;
        }
        case Y_ITIMES: {
            exec_itimes();
            break;
        }
        case Y_IDIV: {
            exec_idiv();
            break;
        }
        case Y_RPLUS: {
            exec_rplus();
            break;
        }
        case Y_RMINUS: {
            exec_rminus();
            break;
        }
        case Y_RTIMES: {
            exec_rtimes();
            break;
        }
        case Y_RDIV: {
            exec_rdiv();
            break;
        }
        case Y_IUMI: {
            exec_iumi();
            break;
        }
        case Y_RUMI: {
            exec_rumi();
            break;
        }
        case Y_NEG: {
            exec_neg();
            break;
        }
        case Y_WR: {
            exec_wr(arg0.sval, 1, stdout); // schema
            break;
        }
        case Y_FWR: {
            exec_fwr(arg0.sval); // schema
            break;
        }
        case Y_RD: {
            exec_rd(arg0.sval, 1, stdin); // schema
            break;
        }
        case Y_FRD: {
            exec_frd(arg0.sval); // schema
            break;
        }
        case Y_TOINT: {
            exec_toint();
            break;
        }
        case Y_TOINTUP: {
            exec_tointup();
            break;
        }
        case Y_TOREAL: {
            exec_toreal();
            break;
        }
        case Y_READ: {
            exec_read(arg0.ival, arg1.sval, 1, stdin); // oid, schema
            break;
        }
        case Y_GREAD: {
            exec_gread(arg0.ival, arg1.sval, 1, stdin); // oid, schema
            break;
        }
        case Y_FREAD: {
            exec_fread(arg0.ival, arg1.sval); // oid, schema
            break;
        }
        case Y_GFREAD: {
            exec_gfread(arg0.ival, arg1.sval); // oid, schema
            break;
        }
        case Y_WRITE: {
            exec_write(arg0.sval); // schema
            break;
        }
        case Y_FWRITE: {
            exec_fwrite(arg0.sval); // schema
            break;
        }
        case Y_TDUP: {
            exec_tdup();
            break;
        }
        case Y_TPOP: {
            exec_tpop(arg0.ival); // num objects
            break;
        }
        case Y_MODULE: {
            // nothing to do here, the instruction is useless
            break;
        }
        case Y_RETURN: {
            exec_return();
            break;
        }
        default: {
            machine_error("Unknown instruction.");
            break;
        }
    }
}
Ejemplo n.º 2
0
int run_program(char* p_buf){
  int i;

  //  I REMOVED THIS AND PUT IT IN FRONT OF THE CALL...
  //NMS-REMOVAL  init_namespace();// Do you need it? May be you want to use the same namespace

  prog = p_buf;
  scan_labels(); /* find the labels in the program */
  ftos = 0; /* initialize the FOR stack index */
  gtos = 0; /* initialize the GOSUB stack index */
  do {
    bas_token_type = get_token();
    // printf("ttype=%d bas_tok=%d <%s>\n", bas_token_type, bas_tok, bas_token);
    /* check for assignment statement */
    if(bas_token_type==VARIABLE) {
      putback(); /* return the var to the input stream */
      assignment(); /* must be assignment statement */
    }
    else /* is command */
      switch(bas_tok) {
        case PRINT:
	  print();
  	  break;
        case GOTO:
	  exec_goto();
	  break;
	case IF:
	  exec_if();
	  break;
	case FOR:
	  exec_for();
	  break;
	case NEXT:
	  next();
	  break;
  	case INPUT:
	  input();
	  break;
        case GOSUB:
	  gosub();
	  break;
	case RETURN:
	  greturn();
	  break;
	case COMMENT:
	  do{
	  get_token();
	  if(bas_tok==EOL || bas_tok==FINISHED) break; 
	  } while (1==1);
	  break;
	case CONTINUE:
	  do{
	  get_token();
	  if(bas_tok==EOL || bas_tok==FINISHED) break; 
	  } while (1==1);
	  break;
        case END:
	  printf("variables----------------------------%s\n","");
	  for (i=0;i<varnamelast;i++){
	    printf("%14s - %19.7f\n", varname[i] , variables[i] );
	  }
	  exit(0);
      }
  } while (bas_tok != FINISHED);
  return 0;
}// run_program