sans.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. typedef unsigned long u;
  2. typedef signed long s;
  3. enum stag {
  4. tbool = 1, // value: #f, #t
  5. tnumb = 2, // ivalue: number
  6. tchar = 3, // ivalue: char
  7. tsymb = 4, // value: symbol table ref
  8. tcons = 5, // value: cons ref
  9. tstrn = 6, // value: string ref
  10. tvect = 7, // value: vec ref
  11. tclos = 8, // value: closure ref
  12. tnull = 9,
  13. teof = 10,
  14. tlabl = 11, // value: label
  15. };
  16. typedef struct {
  17. enum stag tag;
  18. union {
  19. u value;
  20. s ivalue;
  21. } data;
  22. } sdata;
  23. #define SDBOOL(t) (sdata){.tag = tbool, .data.ivalue = t}
  24. #define SDSYMB(t) (sdata){.tag = tsymb, .data.value = intern(t)}
  25. #define SDNUMB(t) (sdata){.tag = tnumb, .data.ivalue = t}
  26. #define SDCHAR(t) (sdata){.tag = tchar, .data.ivalue = t}
  27. #define SDNULL() (sdata){.tag = tnull}
  28. #define SDEOF() (sdata){.tag = teof}
  29. // http://c.learncodethehardway.org/book/ex20.html
  30. #define clean_errno() (errno == 0 ? "None" : strerror(errno))
  31. #define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__); exit(-1)