Script.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. #include <stdarg.h>
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "utils/Functions.h"
  7. #include "vm/Operation.h"
  8. #include "vm/Script.h"
  9. void sError(Script* sc, const char* format, ...) {
  10. va_list args;
  11. va_start(args, format);
  12. vsnprintf(sc->error, SCRIPT_ERROR_SIZE, format, args);
  13. va_end(args);
  14. }
  15. static void sIntPrinter(int i) {
  16. printf("%d\n", i);
  17. }
  18. static void sLongPrinter(long l) {
  19. printf("%ld\n", l);
  20. }
  21. static void sFloatPrinter(float f) {
  22. printf("%.2f\n", f);
  23. }
  24. static void sBoolPrinter(bool b) {
  25. puts(b ? "true" : "false");
  26. }
  27. static void sPointerPrinter(Pointer* b) {
  28. printf("(%d, %d)\n", b->array, b->offset);
  29. }
  30. static IntPrinter intPrinter = sIntPrinter;
  31. static LongPrinter longPrinter = sLongPrinter;
  32. static FloatPrinter floatPrinter = sFloatPrinter;
  33. static BoolPrinter boolPrinter = sBoolPrinter;
  34. static PointerPrinter pointerPrinter = sPointerPrinter;
  35. static bool sRead(Script* sc, void* buffer, int length) {
  36. if(sc->readIndex + length > sc->code->length) {
  37. sError(sc, "cannot read expected %d bytes of data from bytecode");
  38. return false;
  39. }
  40. memcpy(buffer, sc->code->code + sc->readIndex, length);
  41. sc->readIndex += length;
  42. return true;
  43. }
  44. static Operation sReadOperation(Script* sc) {
  45. unsigned char c;
  46. if(sRead(sc, &c, 1)) {
  47. return c;
  48. }
  49. return OP_NOTHING;
  50. }
  51. static void* sReserve(Script* sc, int length) {
  52. if(sc->stackIndex + length > SCRIPT_STACK_SIZE) {
  53. sError(sc, "stack overflow");
  54. return NULL;
  55. }
  56. void* p = sc->stack + sc->stackIndex;
  57. sc->stackIndex += length;
  58. return p;
  59. }
  60. static bool sPush(Script* sc, const void* data, int length) {
  61. void* p = sReserve(sc, length);
  62. if(p != NULL) {
  63. memcpy(p, data, length);
  64. return true;
  65. }
  66. return false;
  67. }
  68. static const void* sFree(Script* sc, int length) {
  69. if(sc->stackIndex < length) {
  70. sError(sc, "stack underflow");
  71. return NULL;
  72. }
  73. sc->stackIndex -= length;
  74. return sc->stack + sc->stackIndex;
  75. }
  76. static bool sPop(Script* sc, void* data, int length) {
  77. const void* p = sFree(sc, length);
  78. if(p != NULL) {
  79. memcpy(data, p, length);
  80. return true;
  81. }
  82. return false;
  83. }
  84. static bool sPeek(Script* sc, void* data, int length) {
  85. if(sc->stackIndex < length) {
  86. sError(sc, "stack underflow");
  87. return false;
  88. }
  89. memcpy(data, sc->stack + (sc->stackIndex - length), length);
  90. return true;
  91. }
  92. #define POP_PUSH(type, Type) \
  93. bool sPop##Type(Script* sc, type* value) { \
  94. return sPop(sc, value, sizeof(type)); \
  95. } \
  96. bool sPush##Type(Script* sc, type value) { \
  97. return sPush(sc, &value, sizeof(type)); \
  98. }
  99. #define READ_POP_PUSH(type, Type) \
  100. static bool sRead##Type(Script* sc, type* i) { \
  101. return sRead(sc, i, sizeof(type)); \
  102. } \
  103. POP_PUSH(type, Type)
  104. #define PUSH_CONSTANT(type, Type) \
  105. { \
  106. type value; \
  107. if(sRead##Type(sc, &value)) { \
  108. sPush##Type(sc, value); \
  109. } \
  110. }
  111. #define ZERO_CHECK(name) \
  112. if(values[0] == 0) { \
  113. sError(sc, name " by 0"); \
  114. return; \
  115. }
  116. #define OP_BASE(type, Type, RType, op, check) \
  117. { \
  118. type values[2]; \
  119. if(sPop##Type(sc, values) && sPop##Type(sc, values + 1)) { \
  120. check; \
  121. sPush##RType(sc, values[1] op values[0]); \
  122. } \
  123. }
  124. #define CHECKED_NUMBER_OP(type, Type, op, check) \
  125. OP_BASE(type, Type, Type, op, check)
  126. #define NUMBER_OP(type, Type, op) CHECKED_NUMBER_OP(type, Type, op, )
  127. #define BOOL_OP(type, Type, op) OP_BASE(type, Type, Bool, op, )
  128. #define DIVISION(type, Type) \
  129. CHECKED_NUMBER_OP(type, Type, /, ZERO_CHECK("division"));
  130. #define MODULE(type, Type) \
  131. CHECKED_NUMBER_OP(type, Type, %, ZERO_CHECK("module"));
  132. READ_POP_PUSH(int, Int)
  133. READ_POP_PUSH(long, Long)
  134. READ_POP_PUSH(float, Float)
  135. POP_PUSH(bool, Bool)
  136. static bool sPopPointer(Script* sc, Pointer* value) {
  137. return sPop(sc, value, sizeof(Pointer));
  138. }
  139. static bool sPushPointer(Script* sc, Pointer* value) {
  140. return sPush(sc, value, sizeof(Pointer));
  141. }
  142. static void sPushNullPointer(Script* sc) {
  143. Pointer p = {-1, -1};
  144. sPushPointer(sc, &p);
  145. }
  146. static void sPrintPointer(Script* sc) {
  147. Pointer p;
  148. if(sPopPointer(sc, &p)) {
  149. pointerPrinter(&p);
  150. }
  151. }
  152. #define PRINT(type, Type, printer) \
  153. { \
  154. type value; \
  155. if(sPop##Type(sc, &value)) { \
  156. printer(value); \
  157. } \
  158. }
  159. #define INVERT_SIGN(type, Type) \
  160. { \
  161. type value = 0; \
  162. if(sPop##Type(sc, &value)) { \
  163. sPush##Type(sc, -value); \
  164. } \
  165. }
  166. static void sReserveBytes(Script* sc) {
  167. int bytes = 0;
  168. int offset = 0;
  169. if(sReadInt(sc, &bytes) && sReadInt(sc, &offset)) {
  170. int oldIndex = sc->stackVarIndex;
  171. sc->stackVarIndex = sc->stackIndex - offset;
  172. sReserve(sc, bytes - offset);
  173. sPushInt(sc, oldIndex);
  174. }
  175. }
  176. static void* sCheckAddress(Script* sc, Pointer* p, int length) {
  177. if(p->array >= 0) {
  178. Array* a = asGet(&sc->arrays, p->array);
  179. if(a == NULL) {
  180. sError(sc, "invalid heap pointer");
  181. return NULL;
  182. } else if(p->offset < 0 || p->offset >= a->size) {
  183. sError(sc, "address %d is out of array bounds", p->offset);
  184. return NULL;
  185. }
  186. return ((char*)a->data) + p->offset;
  187. }
  188. if(p->offset < 0 || p->offset + length > sc->stackIndex) {
  189. sError(sc, "address %d is out of stack bounds", p->offset);
  190. return NULL;
  191. }
  192. return sc->stack + p->offset;
  193. }
  194. static void sNot(Script* sc) {
  195. bool value = false;
  196. if(sPopBool(sc, &value)) {
  197. sPushBool(sc, !value);
  198. }
  199. }
  200. static void sBitNotInt(Script* sc) {
  201. int value = 0;
  202. if(sPopInt(sc, &value)) {
  203. sPushInt(sc, ~value);
  204. }
  205. }
  206. static void sBitNotLong(Script* sc) {
  207. long value = 0;
  208. if(sPopLong(sc, &value)) {
  209. sPushLong(sc, ~value);
  210. }
  211. }
  212. static void sLine(Script* sc) {
  213. sRead(sc, &sc->line, 2);
  214. }
  215. static void sGoTo(Script* sc) {
  216. int gotoIndex;
  217. if(sReadInt(sc, &gotoIndex)) {
  218. sc->readIndex = gotoIndex;
  219. }
  220. }
  221. static void sGoSub(Script* sc) {
  222. int gotoIndex;
  223. int offset;
  224. if(sReadInt(sc, &gotoIndex) && sReadInt(sc, &offset)) {
  225. Pointer p = {.array = -1,
  226. .offset = sc->stackIndex - offset - sizeof(int)};
  227. void* dest = sCheckAddress(sc, &p, sizeof(int));
  228. if(dest != NULL) {
  229. memcpy(dest, &sc->readIndex, sizeof(int));
  230. sc->readIndex = gotoIndex;
  231. }
  232. }
  233. }
  234. static void sReturn(Script* sc) {
  235. int bytes = 0;
  236. int varIndex = 0;
  237. if(sReadInt(sc, &bytes) && sPopInt(sc, &varIndex)) {
  238. sc->stackVarIndex = varIndex;
  239. sFree(sc, bytes);
  240. if(!sPopInt(sc, &sc->readIndex) || sc->readIndex < 0) {
  241. sError(sc, "read index is corrupt");
  242. }
  243. }
  244. }
  245. static void sReturnPointer(Script* sc) {
  246. Pointer p;
  247. if(sPopPointer(sc, &p)) {
  248. sReturn(sc);
  249. sPushPointer(sc, &p);
  250. }
  251. }
  252. #define RETURN(type, Type) \
  253. { \
  254. type value; \
  255. if(sPop##Type(sc, &value)) { \
  256. sReturn(sc); \
  257. sPush##Type(sc, value); \
  258. } \
  259. }
  260. static void sIfGoTo(Script* sc) {
  261. int gotoIndex = 0;
  262. bool value = false;
  263. if(sReadInt(sc, &gotoIndex) && sPopBool(sc, &value) && !value) {
  264. sc->readIndex = gotoIndex;
  265. }
  266. }
  267. static void sPeekFalseGoTo(Script* sc) {
  268. int gotoIndex = 0;
  269. bool value = false;
  270. if(sReadInt(sc, &gotoIndex) && sPeek(sc, &value, sizeof(bool)) && !value) {
  271. sc->readIndex = gotoIndex;
  272. }
  273. }
  274. static void sPeekTrueGoTo(Script* sc) {
  275. int gotoIndex = 0;
  276. bool value = false;
  277. if(sReadInt(sc, &gotoIndex) && sPeek(sc, &value, sizeof(bool)) && value) {
  278. sc->readIndex = gotoIndex;
  279. }
  280. }
  281. static void sNewArray(Script* sc) {
  282. int length = 0;
  283. int size = 0;
  284. if(sReadInt(sc, &size) && sPopInt(sc, &length)) {
  285. Pointer p = {.array = asAllocate(&sc->arrays, size, length),
  286. .offset = 0};
  287. if(p.array == -1) {
  288. sError(sc, "out of memory");
  289. } else if(p.array == -2) {
  290. sError(sc, "bad allocation");
  291. } else {
  292. sPushPointer(sc, &p);
  293. }
  294. }
  295. }
  296. static void sDeleteArray(Script* sc) {
  297. Pointer p;
  298. if(sPopPointer(sc, &p)) {
  299. if(p.offset != 0) {
  300. sError(sc, "delete of array with offset: %d", p.offset);
  301. return;
  302. }
  303. Array* a = asGet(&sc->arrays, p.array);
  304. if(a == NULL) {
  305. sError(sc, "delete of invalid array");
  306. return;
  307. }
  308. asDeleteArray(&sc->arrays, a, p.array);
  309. }
  310. }
  311. static void sLength(Script* sc) {
  312. Pointer p;
  313. if(sPopPointer(sc, &p)) {
  314. if(p.array == -1) {
  315. sPushInt(sc, p.offset >= 0);
  316. return;
  317. }
  318. Array* a = asGet(&sc->arrays, p.array);
  319. if(a == NULL) {
  320. sError(sc, "invalid heap pointer");
  321. return;
  322. }
  323. sPushInt(sc, a->length);
  324. }
  325. }
  326. static void sDereference(Script* sc) {
  327. int address = 0;
  328. if(sReadInt(sc, &address)) {
  329. Pointer p = {.array = -1, .offset = address + sc->stackVarIndex};
  330. sPushPointer(sc, &p);
  331. }
  332. }
  333. static void sLoad(Script* sc, int length) {
  334. Pointer p;
  335. if(sPopPointer(sc, &p)) {
  336. void* src = sCheckAddress(sc, &p, length);
  337. if(src != NULL) {
  338. sPush(sc, src, length);
  339. }
  340. }
  341. }
  342. static void sDuplicateReference(Script* sc) {
  343. Pointer p;
  344. if(sPeek(sc, &p, sizeof(Pointer))) {
  345. sPushPointer(sc, &p);
  346. }
  347. }
  348. static void sAddReference(Script* sc) {
  349. int size = 0;
  350. int add = 0;
  351. Pointer p;
  352. if(sReadInt(sc, &size) && sPopInt(sc, &add) && sPopPointer(sc, &p)) {
  353. p.offset += add * size;
  354. sPushPointer(sc, &p);
  355. }
  356. }
  357. static void sLoadSize(Script* sc) {
  358. int size = 0;
  359. Pointer p;
  360. if(sReadInt(sc, &size) && sPopPointer(sc, &p)) {
  361. void* src = sCheckAddress(sc, &p, size);
  362. if(src != NULL) {
  363. sPush(sc, src, size);
  364. }
  365. }
  366. }
  367. static void sStore(Script* sc, int length) {
  368. int index = sc->stackIndex - sizeof(Pointer) - length;
  369. if(index < 0) {
  370. sError(sc, "stack underflow");
  371. return;
  372. }
  373. Pointer p;
  374. memcpy(&p, sc->stack + index, sizeof(Pointer));
  375. void* dest = sCheckAddress(sc, &p, length);
  376. if(dest != NULL) {
  377. sPop(sc, dest, length);
  378. sc->stackIndex -= sizeof(Pointer);
  379. }
  380. }
  381. static void sEqualPointer(Script* sc) {
  382. Pointer a;
  383. Pointer b;
  384. if(sPopPointer(sc, &a) && sPopPointer(sc, &b)) {
  385. sPushBool(sc, a.array == b.array && a.offset == b.offset);
  386. }
  387. }
  388. static void sCall(Script* sc) {
  389. int function = 0;
  390. if(sReadInt(sc, &function) && gfsCall(sc, function)) {
  391. sError(sc, "invalid function call");
  392. }
  393. }
  394. #define CHANGE_OP(type, op) \
  395. { \
  396. char c = 0; \
  397. Pointer p; \
  398. if(sRead(sc, &c, sizeof(char)) && sPopPointer(sc, &p)) { \
  399. void* data = sCheckAddress(sc, &p, sizeof(type)); \
  400. if(data != NULL) { \
  401. type current; \
  402. memcpy(&current, data, sizeof(type)); \
  403. op \
  404. } \
  405. } \
  406. }
  407. #define PUSH_PRE_CHANGE(Type, type) \
  408. CHANGE_OP(type, current += c; sPush##Type(sc, current); \
  409. memcpy(data, &current, sizeof(type));)
  410. #define PUSH_POST_CHANGE(Type, type) \
  411. CHANGE_OP(type, sPush##Type(sc, current); current += c; \
  412. memcpy(data, &current, sizeof(type));)
  413. #define CHANGE(type) \
  414. CHANGE_OP(type, current += c; memcpy(data, &current, sizeof(type));)
  415. #define CAST(From, from, To) \
  416. { \
  417. from value; \
  418. if(sPop##From(sc, &value)) { \
  419. sPush##To(sc, value); \
  420. } \
  421. }
  422. #define CASE_CHANGE(TYPE, Type, type) \
  423. case OP_PUSH_PRE_CHANGE_##TYPE: PUSH_PRE_CHANGE(Type, type); break; \
  424. case OP_PUSH_POST_CHANGE_##TYPE: PUSH_POST_CHANGE(Type, type); break; \
  425. case OP_CHANGE_##TYPE: \
  426. CHANGE(type); \
  427. break;
  428. #define CASE_NUMBER_OP(name, op) \
  429. case OP_##name##_INT: NUMBER_OP(int, Int, op); break; \
  430. case OP_##name##_LONG: NUMBER_OP(long, Long, op); break; \
  431. case OP_##name##_FLOAT: \
  432. NUMBER_OP(float, Float, op); \
  433. break;
  434. #define CASE_BOOL_OP(name, op) \
  435. case OP_##name##_INT: BOOL_OP(int, Int, op); break; \
  436. case OP_##name##_LONG: BOOL_OP(long, Long, op); break; \
  437. case OP_##name##_FLOAT: \
  438. BOOL_OP(float, Float, op); \
  439. break;
  440. #define CASE_TYPE(TYPE, Type, type) \
  441. case OP_STORE_##TYPE: sStore(sc, sizeof(type)); break; \
  442. case OP_RETURN_##TYPE: RETURN(type, Type); break; \
  443. case OP_PRINT_##TYPE: PRINT(type, Type, type##Printer); break; \
  444. case OP_EQUAL_##TYPE: BOOL_OP(type, Type, ==); break; \
  445. case OP_LOAD_##TYPE: sLoad(sc, sizeof(type)); break;
  446. static void sConsumeInstruction(Script* sc) {
  447. switch(sReadOperation(sc)) {
  448. CASE_NUMBER_OP(ADD, +);
  449. CASE_NUMBER_OP(SUB, -);
  450. CASE_NUMBER_OP(MUL, *);
  451. CASE_BOOL_OP(LESS, <);
  452. CASE_BOOL_OP(GREATER, >);
  453. CASE_TYPE(INT, Int, int);
  454. CASE_TYPE(LONG, Long, long);
  455. CASE_TYPE(BOOL, Bool, bool);
  456. CASE_TYPE(FLOAT, Float, float);
  457. CASE_CHANGE(INT, Int, int);
  458. CASE_CHANGE(LONG, Long, long);
  459. case OP_NOTHING: break;
  460. case OP_PUSH_INT: PUSH_CONSTANT(int, Int); break;
  461. case OP_PUSH_LONG: PUSH_CONSTANT(long, Long); break;
  462. case OP_PUSH_FLOAT: PUSH_CONSTANT(float, Float); break;
  463. case OP_PUSH_TRUE: sPushBool(sc, true); break;
  464. case OP_PUSH_FALSE: sPushBool(sc, false); break;
  465. case OP_PUSH_NULLPTR: sPushNullPointer(sc); break;
  466. case OP_DIV_INT: DIVISION(int, Int); break;
  467. case OP_DIV_LONG: DIVISION(long, Long); break;
  468. case OP_DIV_FLOAT: DIVISION(float, Float); break;
  469. case OP_MOD_INT: MODULE(int, Int); break;
  470. case OP_MOD_LONG: MODULE(long, Long); break;
  471. case OP_INVERT_SIGN_INT: INVERT_SIGN(int, Int); break;
  472. case OP_INVERT_SIGN_LONG: INVERT_SIGN(long, Long); break;
  473. case OP_INVERT_SIGN_FLOAT: INVERT_SIGN(float, Float); break;
  474. case OP_NOT: sNot(sc); break;
  475. case OP_AND: BOOL_OP(bool, Bool, &&); break;
  476. case OP_OR: BOOL_OP(bool, Bool, ||); break;
  477. case OP_BIT_NOT_INT: sBitNotInt(sc); break;
  478. case OP_BIT_AND_INT: NUMBER_OP(int, Int, &); break;
  479. case OP_BIT_OR_INT: NUMBER_OP(int, Int, |); break;
  480. case OP_BIT_XOR_INT: NUMBER_OP(int, Int, ^); break;
  481. case OP_LEFT_SHIFT_INT: NUMBER_OP(int, Int, <<); break;
  482. case OP_RIGHT_SHIFT_INT: NUMBER_OP(int, Int, >>); break;
  483. case OP_BIT_NOT_LONG: sBitNotLong(sc); break;
  484. case OP_BIT_AND_LONG: NUMBER_OP(long, Long, &); break;
  485. case OP_BIT_OR_LONG: NUMBER_OP(long, Long, |); break;
  486. case OP_BIT_XOR_LONG: NUMBER_OP(long, Long, ^); break;
  487. case OP_LEFT_SHIFT_LONG: NUMBER_OP(long, Long, <<); break;
  488. case OP_RIGHT_SHIFT_LONG: NUMBER_OP(long, Long, >>); break;
  489. case OP_LINE: sLine(sc); break;
  490. case OP_GOTO: sGoTo(sc); break;
  491. case OP_IF_GOTO: sIfGoTo(sc); break;
  492. case OP_PEEK_FALSE_GOTO: sPeekFalseGoTo(sc); break;
  493. case OP_PEEK_TRUE_GOTO: sPeekTrueGoTo(sc); break;
  494. case OP_GOSUB: sGoSub(sc); break;
  495. case OP_RETURN: sReturn(sc); break;
  496. case OP_RETURN_POINTER: sReturnPointer(sc); break;
  497. case OP_RESERVE: sReserveBytes(sc); break;
  498. case OP_DEREFERENCE_VAR: sDereference(sc); break;
  499. case OP_REFERENCE: sLoad(sc, sizeof(Pointer)); break;
  500. case OP_DUPLICATE_REFERENCE: sDuplicateReference(sc); break;
  501. case OP_ADD_REFERENCE: sAddReference(sc); break;
  502. case OP_LOAD: sLoadSize(sc); break;
  503. case OP_NEW: sNewArray(sc); break;
  504. case OP_DELETE: sDeleteArray(sc); break;
  505. case OP_LENGTH: sLength(sc); break;
  506. case OP_STORE_POINTER: sStore(sc, sizeof(Pointer)); break;
  507. case OP_PRINT_POINTER: sPrintPointer(sc); break;
  508. case OP_EQUAL_POINTER: sEqualPointer(sc); break;
  509. case OP_INT_TO_FLOAT: CAST(Int, int, Float); break;
  510. case OP_FLOAT_TO_INT: CAST(Float, float, Int); break;
  511. case OP_INT_TO_LONG: CAST(Int, int, Long); break;
  512. case OP_LONG_TO_INT: CAST(Long, long, Int); break;
  513. case OP_FLOAT_TO_LONG: CAST(Float, float, Long); break;
  514. case OP_LONG_TO_FLOAT: CAST(Long, long, Float); break;
  515. case OP_CALL: sCall(sc); break;
  516. }
  517. }
  518. static bool sHasData(Script* sc) {
  519. return sc->readIndex < sc->code->length;
  520. }
  521. Script* sInit(ByteCode* code) {
  522. Script* sc = malloc(sizeof(Script));
  523. sc->error[0] = '\0';
  524. sc->code = code;
  525. sc->readIndex = 0;
  526. sc->stackIndex = 0;
  527. sc->stackVarIndex = 0;
  528. sc->line = 0;
  529. asInit(&sc->arrays);
  530. return sc;
  531. }
  532. void sDelete(Script* sc) {
  533. bcDelete(sc->code);
  534. asDelete(&sc->arrays);
  535. free(sc);
  536. }
  537. void sRun(Script* sc) {
  538. while(sHasData(sc)) {
  539. sConsumeInstruction(sc);
  540. if(sc->error[0] != '\0') {
  541. puts("error:");
  542. printf(" - info: %s\n", sc->error);
  543. printf(" - line: %d\n", sc->line);
  544. return;
  545. }
  546. }
  547. }
  548. void sSetIntPrinter(IntPrinter p) {
  549. intPrinter = p;
  550. }
  551. void sSetLongPrinter(LongPrinter p) {
  552. longPrinter = p;
  553. }
  554. void sSetFloatPrinter(FloatPrinter p) {
  555. floatPrinter = p;
  556. }
  557. void sSetBoolPrinter(BoolPrinter p) {
  558. boolPrinter = p;
  559. }
  560. void sSetPointerPrinter(PointerPrinter p) {
  561. pointerPrinter = p;
  562. }