Script.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #include <stdarg.h>
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "Operation.h"
  7. #include "Script.h"
  8. static void sError(Script* sc, const char* format, ...) {
  9. va_list args;
  10. va_start(args, format);
  11. vsnprintf(sc->error, SCRIPT_ERROR_SIZE, format, args);
  12. va_end(args);
  13. }
  14. static bool sPrinter(Object* o) {
  15. switch(o->type) {
  16. case OT_INT: printf("%d\n", o->data.intValue); return false;
  17. case OT_FLOAT: printf("%.2f\n", o->data.floatValue); return false;
  18. case OT_NULL: printf("null\n"); return false;
  19. case OT_BOOL: printf(o->data.intValue ? "true\n" : "false\n"); return false;
  20. case OT_VOID: printf("void\n"); return false;
  21. }
  22. return true;
  23. }
  24. static ObjectPrinter printer = sPrinter;
  25. static bool sRead(Script* sc, void* buffer, int length) {
  26. if(sc->readIndex + length > sc->code->length) {
  27. sError(sc, "cannot read expected %d bytes of data from bytecode on line %d", sc->line);
  28. return true;
  29. }
  30. memcpy(buffer, sc->code->code + sc->readIndex, length);
  31. sc->readIndex += length;
  32. return false;
  33. }
  34. static Operation sReadOperation(Script* sc) {
  35. unsigned char c;
  36. if(sRead(sc, &c, 1)) {
  37. return OP_NOTHING;
  38. }
  39. return c;
  40. }
  41. static bool sReadInt(Script* sc, int* i) {
  42. return !sRead(sc, i, sizeof(int));
  43. }
  44. static bool sCheckType(Script* sc, Object* o, ObjectType ot) {
  45. if(o->type == ot) {
  46. return true;
  47. }
  48. sError(sc, "object is not of type %s on line %d", oGetName(ot), sc->line);
  49. return false;
  50. }
  51. static bool sPush(Script* sc, Object* o) {
  52. if(sc->stackIndex >= SCRIPT_STACK_SIZE) {
  53. sError(sc, "stack overflow on line %d", sc->line);
  54. return false;
  55. }
  56. sc->stack[sc->stackIndex++] = *o;
  57. return true;
  58. }
  59. static bool sPop(Script* sc, Object* o) {
  60. if(sc->stackIndex <= 0) {
  61. sError(sc, "stack underflow on line %d", sc->line);
  62. return true;
  63. }
  64. *o = sc->stack[--sc->stackIndex];
  65. return false;
  66. }
  67. static void sPopEmpty(Script* sc) {
  68. Object o;
  69. sPop(sc, &o);
  70. }
  71. static Object* sPeek(Script* sc) {
  72. if(sc->stackIndex <= 0) {
  73. sError(sc, "stack underflow on line %d", sc->line);
  74. return NULL;
  75. }
  76. return sc->stack + (sc->stackIndex - 1);
  77. }
  78. static bool sPushInt(Script* sc, int value) {
  79. Object o = {.type = OT_INT, .data.intValue = value};
  80. return sPush(sc, &o);
  81. }
  82. static void sPushFloat(Script* sc, float value) {
  83. Object o = {.type = OT_FLOAT, .data.floatValue = value};
  84. sPush(sc, &o);
  85. }
  86. static void sPushNull(Script* sc) {
  87. Object o = {.type = OT_NULL};
  88. sPush(sc, &o);
  89. }
  90. static void sPushBool(Script* sc, bool value) {
  91. Object o = {.type = OT_BOOL, .data.intValue = value};
  92. sPush(sc, &o);
  93. }
  94. static void sPushVars(Script* sc) {
  95. int vars = 0;
  96. int offset = 0;
  97. if(sReadInt(sc, &vars) && sReadInt(sc, &offset)) {
  98. int stackVarIndex = sc->stackVarIndex;
  99. sc->stackVarIndex = sc->stackIndex - offset;
  100. for(int i = 0; i < vars - offset; i++) {
  101. sPushNull(sc);
  102. }
  103. sPushInt(sc, stackVarIndex);
  104. }
  105. }
  106. static void sPopVars(Script* sc) {
  107. int value = 0;
  108. Object o;
  109. if(sReadInt(sc, &value) && !sPop(sc, &o) && sCheckType(sc, &o, OT_INT)) {
  110. sc->stackVarIndex = o.data.intValue;
  111. if(sc->stackIndex < value) {
  112. sError(sc, "stack underflow on line %d", sc->line);
  113. } else {
  114. sc->stackIndex -= value;
  115. }
  116. }
  117. }
  118. static void sSet(Script* sc) {
  119. int value = 0;
  120. if(sReadInt(sc, &value)) {
  121. sPop(sc, sc->stack + value + sc->stackVarIndex);
  122. }
  123. }
  124. static void sGet(Script* sc) {
  125. int value = 0;
  126. if(sReadInt(sc, &value)) {
  127. sPush(sc, sc->stack + value + sc->stackVarIndex);
  128. }
  129. }
  130. static void sPreIncrement(Script* sc) {
  131. int value = 0;
  132. if(sReadInt(sc, &value)) {
  133. Object* o = sc->stack + value + sc->stackVarIndex;
  134. if(o->type == OT_INT) {
  135. o->data.intValue++;
  136. } else if(o->type == OT_FLOAT) {
  137. o->data.floatValue++;
  138. } else {
  139. sError(sc, "variable is not a number on line %d", sc->line);
  140. return;
  141. }
  142. sPush(sc, o);
  143. }
  144. }
  145. static void sPostIncrement(Script* sc) {
  146. int value = 0;
  147. if(sReadInt(sc, &value)) {
  148. Object* o = sc->stack + value + sc->stackVarIndex;
  149. if(o->type == OT_INT) {
  150. sPush(sc, o);
  151. o->data.intValue++;
  152. } else if(o->type == OT_FLOAT) {
  153. sPush(sc, o);
  154. o->data.floatValue++;
  155. } else {
  156. sError(sc, "variable is not a number on line %d", sc->line);
  157. }
  158. }
  159. }
  160. static void sPreDecrement(Script* sc) {
  161. int value = 0;
  162. if(sReadInt(sc, &value)) {
  163. Object* o = sc->stack + value + sc->stackVarIndex;
  164. if(o->type == OT_INT) {
  165. o->data.intValue--;
  166. } else if(o->type == OT_FLOAT) {
  167. o->data.floatValue--;
  168. } else {
  169. sError(sc, "variable is not a number on line %d", sc->line);
  170. return;
  171. }
  172. sPush(sc, o);
  173. }
  174. }
  175. static void sPostDecrement(Script* sc) {
  176. int value = 0;
  177. if(sReadInt(sc, &value)) {
  178. Object* o = sc->stack + value + sc->stackVarIndex;
  179. if(o->type == OT_INT) {
  180. sPush(sc, o);
  181. o->data.intValue--;
  182. } else if(o->type == OT_FLOAT) {
  183. sPush(sc, o);
  184. o->data.floatValue--;
  185. } else {
  186. sError(sc, "variable is not a number on line %d", sc->line);
  187. }
  188. }
  189. }
  190. static void sPushCodeInt(Script* sc) {
  191. int value = 0;
  192. if(sReadInt(sc, &value)) {
  193. sPushInt(sc, value);
  194. }
  195. }
  196. static void sPushCodeFloat(Script* sc) {
  197. float value = 0;
  198. if(sRead(sc, &value, sizeof(float))) {
  199. sError(sc, "cannot read a float from the bytecode on line %d", sc->line);
  200. return;
  201. }
  202. sPushFloat(sc, value);
  203. }
  204. static void sNumberBinary(Script* sc, int (*fInt)(Script*, int, int), float (*fFloat)(float, float)) {
  205. Object o[2];
  206. if(sPop(sc, o) || sPop(sc, o + 1)) {
  207. return;
  208. } else if(o[0].type == OT_INT && o[1].type == OT_INT) {
  209. sPushInt(sc, fInt(sc, o[0].data.intValue, o[1].data.intValue));
  210. } else if(o[0].type == OT_FLOAT && o[1].type == OT_INT) {
  211. sPushFloat(sc, fFloat(o[0].data.floatValue, o[1].data.intValue));
  212. } else if(o[0].type == OT_INT && o[1].type == OT_FLOAT) {
  213. sPushFloat(sc, fFloat(o[0].data.intValue, o[1].data.floatValue));
  214. } else if(o[0].type == OT_FLOAT && o[1].type == OT_FLOAT) {
  215. sPushFloat(sc, fFloat(o[0].data.floatValue, o[1].data.floatValue));
  216. } else {
  217. sError(sc, "object is not a number on line %d", sc->line);
  218. }
  219. }
  220. static void sIntBinary(Script* sc, int (*f)(Script*, int, int)) {
  221. Object o[2];
  222. if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_INT) && sCheckType(sc, o + 1, OT_INT)) {
  223. sPushInt(sc, f(sc, o[0].data.intValue, o[1].data.intValue));
  224. }
  225. }
  226. static int sIntAdd(Script* sc, int a, int b) {
  227. (void)sc;
  228. return a + b;
  229. }
  230. static int sIntSub(Script* sc, int a, int b) {
  231. (void)sc;
  232. return b - a;
  233. }
  234. static int sIntMul(Script* sc, int a, int b) {
  235. (void)sc;
  236. return a * b;
  237. }
  238. static int sIntDiv(Script* sc, int a, int b) {
  239. if(a == 0) {
  240. sError(sc, "division by 0 on line %d", sc->line);
  241. return b;
  242. }
  243. return b / a;
  244. }
  245. static int sMod(Script* sc, int a, int b) {
  246. if(a == 0) {
  247. sError(sc, "module of 0 on line %d", sc->line);
  248. return b;
  249. }
  250. return b % a;
  251. }
  252. static float sFloatAdd(float a, float b) {
  253. return a + b;
  254. }
  255. static float sFloatSub(float a, float b) {
  256. return b - a;
  257. }
  258. static float sFloatMul(float a, float b) {
  259. return a * b;
  260. }
  261. static float sFloatDiv(float a, float b) {
  262. return b / a;
  263. }
  264. static void sBoolBinary(Script* sc, bool (*fInt)(int, int), bool (*fFloat)(float, float)) {
  265. Object o[2];
  266. if(sPop(sc, o) || sPop(sc, o + 1)) {
  267. return;
  268. } else if(o[0].type == OT_INT && o[1].type == OT_INT) {
  269. sPushBool(sc, fInt(o[0].data.intValue, o[1].data.intValue));
  270. } else if(o[0].type == OT_FLOAT && o[1].type == OT_INT) {
  271. sPushBool(sc, fFloat(o[0].data.floatValue, o[1].data.intValue));
  272. } else if(o[0].type == OT_INT && o[1].type == OT_FLOAT) {
  273. sPushBool(sc, fFloat(o[0].data.intValue, o[1].data.floatValue));
  274. } else if(o[0].type == OT_FLOAT && o[1].type == OT_FLOAT) {
  275. sPushBool(sc, fFloat(o[0].data.floatValue, o[1].data.floatValue));
  276. } else {
  277. sError(sc, "object is not a number on line %d", sc->line);
  278. }
  279. }
  280. static bool sIntLess(int a, int b) {
  281. return b < a;
  282. }
  283. static bool sIntGreater(int a, int b) {
  284. return b > a;
  285. }
  286. static bool sFloatLess(float a, float b) {
  287. return b < a;
  288. }
  289. static bool sFloatGreater(float a, float b) {
  290. return b > a;
  291. }
  292. static void sInvertSign(Script* sc) {
  293. Object* o = sPeek(sc);
  294. if(o == NULL) {
  295. return;
  296. } else if(o->type == OT_INT) {
  297. o->data.intValue = -o->data.intValue;
  298. } else if(o->type == OT_FLOAT) {
  299. o->data.floatValue = -o->data.floatValue;
  300. } else {
  301. sError(sc, "object is not a number on line %d", sc->line);
  302. }
  303. }
  304. static void sEqual(Script* sc) {
  305. Object o[2];
  306. if(sPop(sc, o) || sPop(sc, o + 1)) {
  307. return;
  308. } else if(o[0].type == OT_INT && o[1].type == OT_INT) {
  309. sPushBool(sc, o[0].data.intValue == o[1].data.intValue);
  310. } else if(o[0].type == OT_INT && o[1].type == OT_FLOAT) {
  311. sPushBool(sc, o[0].data.intValue == o[1].data.floatValue);
  312. } else if(o[0].type == OT_FLOAT && o[1].type == OT_INT) {
  313. sPushBool(sc, o[0].data.floatValue == o[1].data.intValue);
  314. } else if(o[0].type == OT_FLOAT && o[1].type == OT_FLOAT) {
  315. sPushBool(sc, o[0].data.floatValue == o[1].data.floatValue);
  316. } else if(o[0].type == OT_BOOL && o[1].type == OT_BOOL) {
  317. sPushBool(sc, o[0].data.intValue == o[1].data.intValue);
  318. } else if(o[0].type == OT_NULL && o[1].type == OT_NULL) {
  319. sPushBool(sc, true);
  320. } else {
  321. sError(sc, "object types do not match on line %d", sc->line);
  322. }
  323. }
  324. static void sNot(Script* sc) {
  325. Object* o = sPeek(sc);
  326. if(o != NULL && sCheckType(sc, o, OT_BOOL)) {
  327. o->data.intValue = !o->data.intValue;
  328. }
  329. }
  330. static void sAnd(Script* sc) {
  331. Object o[2];
  332. if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_BOOL) && sCheckType(sc, o + 1, OT_BOOL)) {
  333. sPushBool(sc, o[0].data.intValue && o[1].data.intValue);
  334. }
  335. }
  336. static void sOr(Script* sc) {
  337. Object o[2];
  338. if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_BOOL) && sCheckType(sc, o + 1, OT_BOOL)) {
  339. sPushBool(sc, o[0].data.intValue || o[1].data.intValue);
  340. }
  341. }
  342. static void sPrint(Script* sc) {
  343. Object o;
  344. if(!sPop(sc, &o) && printer(&o)) {
  345. sError(sc, "cannot print given object on line %d", sc->line);
  346. }
  347. }
  348. static void sLine(Script* sc) {
  349. if(sRead(sc, &sc->line, 2)) {
  350. sError(sc, "line operation without a line near line %d", sc->line);
  351. }
  352. }
  353. static void sGoTo(Script* sc) {
  354. int gotoIndex;
  355. if(sReadInt(sc, &gotoIndex)) {
  356. sc->readIndex = gotoIndex;
  357. }
  358. }
  359. static void sGoSub(Script* sc) {
  360. int gotoIndex;
  361. int arguments;
  362. if(sReadInt(sc, &gotoIndex) && sReadInt(sc, &arguments)) {
  363. int returnStackIndex = sc->stackIndex - arguments - 1;
  364. if(returnStackIndex < 0 || sc->stack[returnStackIndex].type != OT_INT) {
  365. sError(sc, "cannot find return address entry on stack on line %d", sc->line);
  366. return;
  367. }
  368. sc->stack[returnStackIndex].data.intValue = sc->readIndex;
  369. sc->readIndex = gotoIndex;
  370. }
  371. }
  372. static void sIfGoTo(Script* sc) {
  373. int gotoIndex;
  374. Object o;
  375. if(sReadInt(sc, &gotoIndex) && !sPop(sc, &o) && sCheckType(sc, &o, OT_BOOL) && !o.data.intValue) {
  376. sc->readIndex = gotoIndex;
  377. }
  378. }
  379. static void sSetReturn(Script* sc) {
  380. sPop(sc, &sc->returnValue);
  381. }
  382. static void sReturn(Script* sc) {
  383. Object o;
  384. if(!sPop(sc, &o) && sCheckType(sc, &o, OT_INT)) {
  385. sc->readIndex = o.data.intValue;
  386. if(sc->returnValue.type != OT_VOID) {
  387. sPush(sc, &sc->returnValue);
  388. sc->returnValue.type = OT_VOID;
  389. }
  390. }
  391. }
  392. static void sDuplicate(Script* sc) {
  393. Object* o = sPeek(sc);
  394. if(o != NULL) {
  395. sPush(sc, o);
  396. }
  397. }
  398. static void sConsumeInstruction(Script* sc) {
  399. switch(sReadOperation(sc)) {
  400. case OP_NOTHING: break;
  401. case OP_PUSH_INT: sPushCodeInt(sc); break;
  402. case OP_PUSH_FLOAT: sPushCodeFloat(sc); break;
  403. case OP_PUSH_NULL: sPushNull(sc); break;
  404. case OP_PUSH_TRUE: sPushBool(sc, true); break;
  405. case OP_PUSH_FALSE: sPushBool(sc, false); break;
  406. case OP_PUSH_VARS: sPushVars(sc); break;
  407. case OP_POP_VARS: sPopVars(sc); break;
  408. case OP_POP: sPopEmpty(sc); break;
  409. case OP_SET: sSet(sc); break;
  410. case OP_GET: sGet(sc); break;
  411. case OP_PRE_INCREMENT: sPreIncrement(sc); break;
  412. case OP_POST_INCREMENT: sPostIncrement(sc); break;
  413. case OP_PRE_DECREMENT: sPreDecrement(sc); break;
  414. case OP_POST_DECREMENT: sPostDecrement(sc); break;
  415. case OP_ADD: sNumberBinary(sc, sIntAdd, sFloatAdd); break;
  416. case OP_SUB: sNumberBinary(sc, sIntSub, sFloatSub); break;
  417. case OP_MUL: sNumberBinary(sc, sIntMul, sFloatMul); break;
  418. case OP_DIV: sNumberBinary(sc, sIntDiv, sFloatDiv); break;
  419. case OP_MOD: sIntBinary(sc, sMod); break;
  420. case OP_INVERT_SIGN: sInvertSign(sc); break;
  421. case OP_LESS: sBoolBinary(sc, sIntLess, sFloatLess); break;
  422. case OP_GREATER: sBoolBinary(sc, sIntGreater, sFloatGreater); break;
  423. case OP_EQUAL: sEqual(sc); break;
  424. case OP_NOT: sNot(sc); break;
  425. case OP_AND: sAnd(sc); break;
  426. case OP_OR: sOr(sc); break;
  427. case OP_PRINT: sPrint(sc); break;
  428. case OP_LINE: sLine(sc); break;
  429. case OP_GOTO: sGoTo(sc); break;
  430. case OP_GOSUB: sGoSub(sc); break;
  431. case OP_IF_GOTO: sIfGoTo(sc); break;
  432. case OP_SET_RETURN: sSetReturn(sc); break;
  433. case OP_RETURN: sReturn(sc); break;
  434. case OP_DUPLICATE: sDuplicate(sc); break;
  435. }
  436. }
  437. static bool sHasData(Script* sc) {
  438. return sc->readIndex < sc->code->length;
  439. }
  440. Script* sInit(ByteCode* code) {
  441. Script* sc = malloc(sizeof(Script));
  442. sc->error[0] = '\0';
  443. sc->code = code;
  444. sc->readIndex = 0;
  445. sc->returnValue.type = OT_VOID;
  446. sc->stackIndex = 0;
  447. sc->stackVarIndex = 0;
  448. sc->line = 0;
  449. return sc;
  450. }
  451. void sDelete(Script* sc) {
  452. bcDelete(sc->code);
  453. free(sc);
  454. }
  455. void sRun(Script* sc) {
  456. while(sHasData(sc)) {
  457. sConsumeInstruction(sc);
  458. if(sc->error[0] != '\0') {
  459. puts(sc->error);
  460. return;
  461. }
  462. }
  463. }
  464. void sSetPrinter(ObjectPrinter p) {
  465. printer = p;
  466. }
  467. static void sPrintInt(Script* sc, const char* msg) {
  468. int value = 0;
  469. sReadInt(sc, &value);
  470. printf("%s %d\n", msg, value);
  471. }
  472. static void sPrint2Int(Script* sc, const char* msg) {
  473. int a = 0;
  474. sReadInt(sc, &a);
  475. int b = 0;
  476. sReadInt(sc, &b);
  477. printf("%s %d %d\n", msg, a, b);
  478. }
  479. static void sPrintInt16(Script* sc, const char* msg) {
  480. int value = 0;
  481. sRead(sc, &value, 2);
  482. printf("%s %d\n", msg, value);
  483. }
  484. static void sPrintFloat(Script* sc, const char* msg) {
  485. float value = 0;
  486. sRead(sc, &value, sizeof(float));
  487. printf("%s %.2f\n", msg, value);
  488. }
  489. void sPrintCode(Script* sc) {
  490. int oldRead = sc->readIndex;
  491. sc->readIndex = 0;
  492. while(sHasData(sc)) {
  493. printf(" %3d | ", sc->readIndex);
  494. switch(sReadOperation(sc)) {
  495. case OP_NOTHING: puts("Nothing"); break;
  496. case OP_PUSH_INT: sPrintInt(sc, "Push Int"); break;
  497. case OP_PUSH_FLOAT: sPrintFloat(sc, "Push Float"); break;
  498. case OP_PUSH_NULL: puts("Push null"); break;
  499. case OP_PUSH_TRUE: puts("Push true"); break;
  500. case OP_PUSH_FALSE: puts("Push false"); break;
  501. case OP_PUSH_VARS: sPrint2Int(sc, "Push Vars"); break;
  502. case OP_POP_VARS: sPrintInt(sc, "Pop Vars"); break;
  503. case OP_POP: puts("Pop"); break;
  504. case OP_SET: sPrintInt(sc, "Set"); break;
  505. case OP_GET: sPrintInt(sc, "Get"); break;
  506. case OP_PRE_INCREMENT: sPrintInt(sc, "Pre Increment"); break;
  507. case OP_POST_INCREMENT: sPrintInt(sc, "Post Increment"); break;
  508. case OP_PRE_DECREMENT: sPrintInt(sc, "Pre Decrement"); break;
  509. case OP_POST_DECREMENT: sPrintInt(sc, "Post Decrement"); break;
  510. case OP_ADD: puts("Add"); break;
  511. case OP_SUB: puts("Sub"); break;
  512. case OP_MUL: puts("Mul"); break;
  513. case OP_DIV: puts("Div"); break;
  514. case OP_MOD: puts("Mod"); break;
  515. case OP_INVERT_SIGN: puts("Invert Sign"); break;
  516. case OP_LESS: puts("Less"); break;
  517. case OP_GREATER: puts("Greater"); break;
  518. case OP_EQUAL: puts("Equal"); break;
  519. case OP_NOT: puts("Not"); break;
  520. case OP_AND: puts("And"); break;
  521. case OP_OR: puts("And"); break;
  522. case OP_PRINT: puts("Print"); break;
  523. case OP_LINE: sPrintInt16(sc, "------------ Line"); break;
  524. case OP_GOTO: sPrintInt(sc, "GoTo"); break;
  525. case OP_GOSUB: sPrint2Int(sc, "GoSub"); break;
  526. case OP_IF_GOTO: sPrintInt(sc, "If GoTo"); break;
  527. case OP_SET_RETURN: puts("Set Return"); break;
  528. case OP_RETURN: puts("Return"); break;
  529. case OP_DUPLICATE: puts("Duplicate"); break;
  530. }
  531. }
  532. sc->readIndex = oldRead;
  533. }