1
0

minilisp.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 MAX_SYMBOL_SIZE 64
  60. #define ERR_SYNTAX 0
  61. #define ERR_MAX_EVAL_DEPTH 1
  62. #define ERR_UNKNOWN_OP 2
  63. #define ERR_APPLY_NIL 3
  64. #define ERR_INVALID_PARAM_TYPE 4
  65. #define ERR_OUT_OF_BOUNDS 5
  66. #define ERR_OUT_OF_MEMORY 666
  67. #define ERR_NOT_FOUND 404
  68. #define ERR_FORBIDDEN 403
  69. #define max(a,b) (a > b ? a : b)
  70. #define min(a,b) (a < b ? a : b)
  71. typedef struct Cell {
  72. union ar {
  73. jit_word_t value;
  74. void* addr;
  75. } ar;
  76. union dr {
  77. jit_word_t size;
  78. void* next;
  79. } dr;
  80. jit_word_t tag;
  81. } Cell;
  82. int is_nil(Cell* c);
  83. typedef struct env_entry {
  84. Cell* cell;
  85. char name[MAX_SYMBOL_SIZE];
  86. } env_entry;
  87. #define car(x) (x?(Cell*)((Cell*)x)->ar.addr:NULL)
  88. #define cdr(x) (x?(Cell*)((Cell*)x)->dr.next:NULL)
  89. #endif