Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

163 rindas
3.8 KiB

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