1
0

minilisp.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef MINILISP_H
  2. #define MINILISP_H
  3. #if __AMIGA
  4. #define uint8_t unsigned char
  5. #define uint16_t unsigned short
  6. #define uint32_t unsigned long
  7. #define uint64_t unsigned long long
  8. #else
  9. #include <stdint.h>
  10. #endif
  11. #if CPU_X64
  12. #define jit_word_t uint64_t
  13. #else
  14. #define jit_word_t uint32_t
  15. #endif
  16. #include "strmap.h"
  17. #ifndef BLAND
  18. #define KNRM "\x1B[0m"
  19. #define KRED "\x1B[31m"
  20. #define KGRN "\x1B[32m"
  21. #define KYEL "\x1B[33m"
  22. #define KBLU "\x1B[34m"
  23. #define KMAG "\x1B[35m"
  24. #define KCYN "\x1B[36m"
  25. #define KWHT "\x1B[37m"
  26. #else
  27. #define KNRM ""
  28. #define KRED ""
  29. #define KGRN ""
  30. #define KYEL ""
  31. #define KBLU ""
  32. #define KMAG ""
  33. #define KCYN ""
  34. #define KWHT ""
  35. #endif
  36. #define TAG_FREED 0
  37. #define TAG_INT 1
  38. #define TAG_CONS 2
  39. #define TAG_SYM 3
  40. #define TAG_LAMBDA 4
  41. #define TAG_BUILTIN 5
  42. #define TAG_BIGNUM 6
  43. #define TAG_STR 7
  44. #define TAG_BYTES 8
  45. #define TAG_VEC 9
  46. #define TAG_STRUCT_DEF 10
  47. #define TAG_STRUCT 11
  48. #define TAG_ERROR 512
  49. #define TAG_LET 1024
  50. #define TAG_ANY 2048
  51. #define TAG_VOID 4096
  52. #define TAG_STREAM 8192
  53. #define TAG_FS 16384
  54. #define TAG_MARK 65536
  55. #define tag_t jit_word_t
  56. #define MAX_EVAL_DEPTH 10000
  57. #define SYM_INIT_BUFFER_SIZE 32
  58. #define BIGNUM_INIT_BUFFER_SIZE 32
  59. #define ERR_SYNTAX 0
  60. #define ERR_MAX_EVAL_DEPTH 1
  61. #define ERR_UNKNOWN_OP 2
  62. #define ERR_APPLY_NIL 3
  63. #define ERR_INVALID_PARAM_TYPE 4
  64. #define ERR_OUT_OF_BOUNDS 5
  65. #define ERR_OUT_OF_MEMORY 666
  66. #define ERR_NOT_FOUND 404
  67. #define ERR_FORBIDDEN 403
  68. #define max(a,b) (a > b ? a : b)
  69. #define min(a,b) (a < b ? a : b)
  70. typedef struct Cell {
  71. union ar {
  72. jit_word_t value;
  73. void* addr;
  74. } ar;
  75. union dr {
  76. jit_word_t size;
  77. void* next;
  78. } dr;
  79. jit_word_t tag;
  80. } Cell;
  81. int is_nil(Cell* c);
  82. typedef struct env_entry {
  83. Cell* cell;
  84. char name[64];
  85. } env_entry;
  86. #define car(x) (x?(Cell*)((Cell*)x)->ar.addr:NULL)
  87. #define cdr(x) (x?(Cell*)((Cell*)x)->dr.next:NULL)
  88. #endif