compiler_new.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef SLEDGE_COMPILER_H
  2. #define SLEDGE_COMPILER_H
  3. #include <string.h>
  4. #define MAXARGS 8
  5. #define MAXFRAME 64 // maximum MAXFRAME-MAXARGS local vars
  6. typedef void* (*funcptr)();
  7. typedef enum arg_t {
  8. ARGT_CONST,
  9. ARGT_ENV,
  10. ARGT_LAMBDA,
  11. ARGT_REG,
  12. ARGT_REG_INT,
  13. ARGT_STACK,
  14. ARGT_STACK_INT
  15. } arg_t;
  16. typedef struct Arg {
  17. arg_t type;
  18. Cell* cell;
  19. env_entry* env;
  20. int slot;
  21. char* name;
  22. char* type_name;
  23. } Arg;
  24. typedef struct Frame Frame;
  25. struct Frame {
  26. Arg* f;
  27. int sp;
  28. int locals;
  29. void* stack_end;
  30. Frame* parent_frame;
  31. };
  32. typedef struct Label {
  33. char* name;
  34. int idx;
  35. } Label;
  36. typedef enum builtin_t {
  37. BUILTIN_ADD = 1,
  38. BUILTIN_SUB,
  39. BUILTIN_MUL,
  40. BUILTIN_DIV,
  41. BUILTIN_MOD,
  42. BUILTIN_BITAND,
  43. BUILTIN_BITNOT,
  44. BUILTIN_BITOR,
  45. BUILTIN_BITXOR,
  46. BUILTIN_SHL,
  47. BUILTIN_SHR,
  48. BUILTIN_LT,
  49. BUILTIN_GT,
  50. BUILTIN_EQ,
  51. BUILTIN_WHILE,
  52. BUILTIN_DEF,
  53. BUILTIN_IF,
  54. BUILTIN_FN,
  55. BUILTIN_CAR,
  56. BUILTIN_CDR,
  57. BUILTIN_CONS,
  58. BUILTIN_LIST,
  59. BUILTIN_ALLOC,
  60. BUILTIN_ALLOC_STR,
  61. BUILTIN_NEW,
  62. BUILTIN_BYTES_TO_STR,
  63. BUILTIN_STR_TO_BYTES,
  64. BUILTIN_CONCAT,
  65. BUILTIN_SUBSTR,
  66. BUILTIN_GET8,
  67. BUILTIN_GET16,
  68. BUILTIN_GET32,
  69. BUILTIN_PUT8,
  70. BUILTIN_PUT16,
  71. BUILTIN_PUT32,
  72. BUILTIN_SGET,
  73. BUILTIN_SPUT,
  74. BUILTIN_SIZE,
  75. BUILTIN_UGET,
  76. BUILTIN_UPUT,
  77. BUILTIN_USIZE,
  78. BUILTIN_TYPE,
  79. BUILTIN_LET,
  80. BUILTIN_QUOTE,
  81. BUILTIN_STRUCT,
  82. BUILTIN_MAP,
  83. BUILTIN_DO,
  84. BUILTIN_EVAL,
  85. BUILTIN_READ,
  86. BUILTIN_WRITE,
  87. BUILTIN_PRINT,
  88. BUILTIN_MOUNT,
  89. BUILTIN_MMAP,
  90. BUILTIN_OPEN,
  91. BUILTIN_CLOSE,
  92. BUILTIN_RECV,
  93. BUILTIN_SEND,
  94. BUILTIN_GC,
  95. BUILTIN_SYMBOLS,
  96. BUILTIN_DEBUG,
  97. BUILTIN_LOAD,
  98. BUILTIN_SAVE,
  99. BUILTIN_SIN,
  100. BUILTIN_COS,
  101. BUILTIN_SQRT
  102. } builtin_t;
  103. Cell* insert_global_symbol(Cell* symbol, Cell* cell);
  104. env_entry* lookup_global_symbol(char* name);
  105. extern Cell* platform_debug();
  106. Cell* platform_eval(Cell* expr);
  107. #endif