Exemplo n.º 1
0
void
stack_dup(struct stack *stack)
{
	struct value	*value;
	struct value	copy;

	value = stack_tos(stack);
	if (value == NULL) {
		warnx("stack empty");
		return;
	}
	stack_push(stack, stack_dup_value(value, &copy));
}
Exemplo n.º 2
0
void parser_skipws(register Parser *pp)
{
    register StackValue stValue;
                                        /* set up handler set to use        */
    stValue.u_Pfun1p = pp->d_handler;
    stack_push(&pp->d_handler_st, stValue);
    pp->d_handler = ps_handlerSet[SKIPWS_SET];

    p_parse(pp);
                                            /* restore the handler set      */
    pp->d_handler = stack_tos(&pp->d_handler_st)->u_Pfun1p;
    stack_pop(&pp->d_handler_st);
}
Exemplo n.º 3
0
static void
compare(enum bcode_compare type)
{
	int		index, elseindex;
	struct number	*a, *b;
	bool		ok;
	struct value	*v;

	elseindex = NO_ELSE;
	index = readreg();
	if (readch() == 'e')
		elseindex = readreg();
	else
		unreadch();

	a = pop_number();
	if (a == NULL)
		return;
	b = pop_number();
	if (b == NULL) {
		push_number(a);
		return;
	}

	ok = compare_numbers(type, a, b);

	if (!ok && elseindex != NO_ELSE)
		index = elseindex;

	if (index >= 0 && (ok || (!ok && elseindex != NO_ELSE))) {
		v = stack_tos(&bmachine.reg[index]);
		if (v == NULL)
			warnx("register '%c' (0%o) is empty", index, index);
		else {
			switch(v->type) {
			case BCODE_NONE:
				warnx("register '%c' (0%o) is empty",
				    index, index);
				break;
			case BCODE_NUMBER:
				warn("eval called with non-string argument");
				break;
			case BCODE_STRING:
				eval_string(bstrdup(v->u.string));
				break;
			}
		}
	}
}
Exemplo n.º 4
0
static void
load(void)
{
	int		idx;
	struct value	*v, copy;
	struct number	*n;

	idx = readreg();
	if (idx >= 0) {
		v = stack_tos(&bmachine.reg[idx]);
		if (v == NULL) {
			n = new_number();
			bn_check(BN_zero(n->number));
			push_number(n);
		} else
			push(stack_dup_value(v, &copy));
	}
}
Exemplo n.º 5
0
static __inline struct value *
tos(void)
{

	return (stack_tos(&bmachine.stack));
}