示例#1
0
static void ccall(JF, js_Ast *fun, js_Ast *args)
{
	int n;
	switch (fun->type) {
	case EXP_INDEX:
		cexp(J, F, fun->a);
		emit(J, F, OP_DUP);
		cexp(J, F, fun->b);
		emit(J, F, OP_GETPROP);
		emit(J, F, OP_ROT2);
		break;
	case EXP_MEMBER:
		cexp(J, F, fun->a);
		emit(J, F, OP_DUP);
		emitstring(J, F, OP_GETPROP_S, fun->b->string);
		emit(J, F, OP_ROT2);
		break;
	case EXP_IDENTIFIER:
		if (!strcmp(fun->string, "eval")) {
			ceval(J, F, fun, args);
			return;
		}
		/* fall through */
	default:
		cexp(J, F, fun);
		emit(J, F, J->strict ? OP_UNDEF : OP_GLOBAL);
		break;
	}
	n = cargs(J, F, args);
	emit(J, F, OP_CALL);
	emitraw(J, F, n);
}
示例#2
0
	projUV /* bivariate Chebyshev polynomial entry point */
bcheval(projUV in, Tseries *T) {
	projUV out;
		/* scale to +-1 */
 	w.u = ( in.u + in.u - T->a.u ) * T->b.u;
 	w.v = ( in.v + in.v - T->a.v ) * T->b.v;
	if (fabs(w.u) > NEAR_ONE || fabs(w.v) > NEAR_ONE) {
		out.u = out.v = HUGE_VAL;
		pj_errno = -36;
	} else { /* double evaluation */
		w2.u = w.u + w.u;
		w2.v = w.v + w.v;
		out.u = ceval(T->cu, T->mu);
		out.v = ceval(T->cv, T->mv);
	}
	return out;
}
示例#3
0
Cell* eval(Cell* const c)
{
	initialize(c);
	if (c == nil)
		throw RuntimeError("Empty list\n     : At Cell* eval()");
	string s;
	if (!listp(c) && symbolp(c) && fstack.empty())
		throw RuntimeError("Attempt to reference an unbound variable \"" + get_symbol(c) + "\"" + "\n     : At Cell* eval()");
	else if (!listp(c) && !fstack.empty() && symbolp(c)) {
		s = get_symbol(c);
		CellMap::iterator find_key;
		if (fstack.size() > 1) {
			find_key = fstack[1].find(s);
			if (find_key != fstack[1].end())
				return ceval(find_key->second);
		}
		find_key = fstack[0].find(s);
		if (find_key == fstack[0].end())
			throw RuntimeError("Attempt to reference an unbound variable \"" + s + "\"" + "\n     : At Cell* eval()");
		return ceval(find_key->second);
	}
	if (!listp(c) && !symbolp(c))
		return c;
	else if (listp(c) && !symbolp(car(c)) && !listp(car(c)))
		throw RuntimeError("Invalid operator\n     : At Cell* eval()");
	else if (listp(car(c))) {
		if (nullp(car(c)))
			throw RuntimeError("Cannot evaluate a null expression\n     : At Cell* eval()");
		return ceval(c); // pass it to ceval if it's a double list
	}
	s = get_symbol(car(c));
	vector<string>::iterator find_op = locate(op.begin(), op.end(), s);
	if (find_op != op.end())
		return ceval(c);
	else if (fstack.size() > 1) {
		CellMap::iterator find_key = fstack[1].find(s);
		if (find_key != fstack[1].end())
			return ceval(c);// return apply(ceval(find_key->second), cdr(c));
	}
	throw RuntimeError("Invalid operator \"" + s + "\"\n     : At Cell* eval()");
}