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.
- checksums.yaml +4 -4
- data/.clang-format +74 -0
- data/.clangd +2 -0
- data/.github/workflows/c-check.yml +51 -0
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +28 -17
- data/.github/workflows/typecheck.yml +0 -2
- data/.gitignore +4 -0
- data/.rubocop.yml +1 -1
- data/.vscode/extensions.json +5 -0
- data/.vscode/settings.json +19 -0
- data/README.md +37 -0
- data/Rakefile +90 -0
- data/config.yml +1 -1
- data/core/enumerable.rbs +9 -0
- data/core/io.rbs +4 -4
- data/core/thread.rbs +0 -7
- data/ext/rbs_extension/ast_translation.c +1010 -1074
- data/ext/rbs_extension/ast_translation.h +4 -0
- data/ext/rbs_extension/class_constants.c +78 -74
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +15 -1
- data/ext/rbs_extension/legacy_location.c +173 -172
- data/ext/rbs_extension/legacy_location.h +8 -3
- data/ext/rbs_extension/main.c +315 -273
- data/ext/rbs_extension/rbs_extension.h +3 -0
- data/ext/rbs_extension/rbs_string_bridging.h +4 -0
- data/include/rbs/ast.h +11 -12
- data/include/rbs/defines.h +11 -12
- data/include/rbs/lexer.h +108 -108
- data/include/rbs/location.h +14 -14
- data/include/rbs/parser.h +21 -19
- data/include/rbs/string.h +3 -3
- data/include/rbs/util/rbs_allocator.h +14 -14
- data/include/rbs/util/rbs_constant_pool.h +3 -3
- data/include/rbs/util/rbs_encoding.h +1 -1
- data/lib/rbs/environment.rb +4 -0
- data/lib/rbs/namespace.rb +0 -7
- data/lib/rbs/parser_aux.rb +5 -0
- data/lib/rbs/type_name.rb +0 -7
- data/lib/rbs/types.rb +3 -1
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/environment.rbs +3 -0
- data/sig/namespace.rbs +0 -5
- data/sig/parser.rbs +20 -0
- data/sig/typename.rbs +0 -5
- data/sig/types.rbs +4 -1
- data/src/ast.c +216 -214
- data/src/lexer.c +2923 -2675
- data/src/lexstate.c +157 -157
- data/src/location.c +40 -40
- data/src/parser.c +2591 -2586
- data/src/string.c +2 -2
- data/src/util/rbs_allocator.c +7 -9
- data/src/util/rbs_assert.c +9 -9
- data/src/util/rbs_constant_pool.c +5 -7
- data/src/util/rbs_encoding.c +20095 -4056
- data/src/util/rbs_unescape.c +33 -32
- data/stdlib/json/0/json.rbs +9 -43
- data/stdlib/ripper/0/ripper.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +2 -2
- 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;
|
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;
|
34
|
+
return 0xFFFD; // Unicode replacement character
|
35
35
|
}
|
36
36
|
|
37
37
|
s++;
|
data/src/util/rbs_allocator.c
CHANGED
@@ -15,18 +15,17 @@
|
|
15
15
|
#include <inttypes.h>
|
16
16
|
|
17
17
|
#ifdef _WIN32
|
18
|
-
|
18
|
+
#include <windows.h>
|
19
19
|
#else
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
107
|
-
|
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;
|
data/src/util/rbs_assert.c
CHANGED
@@ -6,14 +6,14 @@
|
|
6
6
|
#include <stdbool.h>
|
7
7
|
|
8
8
|
void rbs_assert(bool condition, const char *fmt, ...) {
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if (condition) {
|
10
|
+
return;
|
11
|
+
}
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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++) {
|