Exemplo n.º 1
0
/* single - handle a single action */
int single(void)
{
    /* execute the before code */
    switch (execute(h_before)) {
    case ABORT:	/* before handler aborted sequence */
	return (FALSE);
    case CHAIN:	/* execute the action handler */
	if (execute(getafield(getvalue(V_ACTION),A_CODE)) == ABORT)
	    return (FALSE);
    case FINISH:/* execute the after code */
	if (execute(h_after) == ABORT)
	    return (FALSE);
	break;
    }
    return (TRUE);
}
Exemplo n.º 2
0
/* hasverb - check to see if this action has this verb */
int hasverb(int act,int *verbs)
{
    int link,word,*verb;

    /* get the list of verbs */
    link = getafield(act,A_VERBS);

    /* look for this verb */
    while (link != NIL) {
	verb = verbs;
	word = getword(link+L_DATA);
	while (*verb != NIL && word != NIL) {
	    if (*verb != getword(word+L_DATA))
		break;
	    verb++;
	    word = getword(word+L_NEXT);
	}
	if (*verb == NIL && word == NIL)
	    return (TRUE);
	link = getword(link+L_NEXT);
    }
    return (FALSE);
}
Exemplo n.º 3
0
/* exe_one - execute one instruction */
void exe_one(void)
{
    /* get the opcode */
    opcode = getcbyte(pc); pc++;

    /* execute the instruction */
    switch (opcode) {
    case OP_CALL:
		*--sp = getboperand();
		*--sp = pc;
		*--sp = (int)(top - fp);
		fp = sp;
		pc = getafield(fp[fp[2]+3],A_CODE);
		break;
    case OP_SEND:
		*--sp = getboperand();
		*--sp = pc;
		*--sp = (int)(top - fp);
		fp = sp;
		if (p2 = fp[fp[2]+3])
		    p2 = getofield(p2,O_CLASS);
		else
		    p2 = fp[fp[2]+2];
		if (p2 && (p2 = getp(p2,fp[fp[2]+1]))) {
		    pc = getafield(p2,A_CODE);
		    break;
		}
		*sp = NIL;
		/* return NIL if there is no method for this message */
    case OP_RETURN:
		if (fp == top)
		    sts = CHAIN;
		else {
		    p2 = *sp;
		    sp = fp;
		    fp = top - *sp++;
		    pc = *sp++;
		    p3 = *sp++;
		    sp += p3;
		    *sp = p2;
		}
		break;
    case OP_TSPACE:
		sp -= getboperand();
		break;
    case OP_TMP:
		p2 = getboperand();
		*sp = fp[-p2-1];
		break;
    case OP_TSET:
		p2 = getboperand();
		fp[-p2-1] = *sp;
		break;
    case OP_ARG:
		p2 = getboperand();
		if (p2 >= fp[2])
		    error("too few arguments");
		*sp = fp[p2+3];
		break;
    case OP_ASET:
		p2 = getboperand();
		if (p2 >= fp[2])
		    error("too few arguments");
		fp[p2+3] = *sp;
		break;
    case OP_BRT:
		pc = (*sp ? getwoperand() : pc+2);
		break;
    case OP_BRF:
		pc = (*sp ? pc+2 : getwoperand());
		break;
    case OP_BR:
		pc = getwoperand();
		break;
    case OP_T:
		*sp = T;
		break;
    case OP_NIL:
		*sp = NIL;
		break;
    case OP_PUSH:
		*--sp = NIL;
		break;
    case OP_NOT:
		*sp = (*sp ? NIL : T);
		break;
    case OP_ADD:
		p2 = *sp++;
		*sp += p2;
		break;
    case OP_SUB:
		p2 = *sp++;
		*sp -= p2;
		break;
    case OP_MUL:
		p2 = *sp++;
		*sp *= p2;
		break;
    case OP_DIV:
		p2 = *sp++;
		*sp = (p2 == 0 ? 0 : *sp / p2);
		break;
    case OP_REM:
		p2 = *sp++;
		*sp = (p2 == 0 ? 0 : *sp % p2);
		break;
    case OP_BAND:
		p2 = *sp++;
		*sp &= p2;
		break;
    case OP_BOR:
		p2 = *sp++;
		*sp |= p2;
		break;
    case OP_BNOT:
		*sp = ~*sp;
		break;
    case OP_LT:
		p2 = *sp++;
		*sp = (*sp < p2 ? T : NIL);
		break;
    case OP_EQ:
		p2 = *sp++;
		*sp = (*sp == p2 ? T : NIL);
		break;
    case OP_GT:
		p2 = *sp++;
		*sp = (*sp > p2 ? T : NIL);
		break;
    case OP_LIT:
		*sp = getwoperand();
		break;
    case OP_SPLIT:
		*sp = getboperand();
		break;
    case OP_SNLIT:
		*sp = -getboperand();
		break;
    case OP_VAR:
		*sp = getvalue(getwoperand());
		break;
    case OP_SVAR:
		*sp = getvalue(getboperand());
		break;
    case OP_SET:
		setvalue(getwoperand(),*sp);
		break;
    case OP_SSET:
		setvalue(getboperand(),*sp);
		break;
    case OP_GETP:
		p2 = *sp++;
		*sp = getp(*sp,p2);
		break;
    case OP_SETP:
		p3 = *sp++;
		p2 = *sp++;
		*sp = setp(*sp,p2,p3);
		break;
    case OP_PRINT:
		print(*sp);
		break;
    case OP_PNUMBER:
    		pnumber(*sp);
    		break;
    case OP_PNOUN:
		show_noun(*sp);
		break;
    case OP_TERPRI:
		trm_chr('\n');
		break;
    case OP_FINISH:
		sts = FINISH;
		break;
    case OP_CHAIN:
		sts = CHAIN;
		break;
    case OP_ABORT:
		sts = ABORT;
		break;
    case OP_EXIT:
#ifdef MAC
		macpause();
#endif
		trm_done();
		exit();
		break;
    case OP_YORN:
		trm_get(line);
		*sp = (line[0] == 'Y' || line[0] == 'y' ? T : NIL);
    		break;
    case OP_CLASS:
		*sp = getofield(*sp,O_CLASS);
		break;
    case OP_MATCH:
		p2 = *sp++;
		*sp = (match(*sp,nouns[p2-1],adjectives[p2-1]) ? T : NIL);
		break;
    case OP_SAVE:
		*sp = db_save();
		break;
    case OP_RESTORE:
		*sp = db_restore();
		break;
    case OP_RESTART:
		*sp = db_restart();
		break;
    case OP_RAND:
		*sp = getrand(*sp);
		break;
    case OP_RNDMIZE:
		setrand(time(0L));
		*sp = NIL;
		break;
    default:
	    if (opcode >= OP_XVAR && opcode < OP_XSET)
		*sp = getvalue(opcode - OP_XVAR);
	    else if (opcode >= OP_XSET && opcode < OP_XPLIT)
		setvalue(opcode - OP_XSET,*sp);
	    else if (opcode >= OP_XPLIT && opcode < OP_XNLIT)
		*sp = opcode - OP_XPLIT;
	    else if (opcode >= OP_XNLIT && opcode < 256)
		*sp = OP_XNLIT - opcode;
	    else
		trm_str("Bad opcode\n");
	    break;
    }
}
Exemplo n.º 4
0
/* haspreposition - check to see if an action has a specified preposition */
int haspreposition(int act, int preposition)
{
    return (inlist(getafield(act,A_PREPOSITIONS),preposition));
}