Example #1
0
static void parseexpressionclause(void)
{
  Cell *definition = makeerror();

  if(strcmp(tokenval, "=") != 0) parseerror(5);
  do
  {
    gettoken();
    parseexpression(MAXPRIO);
    if(tokentype == COMMA)
    {
      gettoken();
      if(strcmp(tokenval, "if") == 0)
        gettoken();
      if(tokentype == OTHERWISE)
        gettoken();
      else
      {
        push(makeerror());
        makeinverse(_IF);
        parseexpression(MAXPRIO);
        make(_IF);
      }
    }
    definition = extenddefinition(definition, pop());
    while(tokentype == SEP) gettoken();
    if(tokentype == offside)
    {
      tokenoffside--;
      gettoken();
      tokenoffside++;
    }
  }
  while(strcmp(tokenval, "=") == 0);
  push(definition);
}
Example #2
0
int main(void)
{
  LBIG memsetup[5] = { 1000, 100, 20, 10, 200 };
  B* startup_dvt;    
  B fromconsoleframe[FRAMEBYTES], *sf;
  P nb, retc,tnb;
  B *sysdict, *userdict, *p;
  int sufd;

  sysop = _sysop;
  syserrc = _syserrc;
  syserrm = _syserrm;

  createfds();

  serialized = TRUE; // no serialize operator

/*----------------- SIGNALS that we wish to handle -------------------*/

/* FPU indigestion is recorded in the numovf flag;
   we do not wish to be killed by it
*/
  numovf = FALSE;
  signal(SIGFPE, SIGFPEhandler);

/* The broken pipe signal is ignored, so it cannot kill us;
   it will pop up in attempts to send on a broken connection
*/
  signal(SIGPIPE, SIG_IGN);

/* We use alarms to time-limit read/write operations on sockets  */
  timeout = FALSE;
  signal(SIGALRM, SIGALRMhandler);

/* The interrupt signal is produced by the control-c key of the
   console keyboard, it triggers the execution of 'abort'
*/
  abortflag = FALSE;
  signal(SIGINT, SIGINThandler);

 /*--------------------- set up the tiny D machine -------------------
   Not so tiny for the dvt, this should be good for most work
*/

  if (makeDmemory(memsetup))
    dm_error(0, "D memory");
  
/*----------------- construct frames for use in execution of D code */
  makename((B*) "error", errorframe);
  ATTR(errorframe) = ACTIVE;

  makename((B*) "fromconsole", fromconsoleframe);
  ATTR(fromconsoleframe) = ACTIVE;

  TAG(FREEvm) = STRING;
  ARRAY_SIZE(FREEvm) = 1024;
  VALUE_PTR(FREEvm) = FREEvm + FRAMEBYTES;
  ATTR(FREEvm) = ACTIVE;
  moveframe(FREEvm, inputframe);
  FREEvm += FRAMEBYTES + 1024;

/* The system dictionary is created in the workspace of the tiny D machine.
   If the operator 'makeVM' is used to create a large D machine, this larger
   machine inherits the system dictionary of the tiny machine. We memorize
   the pointers of the tiny D memory so we can revert to the tiny setup.
*/
  if ((sysdict = makeopdict((B *)sysop, syserrc,  syserrm)) == (B *)(-1L))
    dm_error(0,"Cannot make system dictionary");
  if ((userdict = makedict(memsetup[4])) == (B *)(-1L))
    dm_error(0,"Cannot make user dictionary");
  
/* The first two dictionaries on the dicts are systemdict and userdict;
   they are not removable
*/
  moveframe (sysdict-FRAMEBYTES,FREEdicts); 
  FREEdicts += FRAMEBYTES;
  moveframe (userdict-FRAMEBYTES,FREEdicts); 
  FREEdicts += FRAMEBYTES;

  setupdirs();

  fprintf(stderr, "Startup dir: %s\n", startup_dir);
/*----------- read startup_dvt.d and push on execs ----------*/
  startup_dvt 
    = (B*)strcat(strcpy(malloc(strlen((char*)startup_dir) 
			       + strlen("/startup_dgen.d") + 1),
			startup_dir),
		 "/startup_dgen.d");

  if ((sufd = open((char*)startup_dvt, O_RDONLY)) == -1)
    dm_error(errno,"Opening %s", startup_dvt);
  tnb = 0; sf = FREEvm; p = sf + FRAMEBYTES;
  TAG(sf) = ARRAY | BYTETYPE; ATTR(sf) = READONLY | ACTIVE | PARENT;
  VALUE_BASE(sf) = (P)p;
  
  while (((nb = read(sufd,p,CEILvm-p)) > 0) && (p <= CEILvm)) { 
    tnb += nb; 
    p += nb; 
  }
  if (nb == -1) dm_error(errno,"Reading %s", startup_dvt);
  if (p == CEILvm) dm_error(ENOMEM,"%s > VM", startup_dvt);
  ARRAY_SIZE(sf) = tnb;
  FREEvm += DALIGN(FRAMEBYTES + tnb);
  moveframe(sf,x1);
  FREEexecs = x2;
  
  /*-------------------------- run the D mill --------------------- */
  while (1) {
    switch(retc = exec(1000)) {
      case MORE: continue;
      case DONE:     
	moveframe(fromconsoleframe, x1); 
	FREEexecs=x2; 
	continue;
      case ABORT:
	printf("Failure...\n");
	exitval = ((UL32) EXIT_FAILURE) & 0xFF;
	die();
      case QUIT: case TERM: 
	printf("Success..\n"); 
	die();
      default: break;
    }

/*----------------------- error handler ---------------------------*/

    makeerror(retc, errsource);
  };
} /* of main */