2
0

test_byte_code.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "aFun.h"
  4. int main() {
  5. af_ByteCode *bt1 = makeLiteralByteCode("data", "func", ',', 0, "Unknow");
  6. af_ByteCode *bt2 = makeVariableByteCode("var1", 0, 1, NULL);
  7. af_ByteCode *bt3 = makeLiteralByteCode("data2", "func", 0, 0, NULL);
  8. af_ByteCode *bt4 = makeVariableByteCode("var2", 0, 1, NULL);
  9. connectByteCode(&bt1, bt2);
  10. connectByteCode(&bt3, bt4);
  11. af_ByteCode *bt5 = makeBlockByteCode(parentheses, bt3, 0, 1, NULL, NULL);
  12. connectByteCode(&bt2, bt5);
  13. FILE *file = fopen("test.afb", "wb");
  14. if (file == NULL) {
  15. fprintf(stderr, "Can't not creat file: test.afb\n");
  16. return EXIT_FAILURE;
  17. }
  18. if(!writeAllByteCode(bt1, file)) {
  19. fprintf(stderr, "Write test.afb error.\n");
  20. return EXIT_FAILURE;
  21. }
  22. fclose(file);
  23. af_ByteCode *get;
  24. file = fopen("test.afb", "rb");
  25. if (file == NULL) {
  26. fprintf(stderr, "Can't not read file: test.afb\n");
  27. return EXIT_FAILURE;
  28. }
  29. if(!readAllByteCode(&get, file)) {
  30. fprintf(stderr, "Read test.afb error.\n");
  31. return EXIT_FAILURE;
  32. }
  33. fclose(file);
  34. printf("out:\n");
  35. printByteCode(bt1);
  36. printf("in:\n");
  37. printByteCode(get);
  38. freeAllByteCode(bt1);
  39. freeAllByteCode(get);
  40. return EXIT_SUCCESS;
  41. }