Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/dpas/dpas-builtin.c  view on Meta::CPAN

#define	DPAS_BUILTIN_LOG10			19
#define	DPAS_BUILTIN_RINT			20
#define	DPAS_BUILTIN_ROUND			21
#define	DPAS_BUILTIN_SIN			22
#define	DPAS_BUILTIN_SINH			23
#define	DPAS_BUILTIN_SQRT			24
#define	DPAS_BUILTIN_TAN			25
#define	DPAS_BUILTIN_TANH			26
#define	DPAS_BUILTIN_TRUNC			27
#define	DPAS_BUILTIN_ABS			28
#define	DPAS_BUILTIN_MIN			29
#define	DPAS_BUILTIN_MAX			30
#define	DPAS_BUILTIN_SIGN			31
#define	DPAS_BUILTIN_ISNAN			32
#define	DPAS_BUILTIN_ISINF			33
#define	DPAS_BUILTIN_FINITE			34

/*
 * Table that defines the builtins.
 */
typedef struct
{
	const char	   *name;
	int				identifier;
	dpas_semvalue	(*func)(dpas_semvalue *args, int num_args);
	int				num_args;	/* -1 for a vararg function */

} dpas_builtin;
static dpas_builtin const builtins[] = {
	{"Write",		DPAS_BUILTIN_WRITE,		dpas_write,		 -1},
	{"WriteLn",		DPAS_BUILTIN_WRITELN,	dpas_writeln,	 -1},
	{"Flush",		DPAS_BUILTIN_FLUSH,		dpas_flush,		  0},
	{"Terminate",	DPAS_BUILTIN_TERMINATE,	dpas_terminate,	  1},
	{"New",			DPAS_BUILTIN_NEW,		dpas_new,	 	  1},
	{"Dispose",		DPAS_BUILTIN_DISPOSE,	dpas_dispose, 	  1},
	{"SameType",	DPAS_BUILTIN_SAMETYPE,	dpas_same_type,   2},
	{"SameShape",	DPAS_BUILTIN_SAMESHAPE,	dpas_same_shape,  2},
	{"Acos",		DPAS_BUILTIN_ACOS,		dpas_acos,        1},
	{"Asin",		DPAS_BUILTIN_ASIN,		dpas_asin,        1},
	{"Atan",		DPAS_BUILTIN_ATAN,		dpas_atan,        1},
	{"Atan2",		DPAS_BUILTIN_ATAN2,		dpas_atan2,       2},
	{"Ceil",		DPAS_BUILTIN_CEIL,		dpas_ceil,        1},
	{"Cos",			DPAS_BUILTIN_COS,		dpas_cos,         1},
	{"Cosh",		DPAS_BUILTIN_COSH,		dpas_cosh,        1},
	{"Exp",			DPAS_BUILTIN_EXP,		dpas_exp,         1},
	{"Floor",		DPAS_BUILTIN_FLOOR,		dpas_floor,       1},
	{"Log",			DPAS_BUILTIN_LOG,		dpas_log,         1},
	{"Log10",		DPAS_BUILTIN_LOG10,		dpas_log10,       1},
	{"Rint",		DPAS_BUILTIN_RINT,		dpas_rint,        1},
	{"Round",		DPAS_BUILTIN_ROUND,		dpas_round,       1},
	{"Sin",			DPAS_BUILTIN_SIN,		dpas_sin,         1},
	{"Sinh",		DPAS_BUILTIN_SINH,		dpas_sinh,        1},
	{"Sqrt",		DPAS_BUILTIN_SQRT,		dpas_sqrt,        1},
	{"Tan",			DPAS_BUILTIN_TAN,		dpas_tan,         1},
	{"Tanh",		DPAS_BUILTIN_TANH,		dpas_tanh,        1},
	{"Trunc",		DPAS_BUILTIN_TRUNC,		dpas_trunc,       1},
	{"Abs",			DPAS_BUILTIN_ABS,		dpas_abs,         1},
	{"Min",			DPAS_BUILTIN_MIN,		dpas_min,         2},
	{"Max",			DPAS_BUILTIN_MAX,		dpas_max,         2},
	{"Sign",		DPAS_BUILTIN_SIGN,		dpas_sign,        1},
	{"IsNaN",		DPAS_BUILTIN_ISNAN,		dpas_isnan,       1},
	{"IsInf",		DPAS_BUILTIN_ISINF,		dpas_isinf,       1},
	{"Finite",		DPAS_BUILTIN_FINITE,	dpas_finite,      1},
};
#define	num_builtins	(sizeof(builtins) / sizeof(dpas_builtin))

int dpas_is_builtin(const char *name)
{
	int index;
	for(index = 0; index < num_builtins; ++index)
	{
		if(!jit_stricmp(name, builtins[index].name))
		{
			return builtins[index].identifier;
		}
	}
	return 0;
}

dpas_semvalue dpas_expand_builtin
	(int identifier, dpas_semvalue *args, int num_args)
{
	int index;
	dpas_semvalue value;
	for(index = 0; index < num_builtins; ++index)
	{
		if(builtins[index].identifier == identifier)
		{
			if(builtins[index].num_args != -1 &&
			   builtins[index].num_args != num_args)
			{
				dpas_error("incorrect number of arguments to `%s' builtin",
						   builtins[index].name);
				dpas_sem_set_error(value);
				return value;
			}
			return (*(builtins[index].func))(args, num_args);
		}
	}
	dpas_sem_set_error(value);
	return value;
}



( run in 0.461 second using v1.01-cache-2.11-cpan-97f6503c9c8 )