rbs 4.0.0.dev.1 → 4.0.0.dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +51 -0
  5. data/.github/workflows/dependabot.yml +1 -1
  6. data/.github/workflows/ruby.yml +28 -17
  7. data/.github/workflows/typecheck.yml +0 -2
  8. data/.gitignore +4 -0
  9. data/.rubocop.yml +1 -1
  10. data/.vscode/extensions.json +5 -0
  11. data/.vscode/settings.json +19 -0
  12. data/README.md +37 -0
  13. data/Rakefile +90 -0
  14. data/config.yml +1 -1
  15. data/core/enumerable.rbs +9 -0
  16. data/core/io.rbs +4 -4
  17. data/core/thread.rbs +0 -7
  18. data/ext/rbs_extension/ast_translation.c +1010 -1074
  19. data/ext/rbs_extension/ast_translation.h +4 -0
  20. data/ext/rbs_extension/class_constants.c +78 -74
  21. data/ext/rbs_extension/class_constants.h +4 -0
  22. data/ext/rbs_extension/compat.h +10 -0
  23. data/ext/rbs_extension/extconf.rb +15 -1
  24. data/ext/rbs_extension/legacy_location.c +173 -172
  25. data/ext/rbs_extension/legacy_location.h +8 -3
  26. data/ext/rbs_extension/main.c +315 -273
  27. data/ext/rbs_extension/rbs_extension.h +3 -0
  28. data/ext/rbs_extension/rbs_string_bridging.h +4 -0
  29. data/include/rbs/ast.h +11 -12
  30. data/include/rbs/defines.h +11 -12
  31. data/include/rbs/lexer.h +108 -108
  32. data/include/rbs/location.h +14 -14
  33. data/include/rbs/parser.h +21 -19
  34. data/include/rbs/string.h +3 -3
  35. data/include/rbs/util/rbs_allocator.h +14 -14
  36. data/include/rbs/util/rbs_constant_pool.h +3 -3
  37. data/include/rbs/util/rbs_encoding.h +1 -1
  38. data/lib/rbs/environment.rb +4 -0
  39. data/lib/rbs/namespace.rb +0 -7
  40. data/lib/rbs/parser_aux.rb +5 -0
  41. data/lib/rbs/type_name.rb +0 -7
  42. data/lib/rbs/types.rb +3 -1
  43. data/lib/rbs/unit_test/convertibles.rb +1 -0
  44. data/lib/rbs/version.rb +1 -1
  45. data/sig/environment.rbs +3 -0
  46. data/sig/namespace.rbs +0 -5
  47. data/sig/parser.rbs +20 -0
  48. data/sig/typename.rbs +0 -5
  49. data/sig/types.rbs +4 -1
  50. data/src/ast.c +216 -214
  51. data/src/lexer.c +2923 -2675
  52. data/src/lexstate.c +157 -157
  53. data/src/location.c +40 -40
  54. data/src/parser.c +2591 -2586
  55. data/src/string.c +2 -2
  56. data/src/util/rbs_allocator.c +7 -9
  57. data/src/util/rbs_assert.c +9 -9
  58. data/src/util/rbs_constant_pool.c +5 -7
  59. data/src/util/rbs_encoding.c +20095 -4056
  60. data/src/util/rbs_unescape.c +33 -32
  61. data/stdlib/json/0/json.rbs +9 -43
  62. data/stdlib/ripper/0/ripper.rbs +3 -0
  63. data/stdlib/socket/0/addrinfo.rbs +2 -2
  64. metadata +8 -2
