/**
 * This file is part of Erjang - A JVM-based Erlang VM
 *
 * Copyright (c) 2009 by Trifork
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/


package erjang.m.erlang;

import erjang.BIF;
import erjang.EAtom;
import erjang.EFun;
import erjang.EObject;
import erjang.ERT;
import erjang.ESeq;
import erjang.ETuple;
import erjang.ETuple2;

/**
 * BIFs for fun_info/1, fun_info/2 and make_fun/3
 */
public class ErlFun {

	@BIF
	public static EObject fun_info(EObject fun_arg, EObject spec_arg)
	{
		EFun fun = fun_arg.testFunction();
		EAtom spec = spec_arg.testAtom();
		
		if (fun == null || spec == null) throw ERT.badarg(fun_arg, spec_arg);
		
		return fun.info(spec);
	}
	
	@BIF
	public static ESeq fun_info(EObject fun_arg)
	{
		EFun fun = fun_arg.testFunction();
		if (fun == null) throw ERT.badarg(fun_arg);
		
		ESeq res = ERT.NIL;
		
		boolean is_local = fun.is_local();
		
		if (is_local) {
			res = res.cons(fun.info(ERT.am_uniq));
			res = res.cons(fun.info(ERT.am_new_uniq));
			res = res.cons(fun.info(ERT.am_new_index));
			res = res.cons(fun.info(ERT.am_index));
			res = res.cons(fun.info(ERT.am_pid));
		}
		
		res = res.cons(fun.info(ERT.am_env));
		res = res.cons(fun.info(ERT.am_arity));
		res = res.cons(fun.info(ERT.am_name));
		res = res.cons(fun.info(ERT.am_module));
		
		res = res.cons(fun.info(ERT.am_type));
		
		return res;
	}
	
}

@@ -681,16 +681,39 @@
 rlang;%0A%0A
+import kilim.Pausable;%0A
 import e
@@ -764,16 +764,73 @@
 g.EFun;%0A
+import erjang.EFunHandler;%0Aimport erjang.EModuleManager;%0A
 import e
@@ -844,16 +844,37 @@
 Object;%0A
+import erjang.EProc;%0A
 import e
@@ -904,16 +904,38 @@
 g.ESeq;%0A
+import erjang.ESmall;%0A
 import e
@@ -970,16 +970,37 @@
 ETuple2;
+%0Aimport erjang.FunID;
 %0A%0A/**%0A *
@@ -2013,10 +2013,319 @@
 s;%0A%09%7D%0A%09%0A
+%09@BIF%0A%09public static EFun make_fun(EObject m, EObject f, EObject a)%0A%09%7B%0A%09%09EAtom mod = m.testAtom();%0A%09%09EAtom fun = f.testAtom();%0A%09%09ESmall arity = a.testSmall();%0A%09%09if (mod==null%7C%7Cfun==null%7C%7Carity==null) %7B%0A%09%09%09throw ERT.badarg(m,f,a);%0A%09%09%7D%0A%09%09%0A%09%09return EModuleManager.resolve(new FunID(mod, fun, arity.value));%0A%09%7D%0A%09%0A
 %7D%0A

Implement erlang:make_fun/3 (undocumented bif).