예제 #1
0
파일: bif_code.c 프로젝트: aidanhs/teeterl
term_t bif_spawn0_1(term_t F, process_t *ctx)
{
	process_t *proc;
	term_t mod, fun, args = nil;
	term_t cons = nil;
	term_t fridge;
	int i, nfree;

	if (!is_fun(F))
		return A_BADARG;

	fridge = fun_fridge(F);
	nfree = int_value2(tup_size(fridge));

	if (int_value2(fun_arity(F)) != nfree)
		return A_BADARG;

	for (i = 0; i < nfree; i++)
		lst_add(args, cons, tup_elts(fridge)[i], proc_gc_pool(ctx));

	mod = fun_amod(F);
	fun = fun_afun(F);

	proc = proc_spawn(proc_code_base(ctx), proc_atoms(ctx), mod, fun, args);
	if (proc == 0)
		return A_BADARG;

	result(proc_pid(proc, proc_gc_pool(ctx)));
	return AI_OK;
}
예제 #2
0
파일: bif_proc.c 프로젝트: bkearns/ling
term_t cbif_spawn1(proc_t *proc, term_t *regs)
{
	term_t Fun = regs[0];
	if (!is_boxed(Fun))
		badarg(Fun);
	uint32_t *fdata = peel_boxed(Fun);
	if (boxed_tag(fdata) != SUBTAG_FUN)
		badarg(Fun);
	t_fun_t *f = (t_fun_t *)fdata;
	if (f->fe == 0)
		not_implemented("unloaded funs");
	if (fun_arity(fdata) != fun_num_free(fdata))
		badarg();

	proc_t *new_proc = proc_make(proc->group_leader);
	int x = proc_spawn_fun0_N(new_proc, f);
	if (x < 0)
	{
		proc_destroy(new_proc);
		if (x == -TOO_DEEP)
			fail(A_SYSTEM_LIMIT);
		else
			fail(A_NOT_SPAWNED);
	}

	return new_proc->pid;
}