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

121 строка
3.9 KiB

  1. // proc assert_type(Lisp_Object*, Lisp_Object_Type) -> void;
  2. proc add_to_load_path(const char*) -> void;
  3. proc lisp_object_equal(Lisp_Object*,Lisp_Object*) -> bool;
  4. proc built_in_load(String*) -> Lisp_Object*;
  5. proc built_in_import(String*) -> Lisp_Object*;
  6. proc create_error(const char* c_file_name, int c_file_line, Lisp_Object* type, String* message) -> void;
  7. proc create_error(const char* c_file_name, int c_file_line, Lisp_Object* type, const char* format, ...) -> void;
  8. proc create_error(Lisp_Object* type, const char* message, const char* c_file_name, int c_file_line) -> void;
  9. proc eval_arguments(Lisp_Object*) -> Lisp_Object*;
  10. proc eval_expr(Lisp_Object*) -> Lisp_Object*;
  11. proc is_truthy (Lisp_Object*) -> bool;
  12. proc list_length(Lisp_Object*) -> int;
  13. proc load_built_ins_into_environment() -> void;
  14. proc create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function) -> void;
  15. proc print_environment(Environment*) -> void;
  16. inline proc get_root_environment() -> Environment*;
  17. inline proc get_current_environment() -> Environment*;
  18. inline proc push_environment(Environment*) -> void;
  19. inline proc pop_environment() -> void;
  20. proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char*;
  21. proc visualize_lisp_machine() -> void;
  22. proc generate_docs(String* path) -> void;
  23. namespace Memory {
  24. proc create_built_ins_environment() -> Environment*;
  25. proc get_or_create_lisp_object_keyword(const char* identifier) -> Lisp_Object*;
  26. inline proc get_type(Lisp_Object* node) -> Lisp_Object_Type;
  27. }
  28. namespace Parser {
  29. // extern Environment* environment_for_macros;
  30. extern String* standard_in;
  31. extern String* parser_file;
  32. extern int parser_line;
  33. extern int parser_col;
  34. proc parse_single_expression(char* text) -> Lisp_Object*;
  35. }
  36. namespace Globals {
  37. char* bin_path = nullptr;
  38. Log_Level log_level = Log_Level::Debug;
  39. Void_Ptr_Array_List load_path = create_Void_Ptr_array_list();
  40. namespace Current_Execution {
  41. Lisp_Object_Array_List call_stack = create_Lisp_Object_array_list();
  42. Environment_Array_List envi_stack = create_Environment_array_list();
  43. }
  44. #ifdef _DONT_BREAK_ON_ERRORS
  45. bool breaking_on_errors = false;
  46. #else
  47. bool breaking_on_errors = true;
  48. #endif
  49. Error* error = nullptr;
  50. }
  51. inline bool hm_objects_match(char* a, char* b) {
  52. return strcmp(a, b) == 0;
  53. }
  54. inline bool hm_objects_match(void* a, void* b) {
  55. return a == b;
  56. }
  57. u32 hm_hash(void* ptr) {
  58. return ((unsigned long long)ptr * 2654435761) % 4294967296;
  59. }
  60. u32 hm_hash(char* str) {
  61. u32 value = str[0] << 7;
  62. int i = 0;
  63. while (str[i]) {
  64. value = (10000003 * value) ^ str[i++];
  65. }
  66. return value ^ i;
  67. }
  68. inline bool hm_objects_match(Lisp_Object* a, Lisp_Object* b) {
  69. return lisp_object_equal(a, b);
  70. }
  71. u32 hm_hash(Lisp_Object* obj) {
  72. switch (Memory::get_type(obj)) {
  73. // hash from adress: if two objects of these types have
  74. // different addresses, they are different
  75. case Lisp_Object_Type::CFunction:
  76. case Lisp_Object_Type::Function:
  77. case Lisp_Object_Type::Symbol:
  78. case Lisp_Object_Type::Keyword:
  79. case Lisp_Object_Type::Continuation:
  80. case Lisp_Object_Type::Nil:
  81. case Lisp_Object_Type::T:
  82. return hm_hash((void*) obj);
  83. // hash from contents: even if objects are themselved
  84. // different, they cauld be equivalent:
  85. case Lisp_Object_Type::Pointer: return hm_hash((void*) obj->value.pointer);
  86. case Lisp_Object_Type::Number: return hm_hash((void*) (unsigned long long)obj->value.number); // HACK(Felix): yes
  87. case Lisp_Object_Type::String: return hm_hash((char*) &obj->value.string->data);
  88. case Lisp_Object_Type::Pair: {
  89. u32 hash = 1;
  90. for_lisp_list (obj) {
  91. hash <<= 1;
  92. hash += hm_hash(it);
  93. }
  94. return hash;
  95. } break;
  96. case Lisp_Object_Type::Vector:
  97. case Lisp_Object_Type::HashMap:
  98. default:
  99. create_not_yet_implemented_error();
  100. return 0;
  101. }
  102. }