You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

122 lines
3.3 KiB

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