Ejemplo n.º 1
0
void bcd(int n)
{
	int mm;
	int num=0;
	int array[100];
	while(n>0)
	{
		array[num]=mod_u10(n);
		n=div_u10(n);
		num++;
	}
	while(num>0)
	{
		switch(array[num-1])
		{
			case 0: mputs("0000"); break;
			case 1: mputs("0001"); break;
			case 2: mputs("0010"); break;
			case 3: mputs("0011"); break;
			case 4: mputs("0100"); break;
			case 5: mputs("0101"); break;
			case 6: mputs("0110"); break;
			case 7: mputs("0111"); break;
			case 8: mputs("1000"); break;
			case 9: mputs("1001"); break;
		}
		mputc(' ');
		num--;
	}
}
Ejemplo n.º 2
0
void dumpstack(int i, int *sp){
	mputs("STACK[");
	for(int j = 0; j < i; j++){
		mputs(" ");
		mputs(itoa(disk[*sp+j]));
	}
	puts(" ]");
}
Ejemplo n.º 3
0
void stat(){
	mputs("Dict = ");
	puts(itoa(*dict));
	mputs("rstack = ");
	puts(itoa(*rsp - (DSIZE-(RSSIZE+STSIZE+1))));
	mputs("dstack = ");
	puts(itoa(DSIZE-*tosp-1));
}
Ejemplo n.º 4
0
void intern(int x, int imm) {
	enter(*link);
	*link = *dict-1;
	w = *dict;
	enter(0);
	int slen = scant((char) 127, (char *)(disk+(*dict)));
	int ilen = slen/PACK + (slen%PACK) ? 1 : 0;
	disk[w] = slen;
	*dict += slen/PACK + 1;
	enter(imm);
	enter(x);
	mputs("interning ");
	putnumstr(disk+w);
	mputs(" @ ");
	puts(itoa(*dict-1));
}
Ejemplo n.º 5
0
void printState() {  
  parameters[P_COOLING_PWM]         = getCurrentCoolingSpeed();
  parameters[P_CIRCULATION_PWM]     = getCurrentCirculationSpeed();

  for (int i=0;i<P_COUNT;i++) {
    mprintf(PSTR("p%d\t%d\t%p\n"), i, parameters[i], getParameterNamePGM(i));
  }
  mputs(NL);
}
Ejemplo n.º 6
0
void counter(int t, char *s)
{
	int i;
	while(1)
	{
		i=t;
		while(i--);
		mputs(s);
	}
}
Ejemplo n.º 7
0
void second_task()
{
	uint len;
	uint buff[100];
	mputs("THIS IS SECOND_TASK\n");
	mkfifo("/proc/0");
	uint fd = open("/proc/0");
	while(1)
	{
		read(fd,&len,1);
		read(fd,buff,len);
		mputu(buff);
	}
}
Ejemplo n.º 8
0
void init_task()
{
	mputs("THIS IS INIT_TASK\n");
	if( !fork() ) pathserver();
	if( !fork() ) second_task();
	uint fd = open("/proc/0");
	uint buff[100];
	uint len;
	while(1)
	{
		len=setbuff(buff+1,"this is message\n");
		buff[0]=len;
		write(fd,buff,1+len);
	}
}
Ejemplo n.º 9
0
void mr_track(_MIPDO_ )
{ /* track course of program execution *
   * through the MIRACL routines       */

#ifndef MR_NO_STANDARD_IO

    int i;
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    for (i=0;i<mr_mip->depth;i++) fputc('-',stdout);
    fputc('>',stdout);
    mputs(names[mr_mip->trace[mr_mip->depth]]);
    fputc('\n',stdout);
#endif
}
Ejemplo n.º 10
0
void pathserver()
{
	mputs("THIS IS PATHSERVER\n");

	uint paths[PIPE_NUM_LIMIT-TASK_NUM_LIMIT-PATH_NUM_RESERVED][PATH_NAME_MAX];
	uint num=0;
	uint buff[PATH_NAME_MAX];

	uint n = setbuff(buff,"/sys/pathserver");
	imemcpy(paths[num++],buff,n);

	uint i;
	uint fd;
	uint len;

	while(1)
	{
		read(PATHSERVER_FD,&fd,1);
		read(PATHSERVER_FD,&len,1);
		read(PATHSERVER_FD,buff,len);

		if(fd==MKFIFO_FD)
		{
			imemcpy(paths[num++],buff,len);
		}
		else
		{
			for(i=0;i<num;i++)
			{
				if( *paths[i] && istrcmp(buff,paths[i])==0 )
				{
					i = i + PATH_NUM_RESERVED +TASK_NUM_LIMIT;
					write(fd,&i,1);
					i=0;
					break;
				}
				if(i>=num)
				{
					i=-1;
					write(fd,&i,1);
				}
			}
		}
	}
}
Ejemplo n.º 11
0
void pollInput() {
  
  if (mchready()) {
    char ch = mgetch();

    if (ch == '\r') {
      mputs(NL);

      *inputBufferEnd = 0;
      handleInputLine();
      resetInputBuffer();

    } else {
      *inputBufferEnd = ch;
      inputBufferEnd++;
      mputchar(ch);

      if (inputBufferEnd == inputBuffer + INPUT_BUFFER_SIZE -1) {	
	mprintf(PSTR("ERROR: linebuffer overflow\n"));
	resetInputBuffer();
      }      
    }  
  }
}
Ejemplo n.º 12
0
/**********************************************************************
 *  Function  z_alg_menu();
 *                                                                    
 *  Parameter:                                                       
 *   
 *                                                              
 *  This function prompts user to create and utilize the Z values 
 *  for a string.  The utilities menu is also available from this menu.
 *                                                                   
 **********************************************************************/
