Beispiel #1
0
PUBLIC OVECTOR getcont_from(VMSTATE vms) {
  OVECTOR cont;
  VECTOR cstk;
  int i;

  cont = newovector_noinit(CONT_MAXSLOTINDEX, T_CONTINUATION);
  ATPUT(cont, CONT_FRAME, (OBJ) vms->r->vm_frame);
  cstk = newvector_noinit(vms->c.vm_top);
  ATPUT(cont, CONT_STACK, (OBJ) cstk);

  for (i = 0; i < vms->c.vm_top; i++)
    ATPUT(cstk, i, AT(vms->r->vm_stack, i));

  return cont;
}
Beispiel #2
0
PRIVATE void compile_main(FILE *conni, FILE *conno) {
  REPL_DATA rd = allocmem(sizeof(repl_data));
  VMstate vms;

  rd->h1 = rd->h2 = NULL;

  protect(&rd->h1);
  protect(&rd->h2);

  rd->vmregs = (VMREGS) newvector(NUM_VMREGS);	/* dodgy casting :-) */
  vms.r = rd->vmregs;
  protect((OBJ *)(&rd->vmregs));

  init_vm(&vms);
  vms.c.vm_state = VM_STATE_NOQUOTA;

  while (vms.c.vm_state != VM_STATE_DYING) {
    ScanInst si;
    char buf[16384];

    rd->h1 = (OBJ) newbvector(0);

    while (1) {
      char *result;

      result = fgets(buf, 256, conni);

      if (result == NULL)
	break;

      while (1) {
	int l = strlen(buf);
	if (buf[l-1] == '\r' || buf[l-1] == '\n')
	  buf[l-1] = '\0';
	else
	  break;
      }
      strcat(buf, "\n");

      if (!strcmp(buf, ".\n"))
	break;

      rd->h2 = (OBJ) newstring(buf);
      rd->h1 = (OBJ) bvector_concat((BVECTOR) rd->h1, (BVECTOR) rd->h2);
    }

    gc_reach_safepoint();

    rd->h2 = (OBJ) newstringconn((BVECTOR) rd->h1);
    fill_scaninst(&si, (OVECTOR) rd->h2);

    while (!conn_closed((OVECTOR) rd->h2)) {
      rd->h1 = (OBJ) parse(&vms, &si);
      gc_reach_safepoint();

      if (rd->h1 == NULL) {
	sprintf(buf, "-->! the compiler returned NULL.\n");
      } else {
	vms.c.vm_state = VM_STATE_NOQUOTA;

	ATPUT((OVECTOR) rd->h1, ME_OWNER, (OBJ) vms.r->vm_uid);
	vms.r->vm_effuid = vms.r->vm_uid;
	{
	  OVECTOR c = newovector_noinit(CL_MAXSLOTINDEX, T_CLOSURE);
	  ATPUT(c, CL_SELF, NULL);
	  ATPUT(c, CL_METHOD, rd->h1);
	  rd->h1 = (OBJ) c;
	}
	apply_closure(&vms, (OVECTOR) rd->h1, newvector_noinit(1));

	while (!run_vm(&vms)) ;

	rd->h1 = (OBJ) newvector(2);
	ATPUT((VECTOR) rd->h1, 0, NULL);
	ATPUT((VECTOR) rd->h1, 1, vms.r->vm_acc);
	rd->h1 = lookup_prim(0x00001, NULL)(&vms, (VECTOR) rd->h1);
	rd->h1 = (OBJ) bvector_concat((BVECTOR) rd->h1, newbvector(1));
      	/* terminates C-string */

	gc_reach_safepoint();

	sprintf(buf, "--> %s\n", ((BVECTOR) rd->h1)->vec);
      }

      fputs(buf, conno);
    }
  }

  unprotect((OBJ *)(&rd->vmregs));
  unprotect(&rd->h2);
  unprotect(&rd->h1);

  freemem(rd);
}