data/src/string.c CHANGED
@@ -12,7 +12,7 @@ unsigned int rbs_utf8_string_to_codepoint(const rbs_string_t string) {
12
12
  const char *s = string.start;
13
13
  const char *end = string.end;
14
14
 
15
- if (s >= end) return 0; // End of string
15
+ if (s >= end) return 0; // End of string
16
16
 
17
17
  if ((*s & 0x80) == 0) {
18
18
  // Single byte character (0xxxxxxx)
@@ -31,7 +31,7 @@ unsigned int rbs_utf8_string_to_codepoint(const rbs_string_t string) {
31
31
  remaining_bytes = 3;
32
32
  } else {
33
33
  // Invalid UTF-8 sequence
34
- return 0xFFFD; // Unicode replacement character
34
+ return 0xFFFD; // Unicode replacement character
35
35
  }
36
36
 
37
37
  s++;
@@ -15,18 +15,17 @@
15
15
  #include <inttypes.h>
16
16
 
17
17
  #ifdef _WIN32
18
- #include <windows.h>
18
+ #include <windows.h>
19
19
  #else
20
- #include <unistd.h>
21
- #include <sys/types.h>
22
- #include <sys/mman.h>
20
+ #include <unistd.h>
21
+ #include <sys/types.h>
22
+ #include <sys/mman.h>
23
23
  #endif
24
24
 
25
25
  #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun)
26
26
  #define MAP_ANONYMOUS MAP_ANON
27
27
  #endif
28
28
 
29
-
30
29
  struct rbs_allocator {
31
30
  uintptr_t heap_ptr;
32
31
  uintptr_t size;
@@ -49,8 +48,7 @@ static void *map_memory(size_t size) {
49
48
  LPVOID result = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
50
49
  rbs_assert(result != NULL, "VirtualAlloc failed");
51
50
  #else
52
- void *result = mmap(NULL, size, PROT_READ | PROT_WRITE,
53
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
51
+ void *result = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
54
52
  rbs_assert(result != MAP_FAILED, "mmap failed");
55
53
  #endif
56
54
  return result;
@@ -103,8 +101,8 @@ rbs_allocator_t *rbs_allocator_init(void) {
103
101
  guard_page(last_page, page_size);
104
102
  uintptr_t start = (uintptr_t) mem;
105
103
  rbs_allocator_t header = (rbs_allocator_t) {
106
- .heap_ptr = start + sizeof header,
107
- .size = size + page_size,
104
+ .heap_ptr = start + sizeof header,
105
+ .size = size + page_size,
108
106
  };
109
107
  memcpy(mem, &header, sizeof header);
110
108
  return (rbs_allocator_t *) mem;
@@ -6,14 +6,14 @@
6
6
  #include <stdbool.h>
7
7
 
8
8
  void rbs_assert(bool condition, const char *fmt, ...) {
9
- if (condition) {
10
- return;
11
- }
9
+ if (condition) {
10
+ return;
11
+ }
12
12
 
13
- va_list args;
14
- va_start(args, fmt);
15
- vfprintf(stderr, fmt, args);
16
- va_end(args);
17
- fprintf(stderr, "\n");
18
- exit(EXIT_FAILURE);
13
+ va_list args;
14
+ va_start(args, fmt);
15
+ vfprintf(stderr, fmt, args);
16
+ va_end(args);
17
+ fprintf(stderr, "\n");
18
+ exit(EXIT_FAILURE);
19
19
  }
@@ -58,7 +58,7 @@ rbs_constant_pool_resize(rbs_constant_pool_t *pool) {
58
58
  if (next == NULL) return false;
59
59
 
60
60
  rbs_constant_pool_bucket_t *next_buckets = next;
61
- rbs_constant_t *next_constants = (void *)(((char *) next) + next_capacity * sizeof(rbs_constant_pool_bucket_t));
61
+ rbs_constant_t *next_constants = (void *) (((char *) next) + next_capacity * sizeof(rbs_constant_pool_bucket_t));
62
62
 
63
63
  // For each bucket in the current constant pool, find the index in the
64
64
  // next constant pool, and insert it.
@@ -96,14 +96,13 @@ rbs_constant_pool_resize(rbs_constant_pool_t *pool) {
96
96
  }
97
97
 
98
98
  // This storage is initialized by `Init_rbs_extension()` in `main.c`.
99
- static rbs_constant_pool_t RBS_GLOBAL_CONSTANT_POOL_STORAGE = {};
99
+ static rbs_constant_pool_t RBS_GLOBAL_CONSTANT_POOL_STORAGE = { 0 };
100
100
  rbs_constant_pool_t *RBS_GLOBAL_CONSTANT_POOL = &RBS_GLOBAL_CONSTANT_POOL_STORAGE;
101
101
 
102
102
  /**
103
103
  * Initialize a new constant pool with a given capacity.
104
104
  */
105
- bool
106
- rbs_constant_pool_init(rbs_constant_pool_t *pool, uint32_t capacity) {
105
+ bool rbs_constant_pool_init(rbs_constant_pool_t *pool, uint32_t capacity) {
107
106
  const uint32_t maximum = (~((uint32_t) 0));
108
107
  if (capacity >= ((maximum / 2) + 1)) return false;
109
108
 
@@ -113,7 +112,7 @@ rbs_constant_pool_init(rbs_constant_pool_t *pool, uint32_t capacity) {
113
112
  if (memory == NULL) return false;
114
113
 
115
114
  pool->buckets = memory;
116
- pool->constants = (void *)(((char *)memory) + capacity * sizeof(rbs_constant_pool_bucket_t));
115
+ pool->constants = (void *) (((char *) memory) + capacity * sizeof(rbs_constant_pool_bucket_t));
117
116
  pool->size = 0;
118
117
  pool->capacity = capacity;
119
118
  return true;
@@ -256,8 +255,7 @@ rbs_constant_pool_insert_constant(rbs_constant_pool_t *pool, const uint8_t *star
256
255
  /**
257
256
  * Free the memory associated with a constant pool.
258
257
  */
259
- void
260
- rbs_constant_pool_free(rbs_constant_pool_t *pool) {
258
+ void rbs_constant_pool_free(rbs_constant_pool_t *pool) {
261
259
  // For each constant in the current constant pool, free the contents if the
262
260
  // contents are owned.
263
261
  for (uint32_t index = 0; index < pool->capacity; index++) {