void z_alg_menu()
{
  int status, num_lines;
  char ch;
  STRING *text, *pattern;

  while (1) {
    num_lines = 12;
    printf("\n**   Z-value Algorithm Menu    **\n\n");
    printf("1)  Build Z values for a sequence\n");
    printf("2)  Exact matching using Z values\n");
    printf("3)  Knuth-Morris-Pratt  (Z-values preprocessing)\n");
    printf("     a) using sp values\n");
    printf("     b) using sp' values\n");
    printf("*)  String Utilites\n");
    printf("0)  Exit\n");
    printf("\nEnter Selection: ");
  
    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;
    switch (choice[0]) {
    case '0':
      return;

    case '1':
      if (!(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mputs("The string:\n");
      terse_print_string(text);

      status = map_sequences(text, NULL, NULL, 0);
      if (status != -1) {
        mputs("Building Z values...\n\n");
        strmat_z_build(text, stats_flag);
        unmap_sequences(text, NULL, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '2':
      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mputs("\nThe pattern:\n");
      terse_print_string(pattern);
      mputs("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');

      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        mputs("Executing exact matching with Z values algorithm...\n\n");
        strmat_z_match(pattern, text, stats_flag);
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '3':
      ch = choice[1];
      if (toupper(ch) != 'A' && toupper(ch) != 'B') {
        printf("\nYou must specify the KMP variation (as in '3a' or '3b').\n");
        continue;
      }

      if (!(pattern = get_string("pattern")) || !(text = get_string("text")))
        continue;

      mstart(stdin, fpout, OK, OK, 5, NULL);
      mprintf("\nThe pattern:\n");
      terse_print_string(pattern);
      mprintf("\nThe text:\n");
      terse_print_string(text);
      mputc('\n');
        
      status = map_sequences(text, pattern, NULL, 0);
      if (status != -1) {
        if (toupper(ch) == 'A') {
          mprintf ("Executing KMP with sp values...\n\n");
          strmat_kmp_sp_z_match(pattern, text, stats_flag);
        }
        else {
          mprintf ("Executing KMP with sp' values...\n\n");
          strmat_kmp_spprime_z_match(pattern, text, stats_flag);
        }
        unmap_sequences(text, pattern, NULL, 0);
      }
      mend(num_lines);
      putchar('\n');
      break;

    case '*':
      util_menu();
      break;

    default:
      printf("\nThat is not a choice.\n");
    }
  }
}
Ejemplo n.º 13
0
int print_matches(const STRING *string, const STRING **strings, int num_strings, MATCHES list, int num_matches)
{
    int i, j, N, count, matchdigs, minwidth, maxwidth;
    int width, maxposdigs, maxiddigs, multistring_mode;
    CHAR_TYPE *T;
    char format[32];
    MATCHES ptr;

    if (num_matches == 0) {
        mputs("Found 0 matches:\n");
        return 1;
    }

    multistring_mode = (list->type == TEXT_SET_EXACT);
    if ((!multistring_mode && string == NULL) 
        || (multistring_mode && strings == NULL))
    return 0;

  /*
   * Compute the number of digits in the number of matches and the
   * widest position (and possibly widest identifier) of any match.  Also,
   * find the smallest and largest match length.
   */
  matchdigs = my_itoalen(num_matches);

  maxposdigs = maxiddigs = 0;
  minwidth = maxwidth = -1;
  for (count=0,ptr=list; count < num_matches; count++,ptr=ptr->next) {
    if (minwidth == -1 || ptr->rend - ptr->lend + 1 < minwidth)
      minwidth = ptr->rend - ptr->lend + 1;
    if (maxwidth == -1 || ptr->rend - ptr->lend + 1 > maxwidth)
      maxwidth = ptr->rend - ptr->lend + 1;

    width = my_itoalen(ptr->rend);
    if (width > maxposdigs)
      maxposdigs = width;

    if (multistring_mode && num_strings > 1) {
      width = my_itoalen(ptr->textid);
      if (width > maxiddigs)
        maxiddigs = width;
    }
  }

  /* 
   * Print the header line with signal characters showing where
   * the matches are.
   */
  printf("Found %d matches:", num_matches);
  width = (17 + 2 * maxposdigs + maxiddigs) - (15 + matchdigs);
  for (i=0; i < width; i++)
    mputc(' ');
  for (i=0; i < minwidth && i < 43; i++)
    mputc('_');
  for ( ; i < maxwidth && i < 43; i++)
    mputc('.');
  if (i == 43)
    mputc('>');
  mputc('\n');

  /*
   * Build the format for printing the positions of the match, and 
   * then loop through the matches, printing the information.
   */
  if (multistring_mode && num_strings > 1)
    sprintf(format, " %%%dd:  %%%dd-%%%dd:    ", maxiddigs, maxposdigs,
            maxposdigs);
  else
    sprintf(format, "    %%%dd-%%%dd:    ", maxposdigs, maxposdigs);

  T = NULL;
  N = 0;
  if (!multistring_mode) {
      T = string->sequence;
      N = string->length;
  }
  else if (num_strings == 1) {
     T = strings[0]->sequence;
    N = strings[0]->length;
  }
    
  for (count=0,ptr=list; count < num_matches; count++,ptr=ptr->next) {
    if (multistring_mode && num_strings > 1) {
      printf(format, ptr->textid, ptr->lend, ptr->rend);
      T = strings[ptr->textid-1]->sequence;
      N = strings[ptr->textid-1]->length;
    }
    else
      printf(format, ptr->lend, ptr->rend);

    if (ptr->lend - 4 >= 1) {
      mputs("...");
      i = ptr->lend - 4;
    }
    else {
      mputs("   ");
      for (i=ptr->lend-4; i < 1; i++)
        mputc(' ');
    }

    for (j=0; j < 44 && i <= N && i <= ptr->rend + 4; i++,j++)
      mputc((isprint((int)T[i-1]) ? T[i-1] : '#'));

    if (i <= N)
      mputs("...");

    if (mputc('\n') == 0)
      break;
  }

  mputc('\n');

  return 1;
}
Ejemplo n.º 14
0
void mr_berror(_MIPD_ int nerr)
{  /*  Big number error routine  */
#ifndef MR_STRIPPED_DOWN
int i;
#endif

#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif

if (mr_mip->ERCON)
{
    mr_mip->ERNUM=nerr;
    return;
}
#ifndef MR_NO_STANDARD_IO

#ifndef MR_STRIPPED_DOWN
mputs("\nMIRACL error from routine ");
if (mr_mip->depth<MR_MAXDEPTH) mputs(names[mr_mip->trace[mr_mip->depth]]);
else                           mputs("???");
fputc('\n',stdout);

for (i=mr_mip->depth-1;i>=0;i--)
{
    mputs("              called from ");
    if (i<MR_MAXDEPTH) mputs(names[mr_mip->trace[i]]);
    else               mputs("???");
    fputc('\n',stdout);
}

switch (nerr)
{
case 1 :
mputs("Number base too big for representation\n");
break;
case 2 :
mputs("Division by zero attempted\n");
break;
case 3 : 
mputs("Overflow - Number too big\n");
break;
case 4 :
mputs("Internal result is negative\n");
break;
case 5 : 
mputs("Input format error\n");
break;
case 6 :
mputs("Illegal number base\n");
break;
case 7 : 
mputs("Illegal parameter usage\n");
break;
case 8 :
mputs("Out of space\n");
break;
case 9 :
mputs("Even root of a negative number\n");
break;
case 10:
mputs("Raising integer to negative power\n");
break;
case 11:
mputs("Attempt to take illegal root\n");
break;
case 12:
mputs("Integer operation attempted on Flash number\n");
break;
case 13:
mputs("Flash overflow\n");
break;
case 14:
mputs("Numbers too big\n");
break;
case 15:
mputs("Log of a non-positive number\n");
break;
case 16:
mputs("Flash to double conversion failure\n");
break;
case 17:
mputs("I/O buffer overflow\n");
break;
case 18:
mputs("MIRACL not initialised - no call to mirsys()\n");
break;
case 19:
mputs("Illegal modulus \n");
break;
case 20:
mputs("No modulus defined\n");
break;
case 21:
mputs("Exponent too big\n");
break;
case 22:
mputs("Unsupported Feature - check mirdef.h\n");
break;
case 23:
mputs("Specified double length type isn't double length\n");
break;
case 24:
mputs("Specified basis is NOT irreducible\n");
break;
case 25:
mputs("Unable to control Floating-point rounding\n");
break;
case 26:
mputs("Base must be binary (MR_ALWAYS_BINARY defined in mirdef.h ?)\n");
break;
case 27:
mputs("No irreducible basis defined\n");
break;
case 28:
mputs("Composite modulus\n");
break;
default:
mputs("Undefined error\n");
break;
}
exit(0);
#else
mputs("MIRACL error\n");
exit(0);
#endif

#endif
}
Ejemplo n.º 15
0
int main()
{
	mputs("THIS IS MAIN\n");

	uint i;
	for(i=0;i<PIPE_NUM_LIMIT;i++)
		pipes[i].head = pipes[i].tail = 0;

	uint task_stack[TASK_NUM_LIMIT][TASK_STACK_SIZE];
	RegSet *rs[TASK_NUM_LIMIT];
	rs[task_number]=set_task(task_stack[task_number],&init_task);
	task_number++;

	SYSTICK_RELOAD_VALUE=5000;
	SYSTICK_CONTROL=SYSTICK_CONTROL_ENABLE|SYSTICK_CONTROL_CONTINUOUS;

	while(1)
	{
		//mputc('*');
		if(rs[task_currnet]->state==TASK_READY)
			rs[task_currnet] = to_user_mode(rs[task_currnet]);
		//rs[task_currnet]->state=TASK_READY;
		switch(rs[task_currnet]->it_number)
		{
			case IT_FORK:
				if(task_number==TASK_NUM_LIMIT)
				{
					rs[task_currnet]->r0=-1;
				}
				else
				{
					uint used=(task_stack[task_currnet])+
						(TASK_STACK_SIZE)-(uint *)(rs[task_currnet]);
					rs[task_number]=(RegSet *)
						(task_stack[task_number]+(TASK_STACK_SIZE)-used);
					imemcpy(rs[task_number],rs[task_currnet],used);

					rs[task_currnet]->r0=task_number;
					rs[task_number]->r0=0;
					task_number++;
				}
				break;
			case IT_GETPID:
				rs[task_currnet]->r0=task_currnet;
				break;
			case IT_READ:
				_read(rs[task_currnet],&pipes[rs[task_currnet]->r0]);
				if(rs[task_currnet]->state==TASK_READY)
				{
					for(i=0;i<task_number;i++)
					{
						if(rs[i]->state==TASK_WAIT_WRITE)
							rs[i]->state=TASK_WRITE;
					}
				}
				break;
			case IT_WRITE:
				_write(rs[task_currnet],&pipes[rs[task_currnet]->r0]);
				if(rs[task_currnet]->state==TASK_READY)
				{
					for(i=0;i<task_number;i++)
					{
						if(rs[i]->state==TASK_WAIT_READ)
							rs[i]->state=TASK_READ;
					}
				}
				break;

			case IT_SYSCALL:
				break;
			case IT_SYSTICK:
				break;
		}
		while(1)
		{
			task_currnet=(task_currnet+1>=task_number)?0:task_currnet+1;
			uint state=rs[task_currnet]->state;
			if(state==TASK_READY||state==TASK_READ||state==TASK_WRITE) break;
		}
	}

	//while(1);

	//int n;
	//while(n!=9)
	//{
	//	mputs("\n\n\n");
	//	mputs("PROGRAM START\n");
	//	mputs(">> 1: qsort\n");
	//	mputs(">> 2: gcd\n");
	//	mputs(">> 3: bcd\n");
	//	mputs(">> 9: go\n");
	//	n=mgetn();
	//	switch(n)
	//	{
	//		case 1: qsort_task(); break;
	//		case 2: gcd_task();   break;
	//		case 3: bcd_task();   break;
	//	}
	//}

	//while(1);
	//return 0;
}
Ejemplo n.º 16
0
void finit(){
	//push the address of the next open cell to the stack
	COLON(here);
	COMPPRIM(LIT);
	enter(0);
	COMPPRIM(PEEK);
	COMPPRIM(EXIT);
	//compile TOS
	COLON(comptos);
	enter(here);
	COMPPRIM(POKE);
	enter(here);
	COMPPRIM(LIT);
	enter(1);
	COMPPRIM(PLUS);
	COMPPRIM(LIT);
	enter(0);
	COMPPRIM(POKE);
	COMPPRIM(EXIT);
	//turn a nonzero value to -1, and keep zero values
	COLON(logify);
	COMPPRIM(LIT);
	enter(0);
	COMPPRIM(EQL);
	COMPPRIM(NOT);
	COMPPRIM(EXIT);
	//branch if false
	COLON(notbranch);
	COMPPRIM(LIT);  //I could have used logify and then not, but there's an extra 'not' in logify, so for efficiency I just implemented it inline.
	enter(0);
	COMPPRIM(EQL);
	COMPPRIM(PUSNXT);
	COMPPRIM(AND); //compute branch value depending on the boolean found on the stack.
	COMPPRIM(FROMR);
	COMPPRIM(PLUS);
	COMPPRIM(TOR);
	//add the branch value to the return value and store it back on the return stack, overwriting the old value.
	COMPPRIM(EXIT);
	//peek xt
	COLON(peekxt);
	COMPPRIM(LIT);
	enter(127);
	COMPPRIM(WORD);
	COMPPRIM(DUP);
	enter(comptos);
	COMPPRIM(FIND);
	enter(here);
	COMPPRIM(LIT);
	enter(1);
	COMPPRIM(MINUS);
	COMPPRIM(PEEK);
	COMPPRIM(LIT);
	enter(0);
	COMPPRIM(POKE);
	COMPPRIM(EXIT);
	//execute xt
	COLON(excut);
	int extspace = *dict + 3;
	COMPPRIM(LIT);
	enter(extspace);
	COMPPRIM(POKE);
	enter(0);
	COMPPRIM(EXIT);
	//interpret
	intern(DOCOL, -1);
	COMPPRIM(FROMR);
	COMPPRIM(FROMR);
	COMPPRIM(FROMR);
	COMPPRIM(PDROP);
	COMPPRIM(PDROP);
	COMPPRIM(PDROP);
	enter(*dict+1);
	enter(0);
	int intloop = *dict-1;
	enter(peekxt);
	COMPPRIM(LIT);
	enter(1);
	COMPPRIM(EQL);
	COMPPRIM(NOT);
	IF(intfound);
	enter(excut);
	ELSE(intfound);
	COMPPRIM(ATOI);
	THEN(intfound);
	COMPPRIM(LIT);
	enter((int)'\n');
	COMPPRIM(LIT);
	enter((int)'k');
	COMPPRIM(LIT);
	enter((int)'o');
	COMPPRIM(EMIT);
	COMPPRIM(EMIT);
	COMPPRIM(EMIT);
	COMPPRIM(FROMR);
	COMPPRIM(PDROP);
	enter(intloop);
	//compile
	intern(DOCOL, 0);
	COMPPRIM(FROMR);
	COMPPRIM(FROMR);
	COMPPRIM(FROMR);
	COMPPRIM(PDROP);
	COMPPRIM(PDROP);
	COMPPRIM(PDROP);
	enter(*dict+1);
	enter(0);
	int comploop = *dict-1;
	enter(peekxt);
	COMPPRIM(DUP);
	COMPPRIM(LIT);
	enter(1);
	COMPPRIM(EQL);
	COMPPRIM(NOT);
	IF(compfound);
	IF(compimm);
	enter(excut);
	ELSE(compimm);
	enter(comptos);
	ELSE(compfound);
	COMPPRIM(PDROP);
	COMPPRIM(LIT);
	COMPPRIM(LIT);
	enter(comptos);
	COMPPRIM(ATOI);
	enter(comptos);
	THEN(compfound); THEN(compimm);
	COMPPRIM(FROMR);
	COMPPRIM(PDROP);
	enter(comploop);
	//colon compiler
	COLON(colon);
	enter(here);
	COMPPRIM(LIT);
	enter(3);
	COMPPRIM(DUP);
	COMPPRIM(PEEK);
	enter(comptos);
	COMPPRIM(POKE);
	COMPPRIM(LIT);
	enter(127);
	COMPPRIM(WORD);
	COMPPRIM(PDROP);
	COMPPRIM(LIT);
	enter(0);
	COMPPRIM(DUP);
	enter(comptos);
	enter(comptos);
	COMPPRIM(EXIT);
	//cold start to setup interpreter
	mputs("cs @ ");
	puts(itoa(*dict));
	int coldstart = *dict;
	enter(DOCOL);
	enter(intloop);

	IP=coldstart;
	cs=coldstart;
}
Ejemplo n.º 17
0
void execute(int x) {
	int op = disk[x];
	char *s;
	switch (op) {
	case DOCOL:
		w = ++IP;
		RPUSH ++IP;
		IP = disk[w];
		break;
	case KEY:
		PUSH getchar();
		NEXT;
		break;
	case WORD:
		w = *dict;
		enter(0);
		int slen = scant((char) TOS, (char *)(disk + (*dict)));
		DROP;
		disk[w] = slen;
		PUSH w;
		*dict += slen/PACK + 1;
		NEXT;
		break;
	case FIND:
		w = *link;
		while (!(streql(disk+TOS, (disk+w+1))) && w) {
			w = disk[w];
		}
		if (!w) {
			PUSH 1;
		} else {
			TOS = w + 2 + ((disk[w+1])/PACK + 2);
			w = disk[TOS-1];
			PUSH w;
		}
		NEXT;
		break;
	case EXIT:
		RDROP;
		NEXT;
		break;
	case PEEK:
		TOS = disk[TOS];
		NEXT;
		break;
	case POKE:
		disk[TOS] = NTOS;
		DROP;
		DROP;
		NEXT;
		break;
	case LIT:
		PUSH disk[TORS++];
		NEXT;
		break;
	case PUSNXT:
		PUSH disk[NTORS++];
		NEXT;
		break;
	case BRANCH:
		TORS += disk[TORS] + 1; //was off by one
		NEXT;
		break;
	case PDROP:
		DROP;
		NEXT;
		break;
	case TOR:
		w = TORS;
		TORS = TOS;
		RPUSH w;
		DROP;
		NEXT;
		break;
	case FROMR:
		PUSH NTORS;
		w = TORS;
		RDROP;
		TORS = w;
		NEXT;
		break;
	case DUP:
		w = TOS;
		PUSH w;
		NEXT;
		break;
	case SWAP:
		w = TOS;
		TOS = NTOS;
		NTOS = w;
		NEXT;
		break;
	case ROT:
		w = TOS;
		TOS = disk[(*tosp)+2];
		disk[(*tosp)+2] = NTOS;
		NTOS = w;
		NEXT;
		break;
	case PLUS:
		TWOLEVEL(TOS + NTOS);
		break;
	case MINUS:
		TWOLEVEL(NTOS - TOS);
		break;
	case MULT:
		TWOLEVEL(TOS * NTOS);
		break;
	case DIV:
		TWOLEVEL(NTOS / TOS);
		break;
	case RSHIFT:
		NTOS >>= TOS;
		DROP;
		NEXT;
		break;
	case LSHIFT:
		NTOS <<= TOS;
		DROP;
		NEXT;
		break;
	case LESS:
		TWOLEVEL(NTOS < TOS ? -1 : 0);
		break;
	case GREAT:
		TWOLEVEL(NTOS > TOS ? -1 : 0);
		break;
	case EQL:
		NTOS = NTOS == TOS ? -1 : 0;
		DROP;
		NEXT;
		break;
	case EMIT:
		mputchar(TOS);
		DROP;
		NEXT;
		break;
	case PUTS:
		putnumstr(disk+TOS);
		DROP;
		NEXT;
		break;
	case ATOI:
		w = TOS+1;
		TOS = (int) strtol((char *)(disk+w),&s, 10);
		if(s == (char *)(disk+w)){
			DROP;
			mputs("NO NUMBER FOUND: ");
			putnumstr(disk+w-1);
			puts("");
		}
		NEXT;
		break;
	case PNUM:
		puts(itoa(TOS));
		DROP;
		NEXT;
		break;
	case AND:
	       	NTOS &= TOS;
		DROP;
		NEXT;
		break;
	case OR:
		NTOS |= TOS;
		DROP;
		NEXT;
		break;
	case XOR:
		NTOS ^= TOS;
		DROP;
		NEXT;
		break;
	case NOT:
		TOS = ~TOS;
		NEXT;
		break;
	default: //this should be unreachable
		mputs("execute fallthrough: ");
		puts(itoa(op));
		dumpstack(3,tosp);
		dumpstack(5,rsp);
		dumpstack(15, disk+(*link));
		mputs("IP = ");
		puts(itoa(IP));
		stat();
		*rsp = DSIZE-(RSSIZE+STSIZE+1);
		IP = cs;
	}
}
Ejemplo n.º 18
0
static void repl_action(frameact action, u8 **ffp, u8 **fsp)
{
  struct repl_frame *frame = (struct repl_frame *)*ffp;

  switch (action)
    {
    case fa_unwind:
      throw_handled();
      frame->state = read_line;
      return;
    case fa_execute:
      switch (frame->state)
	{
	case read_line:
#ifdef USE_READLINE
	  if (frame->line)
	    free(frame->line);

	  frame->line = readline((char *)"motlle> ");

	  if (!frame->line)
	    exit(0);

	  if (*frame->line)
	    add_history(frame->line);
#else
	  {
	    char _line[512];

	    frame->line = _line;
	    fputs("mudlle> ", stdout);
	    if (!fgets(_line, sizeof _line, stdin))
	      exit(0);
	  }
#endif
	  read_from_string(frame->line);
	  frame->state = print_result;
	  context.display_error = TRUE;
	  context._mudout = context._muderr = mstdout;
	  context.call_count = MAX_CALLS;
	  compile_and_run(NULL, globals, "<interactive>", NULL, FALSE);
	  break;
	case print_result:
	  {
	    value result = stack_pop();

	    printf("Result: ");
	    mprint(mstdout, prt_print, result);
	    printf("\n");
	    frame->state = read_line;
	    break;
	  }
	default:
	  abort();
	}
      break;
    case fa_print:
      mputs("<repl>" EOL, muderr);
      break;
    case fa_gcforward:
      /* fall through */
    case fa_pop:
      pop_frame(ffp, fsp, sizeof(struct repl_frame));
      break;
    default: abort();
    }
}