Exemplo n.º 1
0
void Parse::printExpr(char stopToken) {
	// Expression printing disabled by default
	return;

	char* savedPos = _vm->_global->_inter_execPtr;
	printExpr_internal(stopToken);

	// restore IP to start of expression
	_vm->_global->_inter_execPtr = savedPos;
}
Exemplo n.º 2
0
void Expression::printExpr(char stopToken) {
	// Expression printing disabled by default
#if 0

	int32 savedPos = _vm->_game->_script->pos();
	printExpr_internal(stopToken);

	// restore IP to start of expression
	_vm->_game->_script->seek(savedPos);
#endif
}
Exemplo n.º 3
0
void Parse::printExpr_internal(char stopToken) {
	int16 dimCount;
	char operation;
	int16 num;
	int16 dim;
	char *arrDesc;
	char func;

	num = 0;
	while (1) {
		operation = *_vm->_global->_inter_execPtr++;

		if (operation >= 16 && operation <= 29) {
			// operands

			switch (operation) {
			case 17: // uint16 variable load
				debugN(5, "var16_%d", _vm->_inter->load16());
				break;

			case 18: // uint8 variable load:
				debugN(5, "var8_%d", _vm->_inter->load16());
				break;

			case 19: // uint32 immediate
				debugN(5, "%d", READ_LE_UINT32(_vm->_global->_inter_execPtr));
				_vm->_global->_inter_execPtr += 4;
				break;

			case 20: // uint16 immediate
				debugN(5, "%d", _vm->_inter->load16());
				break;

			case 21: // uint8 immediate
				debugN(5, "%d",  *_vm->_global->_inter_execPtr++);
				break;

			case 22: // string immediate
				debugN(5, "\42%s\42", _vm->_global->_inter_execPtr);
				_vm->_global->_inter_execPtr += strlen(_vm->_global->_inter_execPtr) + 1;
				break;

			case 23: // uint32 variable load
			case 24: // uint32 variable load as uint16
				debugN(5, "var_%d", _vm->_inter->load16());
				break;

			case 25: // string variable load
				debugN(5, "(&var_%d)", _vm->_inter->load16());
				if (*_vm->_global->_inter_execPtr == 13) {
					_vm->_global->_inter_execPtr++;
					debugN(5, "{");
					printExpr_internal(12); // this also prints the closing }
				}
				break;

			case 16: // uint8 array access
			case 26: // uint32 array access
			case 27: // uint16 array access
			case 28: // string array access
				debugN(5, "\n");
				if (operation == 28)
					debugN(5, "(&");

				debugN(5, "var_%d[", _vm->_inter->load16());
				dimCount = *_vm->_global->_inter_execPtr++;
				arrDesc = _vm->_global->_inter_execPtr;
				_vm->_global->_inter_execPtr += dimCount;
				for (dim = 0; dim < dimCount; dim++) {
					printExpr_internal(12);
					debugN(5, " of %d", (int16)arrDesc[dim]);
					if (dim != dimCount - 1)
						debugN(5, ",");
				}
				debugN(5, "]");
				if (operation == 28)
					debugN(5, ")");

				if (operation == 28 && *_vm->_global->_inter_execPtr == 13) {
					_vm->_global->_inter_execPtr++;
					debugN(5, "{");
					printExpr_internal(12); // this also prints the closing }
				}
				break;

			case 29: // function
				func = *_vm->_global->_inter_execPtr++;
				if (func == 5)
					debugN(5, "sqr(");
				else if (func == 10)
					debugN(5, "rand(");
				else if (func == 7)
					debugN(5, "abs(");
				else if (func == 0 || func == 1 || func == 6)
					debugN(5, "sqrt(");
				else
					debugN(5, "id(");
				printExpr_internal(10);
				break;
			}
			continue;
		}		// if (operation >= 16 && operation <= 29)

		// operators
		switch (operation) {
		case 9:
			debugN(5, "(");
			break;

		case 11:
			debugN(5, "!");
			break;

		case 10:
			debugN(5, ")");
			break;

		case 1:
			debugN(5, "-");
			break;

		case 2:
			debugN(5, "+");
			break;

		case 3:
			debugN(5, "-");
			break;

		case 4:
			debugN(5, "|");
			break;

		case 5:
			debugN(5, "*");
			break;

		case 6:
			debugN(5, "/");
			break;

		case 7:
			debugN(5, "%%");
			break;

		case 8:
			debugN(5, "&");
			break;

		case 30:
			debugN(5, "||");
			break;

		case 31:
			debugN(5, "&&");
			break;

		case 32:
			debugN(5, "<");
			break;

		case 33:
			debugN(5, "<=");
			break;

		case 34:
			debugN(5, ">");
			break;

		case 35:
			debugN(5, ">=");
			break;

		case 36:
			debugN(5, "==");
			break;

		case 37:
			debugN(5, "!=");
			break;

		case 99:
			debugN(5, "\n");
			break;

		case 12:
			debugN(5, "}");
			if (stopToken != 12) {
				debugN(5, "Closing paren without opening?");
			}
			break;

		default:
			debugN(5, "<%d>", (int16)operation);
			error("printExpr: invalid operator in expression");
			break;
		}

		if (operation == 9) {
			num++;
			continue;
		}

		if (operation == 11 || (operation >= 1 && operation <= 8))
			continue;

		if (operation >= 30 && operation <= 37)
			continue;

		if (operation == 10)
			num--;

		if (operation == stopToken) {
			if (stopToken != 10 || num < 0) {
				return;
			}
		}
	}
}
Exemplo n.º 4
0
void Expression::printExpr_internal(char stopToken) {
	int16 dimCount;
	byte operation;
	int16 num;
	int16 dim;
	byte *arrDesc;
	byte func;

	num = 0;
	while (true) {
		operation = _vm->_game->_script->readByte();

		if ((operation >= OP_ARRAY_INT8) && (operation <= OP_FUNC)) {
			// operands

			switch (operation) {
			case OP_LOAD_VAR_INT16: // int16 variable load
				debugN(5, "var16_%d", _vm->_game->_script->readUint16());
				break;

			case OP_LOAD_VAR_INT8: // int8 variable load:
				debugN(5, "var8_%d", _vm->_game->_script->readUint16());
				break;

			case OP_LOAD_IMM_INT32: // int32/uint32 immediate
				debugN(5, "%d", _vm->_game->_script->readInt32());
				break;

			case OP_LOAD_IMM_INT16: // int16 immediate
				debugN(5, "%d", _vm->_game->_script->readInt16());
				break;

			case OP_LOAD_IMM_INT8: // int8 immediate
				debugN(5, "%d",  _vm->_game->_script->readInt8());
				break;

			case OP_LOAD_IMM_STR: // string immediate
				debugN(5, "\42%s\42", _vm->_game->_script->readString());
				break;

			case OP_LOAD_VAR_INT32:
			case OP_LOAD_VAR_INT32_AS_INT16:
				debugN(5, "var_%d", _vm->_game->_script->readUint16());
				break;

			case OP_LOAD_VAR_STR: // string variable load
				debugN(5, "(&var_%d)", _vm->_game->_script->readUint16());
				if (_vm->_game->_script->peekByte() == 13) {
					_vm->_game->_script->skip(1);
					debugN(5, "{");
					printExpr_internal(OP_END_MARKER); // this also prints the closing }
				}
				break;

			case OP_ARRAY_INT8:  // int8 array access
			case OP_ARRAY_INT32: // int32 array access
			case OP_ARRAY_INT16: // int16 array access
			case OP_ARRAY_STR:   // string array access
				debugN(5, "\n");
				if (operation == OP_ARRAY_STR)
					debugN(5, "(&");

				debugN(5, "var_%d[", _vm->_game->_script->readInt16());
				dimCount = _vm->_game->_script->readByte();
				arrDesc = _vm->_game->_script->getData() + _vm->_game->_script->pos();
				_vm->_game->_script->skip(dimCount);
				for (dim = 0; dim < dimCount; dim++) {
					printExpr_internal(OP_END_MARKER);
					debugN(5, " of %d", (int16) arrDesc[dim]);
					if (dim != dimCount - 1)
						debugN(5, ",");
				}
				debugN(5, "]");
				if (operation == OP_ARRAY_STR)
					debugN(5, ")");

				if ((operation == OP_ARRAY_STR) && (_vm->_game->_script->peekByte() == 13)) {
					_vm->_game->_script->skip(1);
					debugN(5, "{");
					printExpr_internal(OP_END_MARKER); // this also prints the closing }
				}
				break;

			case OP_FUNC: // function
				func = _vm->_game->_script->readByte();
				if (func == FUNC_SQR)
					debugN(5, "sqr(");
				else if (func == FUNC_RAND)
					debugN(5, "rand(");
				else if (func == FUNC_ABS)
					debugN(5, "abs(");
				else if ((func == FUNC_SQRT1) || (func == FUNC_SQRT2) || (func == FUNC_SQRT3))
					debugN(5, "sqrt(");
				else
					debugN(5, "id(");
				printExpr_internal(OP_END_EXPR);
				break;
			}
			continue;
		}		// if ((operation >= OP_ARRAY_INT8) && (operation <= OP_FUNC))

		// operators
		switch (operation) {
		case OP_BEGIN_EXPR:
			debugN(5, "(");
			break;

		case OP_NOT:
			debugN(5, "!");
			break;

		case OP_END_EXPR:
			debugN(5, ")");
			break;

		case OP_NEG:
			debugN(5, "-");
			break;

		case OP_ADD:
			debugN(5, "+");
			break;

		case OP_SUB:
			debugN(5, "-");
			break;

		case OP_BITOR:
			debugN(5, "|");
			break;

		case OP_MUL:
			debugN(5, "*");
			break;

		case OP_DIV:
			debugN(5, "/");
			break;

		case OP_MOD:
			debugN(5, "%%");
			break;

		case OP_BITAND:
			debugN(5, "&");
			break;

		case OP_OR:
			debugN(5, "||");
			break;

		case 31:
			debugN(5, "&&");
			break;

		case OP_LESS:
			debugN(5, "<");
			break;

		case OP_LEQ:
			debugN(5, "<=");
			break;

		case OP_GREATER:
			debugN(5, ">");
			break;

		case OP_GEQ:
			debugN(5, ">=");
			break;

		case OP_EQ:
			debugN(5, "==");
			break;

		case OP_NEQ:
			debugN(5, "!=");
			break;

		case 99:
			debugN(5, "\n");
			break;

		case OP_END_MARKER:
			debugN(5, "}");
			if (stopToken != OP_END_MARKER) {
				debugN(5, "Closing paren without opening?");
			}
			break;

		default:
			debugN(5, "<%d>", (int16) operation);
			error("Expression::printExpr(): invalid operator in expression");
			break;
		}

		if (operation == OP_BEGIN_EXPR) {
			num++;
			continue;
		}

		if ((operation == OP_NOT) || ((operation >= OP_NEG) && (operation <= 8)))
			continue;

		if ((operation >= OP_OR) && (operation <= OP_NEQ))
			continue;

		if (operation == OP_END_EXPR)
			num--;

		if (operation == stopToken) {
			if ((stopToken != OP_END_EXPR) || (num < 0)) {
				return;
			}
		}
	}
}