1
0

minilisp.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef MINILISP_H
  2. #define MINILISP_H
  3. #define jit_word_t unsigned long // FIXME: works only on linux
  4. #include "strmap.h"
  5. #define KNRM "\x1B[0m"
  6. #define KRED "\x1B[31m"
  7. #define KGRN "\x1B[32m"
  8. #define KYEL "\x1B[33m"
  9. #define KBLU "\x1B[34m"
  10. #define KMAG "\x1B[35m"
  11. #define KCYN "\x1B[36m"
  12. #define KWHT "\x1B[37m"
  13. #define TAG_FREED 0
  14. #define TAG_INT 1
  15. #define TAG_CONS 2
  16. #define TAG_SYM 4
  17. #define TAG_LAMBDA 8
  18. #define TAG_BUILTIN 16
  19. #define TAG_BIGNUM 32
  20. #define TAG_STR 64
  21. #define TAG_BYTES 128
  22. #define TAG_VEC 256
  23. #define TAG_ERROR 512
  24. #define TAG_LET 1024
  25. #define TAG_ANY 2048
  26. #define TAG_VOID 4096
  27. #define TAG_STREAM 8192
  28. #define TAG_FS 16384
  29. #define TAG_MARK 65536
  30. #define tag_t jit_word_t
  31. #define MAX_EVAL_DEPTH 10000
  32. #define SYM_INIT_BUFFER_SIZE 32
  33. #define BIGNUM_INIT_BUFFER_SIZE 32
  34. #define ERR_SYNTAX 0
  35. #define ERR_MAX_EVAL_DEPTH 1
  36. #define ERR_UNKNOWN_OP 2
  37. #define ERR_APPLY_NIL 3
  38. #define ERR_INVALID_PARAM_TYPE 4
  39. #define ERR_OUT_OF_BOUNDS 5
  40. #define ERR_OUT_OF_MEMORY 666
  41. #define ERR_NOT_FOUND 404
  42. #define ERR_FORBIDDEN 403
  43. #define max(a,b) (a > b ? a : b)
  44. #define min(a,b) (a < b ? a : b)
  45. typedef struct Cell {
  46. union ar {
  47. jit_word_t value;
  48. void* addr;
  49. } ar;
  50. union dr {
  51. jit_word_t size;
  52. void* next;
  53. } dr;
  54. jit_word_t tag;
  55. } Cell;
  56. int is_nil(Cell* c);
  57. typedef struct env_entry {
  58. Cell* cell;
  59. char name[64];
  60. } env_entry;
  61. #define car(x) (x?(Cell*)((Cell*)x)->ar.addr:NULL)
  62. #define cdr(x) (x?(Cell*)((Cell*)x)->dr.next:NULL)
  63. #endif