예제 #1
0
BIF_RETTYPE delete_module_1(BIF_ALIST_1)
{
    ErtsCodeIndex code_ix;
    Module* modp;
    int is_blocking = 0;
    int success = 0;
    Eterm res = NIL;

    if (is_not_atom(BIF_ARG_1)) {
	BIF_ERROR(BIF_P, BADARG);
    }

    if (!erts_try_seize_code_write_permission(BIF_P)) {
	ERTS_BIF_YIELD1(bif_export[BIF_delete_module_1], BIF_P, BIF_ARG_1);
    }

    {
	erts_start_staging_code_ix(0);
	code_ix = erts_staging_code_ix();
	modp = erts_get_module(BIF_ARG_1, code_ix);
	if (!modp) {
	    res = am_undefined;
	}
	else if (modp->old.code_hdr) {
	    erts_dsprintf_buf_t *dsbufp = erts_create_logger_dsbuf();
	    erts_dsprintf(dsbufp, "Module %T must be purged before loading\n",
			  BIF_ARG_1);
	    erts_send_error_to_logger(BIF_P->group_leader, dsbufp);
	    ERTS_BIF_PREP_ERROR(res, BIF_P, BADARG);
	}
	else {
	    if (modp->curr.num_breakpoints > 0 ||
		modp->curr.num_traced_exports > 0 ||
		IF_HIPE(hipe_need_blocking(modp))) {
		/* tracing or hipe need to go single threaded */
		erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN);
		erts_smp_thr_progress_block();
		is_blocking = 1;
		if (modp->curr.num_breakpoints) {
		    erts_clear_module_break(modp);
		    ASSERT(modp->curr.num_breakpoints == 0);
		}
	    }
	    delete_code(modp);
	    res = am_true;
	    success = 1;
	}
    }
    {
	struct m mod;
	Eterm retval;
	mod.module = BIF_ARG_1;
	mod.modp = modp;
	retval = staging_epilogue(BIF_P, success, res, is_blocking, &mod, 1, 0);
	return retval;
    }
}
예제 #2
0
Eterm
beam_make_current_old(Process *c_p, ErtsProcLocks c_p_locks, Eterm module)
{
    Module* modp = erts_put_module(module);

    /*
     * Check if the previous code has been already deleted;
     * if not, delete old code; error if old code already exists.
     */

    if (modp->curr.code_hdr && modp->old.code_hdr)  {
	return am_not_purged;
    } else if (!modp->old.code_hdr) { /* Make the current version old. */
	delete_code(modp);
    }
    return NIL;
}
예제 #3
0
int
beam_make_current_old(Process *c_p, ErtsProcLocks c_p_locks, Eterm module)
{
    Module* modp = erts_put_module(module);

    /*
     * Check if the previous code has been already deleted;
     * if not, delete old code; error if old code already exists.
     */

    if (modp->code != NULL && modp->old_code != NULL)  {
	return -3;
    } else if (modp->old_code == NULL) { /* Make the current version old. */
	if (display_loads) {
	    erts_printf("saving old code\n");
	}
	delete_code(c_p, c_p_locks, modp);
	delete_export_references(module);
    }
    return 0;
}
예제 #4
0
BIF_RETTYPE delete_module_1(BIF_ALIST_1)
{
    int res;

    if (is_not_atom(BIF_ARG_1))
	goto badarg;

    erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN);
    erts_smp_block_system(0);

    {
	Module *modp = erts_get_module(BIF_ARG_1);
	if (!modp) {
	    res = am_undefined;
	}
	else if (modp->old_code != 0) {
	    erts_dsprintf_buf_t *dsbufp = erts_create_logger_dsbuf();
	    erts_dsprintf(dsbufp, "Module %T must be purged before loading\n",
			  BIF_ARG_1);
	    erts_send_error_to_logger(BIF_P->group_leader, dsbufp);
	    res = am_badarg;
	}
	else {
	    delete_export_references(BIF_ARG_1);
	    delete_code(BIF_P, 0, modp);
	    res = am_true;
	}
    }

    erts_smp_release_system();
    erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN);

    if (res == am_badarg) {
    badarg:
	BIF_ERROR(BIF_P, BADARG);
    }
    BIF_RET(res);
}
예제 #5
0
파일: compiler.c 프로젝트: vroman/edivc
void gen(int param, int op, int pa)
{
  optimizado = 0;

  switch (op)
  {
  case lcar:
    if (code[15].op == lcar)
    {
      code[15].op = mem[imem - 2] = lcar2;
      code[15].param = 2;
      mem[imem++] = pa;
      optimizado = 1;
    }
    else if (code[15].op == lcar2)
    {
      code[15].op = mem[imem - 3] = lcar3;
      code[15].param = 3;
      mem[imem++] = pa;
      optimizado = 1;
    }
    else if (code[15].op == lcar3)
    {
      code[15].op = mem[imem - 4] = lcar4;
      code[15].param = 4;
      mem[imem++] = pa;
      optimizado = 1;
    }
    break;
  case lasp:
    if (code[15].op == lasi)
    {
      if (code[14].op == lcar)
      {
        remove_code(1);
        code[15].op = mem[imem - 2] = lcarasiasp;
      }
      else
      {
        code[15].op = mem[imem - 1] = lasiasp;
        optimizado = 1;
      }
    }
    else if (code[15].op == lfun)
    {
      code[15].op = mem[imem - 2] = lfunasp;
      optimizado = 1;
    }
    else if (code[15].op == lext)
    {
      code[15].op = mem[imem - 2] = lextasp;
      optimizado = 1;
    }
    break;
  case laid:
    if (code[15].op == lcar)
    {
      code[15].op = mem[imem - 2] = lcaraid;
      optimizado = 1;
    }
    break;
  case lptr:
    if (code[15].op == lcar)
    {
      code[15].op = mem[imem - 2] = lcarptr;
      optimizado = 1;
    }
    else if (code[15].op == lcaradd)
    {
      code[15].op = mem[imem - 2] = lcaraddptr;
      optimizado = 1;
    }
    else if (code[15].op == laid)
    {
      code[15].op = mem[imem - 1] = laidptr;
      optimizado = 1;
    }
    else if (code[15].op == ladd)
    {
      code[15].op = mem[imem - 1] = laddptr;
      optimizado = 1;
    }
    else if (code[15].op == lcaraid)
    {
      code[15].op = mem[imem - 2] = lcaraidptr;
      optimizado = 1;
    }
    break;
  case lcpa:
    if (code[15].op == lcaraid)
    {
      code[15].op = mem[imem - 2] = lcaraidcpa;
      optimizado = 1;
    }
    break;
  case ladd:
    if (code[15].op == lcar2)
    {
      code[15].op = mem[imem - 3] = lcar;
      code[15].param = 1;
      mem[imem - 2] += mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar3)
    {
      code[15].op = mem[imem - 4] = lcar2;
      code[15].param = 2;
      mem[imem - 2] += mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar4)
    {
      code[15].op = mem[imem - 5] = lcar3;
      code[15].param = 3;
      mem[imem - 2] += mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar)
    {
      if (mem[imem - 1] == 0)
        remove_code(1);
      else
      {
        code[15].op = mem[imem - 2] = lcaradd;
        optimizado = 1;
      }
    }
    else if (code[15].op == lcarmul)
    {
      code[15].op = mem[imem - 2] = lcarmuladd;
      optimizado = 1;
    }
    break;
  case lmul:
    if (code[15].op == lcar2)
    {
      code[15].op = mem[imem - 3] = lcar;
      code[15].param = 1;
      mem[imem - 2] *= mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar3)
    {
      code[15].op = mem[imem - 4] = lcar2;
      code[15].param = 2;
      mem[imem - 2] *= mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar4)
    {
      code[15].op = mem[imem - 5] = lcar3;
      code[15].param = 3;
      mem[imem - 2] *= mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar)
    {
      if (mem[imem - 1] == 1)
        remove_code(1);
      else
      {
        code[15].op = mem[imem - 2] = lcarmul;
        optimizado = 1;
      }
    }
    break;
  case lsub:
    if (code[15].op == lcar2)
    {
      code[15].op = mem[imem - 3] = lcar;
      code[15].param = 1;
      mem[imem - 2] -= mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar3)
    {
      code[15].op = mem[imem - 4] = lcar2;
      code[15].param = 2;
      mem[imem - 2] -= mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar4)
    {
      code[15].op = mem[imem - 5] = lcar3;
      code[15].param = 3;
      mem[imem - 2] -= mem[imem - 1];
      imem--;
      optimizado = 1;
    }
    else if (code[15].op == lcar)
    {
      if (mem[imem - 1] == 0)
        remove_code(1);
      else
      {
        code[15].op = mem[imem - 2] = lcarsub;
        optimizado = 1;
      }
    }
    break;
  case ldiv:
    if (code[15].op == lcar2)
    {
      if (mem[imem - 1] != 0)
      {
        code[15].op = mem[imem - 3] = lcar;
        code[15].param = 1;
        mem[imem - 2] /= mem[imem - 1];
        imem--;
        optimizado = 1;
      }
    }
    else if (code[15].op == lcar3)
    {
      if (mem[imem - 1] != 0)
      {
        code[15].op = mem[imem - 4] = lcar2;
        code[15].param = 2;
        mem[imem - 2] /= mem[imem - 1];
        imem--;
        optimizado = 1;
      }
    }
    else if (code[15].op == lcar4)
    {
      if (mem[imem - 1] != 0)
      {
        code[15].op = mem[imem - 5] = lcar3;
        code[15].param = 3;
        mem[imem - 2] /= mem[imem - 1];
        imem--;
        optimizado = 1;
      }
    }
    else if (code[15].op == lcar)
    {
      if (mem[imem - 1] == 1)
        remove_code(1);
      else if (mem[imem - 1] != 0)
      {
        code[15].op = mem[imem - 2] = lcardiv; /* Un cardiv nunca será "cardiv 0" */
        optimizado = 1;
      }
    }
    break;
  case lneg:
    if (code[15].op == lcar || code[15].op == lcar2 || code[15].op == lcar3 || code[15].op == lcar4)
    {
      mem[imem - 1] = -mem[imem - 1];
      optimizado = 1;
    }
    break;
  case lnot:
    if (code[15].op == lcar || code[15].op == lcar2 || code[15].op == lcar3 || code[15].op == lcar4)
    {
      mem[imem - 1] = mem[imem - 1] ^ -1;
      optimizado = 1;
    }
    break;
  }

  if (!optimizado)
  {
    if (imem - code[15].dir > 2)
      delete_code();
    add_code(imem, param, op);
    if (param)
    {
      mem[imem++] = op;
      mem[imem++] = pa;
    }
    else
      mem[imem++] = op;
  }
}