Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

156 строки
3.9 KiB

  1. namespace Slime {
  2. struct Lisp_Object;
  3. struct String;
  4. struct Environment;
  5. enum struct Thread_Type : u8 {
  6. Main,
  7. GarbageCollection
  8. };
  9. enum struct Lisp_Object_Type : u8 {
  10. Nil,
  11. T,
  12. Symbol,
  13. Keyword,
  14. Number,
  15. String,
  16. Pair,
  17. Vector,
  18. Continuation,
  19. Pointer,
  20. HashMap,
  21. Function,
  22. Invalid_Garbage_Collected,
  23. Invalid_Under_Construction
  24. };
  25. enum struct NasAction : u8 {
  26. And_Then_Action,
  27. Macro_Write_Back,
  28. Eval,
  29. Step,
  30. TM,
  31. Pop,
  32. If,
  33. Define_Var,
  34. Pop_Environment
  35. };
  36. enum struct Lisp_Function_Type : u8 {
  37. Lambda, // normal evaluation order
  38. Macro // args are not evaluated, a new programm is returned
  39. // that will be executed again
  40. };
  41. enum struct C_Function_Type : u8 {
  42. cFunction, // normal evaluation order
  43. cSpecial, // args are not evaluated, but result is returned
  44. // as you would expect
  45. cMacro // No return value, but the current_execution is
  46. // modified
  47. };
  48. enum struct Log_Level : u8 {
  49. None,
  50. Critical,
  51. Warning,
  52. Info,
  53. Debug,
  54. };
  55. struct Continuation {
  56. Array_List<Lisp_Object*> cs; // call stack
  57. Array_List<Lisp_Object*> pcs; // program counter stack
  58. Array_List<int> ams; // apply marker stack
  59. Array_List<Array_List<NasAction>> nass; // next action stack stack
  60. Array_List<Lambda<void()>> ats; // and then stack
  61. Array_List<Lisp_Object*> mes; // macro expansion stack
  62. Array_List<Environment*> envi_stack;
  63. };
  64. struct String {
  65. u32 length;
  66. char* data;
  67. };
  68. struct Source_Code_Location {
  69. String file;
  70. u32 line;
  71. u32 column;
  72. };
  73. struct Pair {
  74. Lisp_Object* first;
  75. Lisp_Object* rest;
  76. };
  77. struct Vector {
  78. u32 length;
  79. Lisp_Object* data;
  80. };
  81. struct Positional_Arguments {
  82. Array_List<Lisp_Object*> symbols;
  83. };
  84. struct Keyword_Arguments {
  85. // Array of Pointers to Lisp_Object<Keyword>
  86. Array_List<Lisp_Object*> keywords;
  87. // NOTE(Felix): values[i] will be nullptr if no defalut value was
  88. // declared for key identifiers[i]
  89. Array_List<Lisp_Object*> values;
  90. };
  91. struct Arguments {
  92. Positional_Arguments positional;
  93. Keyword_Arguments keyword;
  94. // NOTE(Felix): rest_argument will be nullptr if no rest argument
  95. // is declared otherwise its a symbol
  96. Lisp_Object* rest;
  97. };
  98. struct Environment {
  99. Array_List<Environment*> parents;
  100. Hash_Map<void*, Lisp_Object*> hm;
  101. };
  102. struct Function {
  103. Arguments args;
  104. Environment* parent_environment;
  105. bool is_c;
  106. union {
  107. Lisp_Function_Type lisp_function_type;
  108. C_Function_Type c_function_type;
  109. } type;
  110. union {
  111. Lisp_Object* lisp_body;
  112. Lisp_Object* (*c_body)();
  113. void (*c_macro_body)();
  114. } body;
  115. };
  116. // #pragma pack(1)
  117. struct Lisp_Object {
  118. Lisp_Object_Type type;
  119. union value {
  120. String symbol; // used for symbols and keywords
  121. f64 number;
  122. String string;
  123. Pair pair;
  124. Vector vector;
  125. Function* function;
  126. void* pointer;
  127. Continuation* continuation;
  128. Hash_Map<Lisp_Object*, Lisp_Object*>* hashMap;
  129. } value;
  130. };
  131. // #pragma options align=reset
  132. struct Error {
  133. Lisp_Object* position;
  134. // type has to be a keyword
  135. Lisp_Object* type;
  136. String message;
  137. };
  138. }