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

150 строки
3.0 KiB

  1. struct Lisp_Object;
  2. struct String;
  3. struct Environment;
  4. define_array_list(Lisp_Object*, Lisp_Object);
  5. define_array_list(String*, String);
  6. define_array_list(int, Int);
  7. define_array_list(void*, Void_Ptr);
  8. enum struct Lisp_Object_Type {
  9. Nil,
  10. T,
  11. Symbol,
  12. Keyword,
  13. Number,
  14. String,
  15. Pair,
  16. Function,
  17. CFunction,
  18. };
  19. enum struct Function_Type {
  20. Lambda,
  21. Special_Lambda,
  22. Macro
  23. };
  24. enum struct Error_Type {
  25. Ill_Formed_Arguments,
  26. Ill_Formed_Lambda_List,
  27. Ill_Formed_List,
  28. Not_A_Function,
  29. Not_Yet_Implemented,
  30. Symbol_Not_Defined,
  31. Syntax_Error,
  32. Trailing_Garbage,
  33. Type_Missmatch,
  34. Unbalanced_Parenthesis,
  35. Unexpected_Eof,
  36. Unknown_Error,
  37. Unknown_Keyword_Argument,
  38. Wrong_Number_Of_Arguments,
  39. Out_Of_Memory,
  40. };
  41. enum struct Log_Level {
  42. None,
  43. Critical,
  44. Warning,
  45. Info,
  46. Debug,
  47. };
  48. struct String {
  49. int length;
  50. char data;
  51. };
  52. struct Source_Code_Location {
  53. String* file;
  54. int line;
  55. int column;
  56. };
  57. struct Symbol {
  58. String* identifier;
  59. };
  60. struct Keyword {
  61. String* identifier;
  62. };
  63. struct Number {
  64. double value;
  65. };
  66. struct Pair {
  67. Lisp_Object* first;
  68. Lisp_Object* rest;
  69. };
  70. struct Positional_Arguments {
  71. // TODO(Felix) use Lisp_Object_symbols here instead, so we don't have
  72. // to convert them to strings and back to symbols
  73. String** identifiers; // Array of Pointers to String
  74. int next_index;
  75. int length;
  76. };
  77. struct Keyword_Arguments {
  78. String** identifiers; // Array of Pointers to String
  79. // NOTE(Felix): values[i] will be nullptr if no defalut value was
  80. // declared for key identifiers[i]
  81. Lisp_Object_Array_List* values;
  82. int next_index;
  83. int length;
  84. };
  85. struct Function {
  86. Function_Type type;
  87. String* docstring;
  88. Positional_Arguments* positional_arguments;
  89. Keyword_Arguments* keyword_arguments;
  90. // rest_argument will be nullptr if no rest argument is declared
  91. String* rest_argument;
  92. Lisp_Object* body; // implicit prog
  93. Environment* parent_environment; // we are doing closures now!!
  94. };
  95. struct cFunction {
  96. std::function<Lisp_Object* (Lisp_Object*, Environment*)> function;
  97. };
  98. struct Lisp_Object {
  99. Source_Code_Location* sourceCodeLocation;
  100. Lisp_Object_Type type;
  101. union {
  102. Symbol* symbol;
  103. Keyword* keyword;
  104. Number* number;
  105. String* string;
  106. Pair* pair;
  107. Function* function;
  108. cFunction* cFunction;
  109. } value;
  110. };
  111. struct Parsed_Arguments {
  112. Lisp_Object_Array_List* positional_arguments;
  113. // TODO(Felix): Really use hashmap (keyword[sting] ->
  114. // value[Lisp_Object*]) here
  115. Lisp_Object_Array_List* keyword_keys;
  116. Lisp_Object_Array_List* keyword_values;
  117. };
  118. struct Environment {
  119. Environment* parent;
  120. int capacity;
  121. int next_index;
  122. // TODO(Felix): Use a hashmap here.
  123. char** keys;
  124. Lisp_Object** values;
  125. };
  126. struct Error {
  127. Error_Type type;
  128. Source_Code_Location* location;
  129. };