Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

129 righe
3.3 KiB

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _CRT_SECURE_NO_DEPRECATE
  3. #define _CRTDBG_MAP_ALLOC
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include <string.h>
  8. #include <cmath>
  9. #include <ctype.h>
  10. #include <stdarg.h>
  11. #include <errno.h>
  12. #include <new>
  13. // #include <functional>
  14. #ifdef _MSC_VER
  15. # include <crtdbg.h>
  16. # include <direct.h>
  17. # include <windows.h>
  18. #else
  19. # include <unistd.h>
  20. # include <signal.h>
  21. #endif
  22. #include "ftb/types.hpp"
  23. #include "ftb/arraylist.hpp"
  24. #include "ftb/bucket_allocator.hpp"
  25. #include "ftb/macros.hpp"
  26. #include "ftb/profiler.hpp"
  27. /*
  28. Forward declare the hash functions for the hashmap (needed at least
  29. for clang++)
  30. */
  31. namespace Slime {struct Lisp_Object;}
  32. bool hm_objects_match(char* a, char* b);
  33. bool hm_objects_match(void* a, void* b);
  34. bool hm_objects_match(Slime::Lisp_Object* a, Slime::Lisp_Object* b);
  35. unsigned int hm_hash(char* str);
  36. unsigned int hm_hash(void* ptr);
  37. unsigned int hm_hash(Slime::Lisp_Object* obj);
  38. #include "ftb/hashmap.hpp"
  39. namespace Slime {
  40. # include "defines.cpp"
  41. # include "assert.hpp"
  42. # include "define_macros.hpp"
  43. # include "platform.cpp"
  44. # include "structs.cpp"
  45. # include "forward_decls.cpp"
  46. }
  47. bool hm_objects_match(char* a, char* b) {
  48. return strcmp(a, b) == 0;
  49. }
  50. bool hm_objects_match(void* a, void* b) {
  51. return a == b;
  52. }
  53. bool hm_objects_match(Slime::Lisp_Object* a, Slime::Lisp_Object* b) {
  54. return Slime::lisp_object_equal(a, b);
  55. }
  56. unsigned int hm_hash(char* str) {
  57. unsigned int value = str[0] << 7;
  58. int i = 0;
  59. while (str[i]) {
  60. value = (10000003 * value) ^ str[i++];
  61. }
  62. return value ^ i;
  63. }
  64. unsigned int hm_hash(void* ptr) {
  65. return ((unsigned long long)ptr * 2654435761) % 4294967296;
  66. }
  67. unsigned int hm_hash(Slime::Lisp_Object* obj) {
  68. using namespace Slime;
  69. switch (Memory::get_type(obj)) {
  70. // hash from adress: if two objects of these types have
  71. // different addresses, they are different
  72. case Lisp_Object_Type::CFunction:
  73. case Lisp_Object_Type::Function:
  74. case Lisp_Object_Type::Symbol:
  75. case Lisp_Object_Type::Keyword:
  76. case Lisp_Object_Type::Continuation:
  77. case Lisp_Object_Type::Nil:
  78. case Lisp_Object_Type::T:
  79. return hm_hash((void*) obj);
  80. // hash from contents: even if objects are themselved
  81. // different, they cauld be equivalent:
  82. case Lisp_Object_Type::Pointer: return hm_hash((void*) obj->value.pointer);
  83. case Lisp_Object_Type::Number: return hm_hash((void*) (unsigned long long)obj->value.number); // HACK(Felix): yes
  84. case Lisp_Object_Type::String: return hm_hash((char*) &obj->value.string->data);
  85. case Lisp_Object_Type::Pair: {
  86. u32 hash = 1;
  87. for_lisp_list (obj) {
  88. hash <<= 1;
  89. hash += hm_hash(it);
  90. }
  91. return hash;
  92. } break;
  93. case Lisp_Object_Type::Vector:
  94. case Lisp_Object_Type::HashMap:
  95. default:
  96. create_not_yet_implemented_error();
  97. return 0;
  98. }
  99. }
  100. namespace Slime {
  101. # include "globals.cpp"
  102. # include "memory.cpp"
  103. # include "gc.cpp"
  104. # include "lisp_object.cpp"
  105. # include "error.cpp"
  106. # include "io.cpp"
  107. # include "env.cpp"
  108. # include "parse.cpp"
  109. # include "eval.cpp"
  110. # include "visualization.cpp"
  111. # include "docgeneration.cpp"
  112. # include "built_ins.cpp"
  113. # include "testing.cpp"
  114. // # include "undefines.cpp"
  115. }