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

142 строки
2.8 KiB

  1. struct Lisp_Object;
  2. struct String;
  3. struct Environment;
  4. define_array_list(Lisp_Object*, Lisp_Object);
  5. define_array_list(Environment*, Environment);
  6. define_array_list(String*, String);
  7. define_array_list(int, Int);
  8. define_array_list(void*, Void_Ptr);
  9. enum struct Lisp_Object_Type {
  10. Nil,
  11. T,
  12. Symbol,
  13. Keyword,
  14. Number,
  15. String,
  16. Pair,
  17. // Pointer,
  18. // OwningPointer,
  19. Function,
  20. CFunction,
  21. };
  22. typedef uint64_t u64;
  23. enum class Lisp_Object_Flags : u64
  24. {
  25. // bits 1 to 5 (including) will be reserved for the type
  26. aliveness = 1 << 5,
  27. };
  28. enum struct Function_Type {
  29. Lambda,
  30. Special_Lambda,
  31. Macro
  32. };
  33. enum struct Log_Level {
  34. None,
  35. Critical,
  36. Warning,
  37. Info,
  38. Debug,
  39. };
  40. struct String {
  41. int length;
  42. char data;
  43. };
  44. struct Source_Code_Location {
  45. String* file;
  46. int line;
  47. int column;
  48. };
  49. struct Symbol {
  50. String* identifier;
  51. u64 hash;
  52. };
  53. struct Keyword {
  54. String* identifier;
  55. u64 hash;
  56. };
  57. struct Pair {
  58. Lisp_Object* first;
  59. Lisp_Object* rest;
  60. };
  61. struct Positional_Arguments {
  62. Lisp_Object** symbols; // Array of Pointers to Lisp_Object<Symbol>
  63. int next_index;
  64. int length;
  65. };
  66. struct Keyword_Arguments {
  67. Lisp_Object** keywords; // Array of Pointers to Lisp_Object<Keyword>
  68. // NOTE(Felix): values[i] will be nullptr if no defalut value was
  69. // declared for key identifiers[i]
  70. Lisp_Object_Array_List* values;
  71. int next_index;
  72. int length;
  73. };
  74. struct Function {
  75. Function_Type type;
  76. Positional_Arguments* positional_arguments;
  77. Keyword_Arguments* keyword_arguments;
  78. // rest_argument will be nullptr if no rest argument is declared
  79. String* rest_argument;
  80. Lisp_Object* body; // implicit begin
  81. Environment* parent_environment; // we are doing closures now!!
  82. };
  83. struct cFunction {
  84. std::function<Lisp_Object* (Lisp_Object*, Environment*)> function;
  85. };
  86. struct Lisp_Object {
  87. Source_Code_Location* sourceCodeLocation;
  88. u64 flags;
  89. Lisp_Object* userType;
  90. String* docstring;
  91. union {
  92. Symbol symbol; // used for symbols and keywords
  93. double number;
  94. String* string;
  95. Pair pair;
  96. Function function;
  97. cFunction* cFunction;
  98. } value;
  99. };
  100. struct Parsed_Arguments {
  101. Lisp_Object_Array_List* positional_arguments;
  102. // TODO(Felix): Really use hashmap (keyword[sting] ->
  103. // value[Lisp_Object*]) here
  104. Lisp_Object_Array_List* keyword_keys;
  105. Lisp_Object_Array_List* keyword_values;
  106. };
  107. struct Environment {
  108. Environment_Array_List* parents;
  109. int capacity;
  110. int next_index;
  111. // TODO(Felix): Use a hashmap here.
  112. char** keys;
  113. Lisp_Object** values;
  114. };
  115. struct Error {
  116. Lisp_Object* position;
  117. // type has to be a keyword
  118. Lisp_Object* type;
  119. String* message;
  120. };