yarp 0.6.0 → 0.8.0

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -0
  3. data/CONTRIBUTING.md +4 -0
  4. data/{Makefile.in → Makefile} +5 -4
  5. data/README.md +6 -3
  6. data/config.yml +83 -274
  7. data/docs/build_system.md +4 -15
  8. data/docs/building.md +1 -5
  9. data/docs/encoding.md +1 -0
  10. data/docs/{extension.md → ruby_api.md} +6 -3
  11. data/docs/serialization.md +71 -24
  12. data/ext/yarp/api_node.c +173 -585
  13. data/ext/yarp/extconf.rb +15 -10
  14. data/ext/yarp/extension.c +4 -2
  15. data/ext/yarp/extension.h +1 -1
  16. data/include/yarp/ast.h +167 -306
  17. data/include/yarp/defines.h +5 -15
  18. data/include/yarp/enc/yp_encoding.h +1 -0
  19. data/include/yarp/unescape.h +1 -1
  20. data/include/yarp/util/yp_buffer.h +9 -0
  21. data/include/yarp/util/yp_constant_pool.h +3 -0
  22. data/include/yarp/util/yp_list.h +7 -7
  23. data/include/yarp/util/yp_newline_list.h +4 -0
  24. data/include/yarp/util/yp_state_stack.h +1 -1
  25. data/include/yarp/util/yp_string.h +5 -1
  26. data/include/yarp/version.h +2 -3
  27. data/include/yarp.h +4 -2
  28. data/lib/yarp/ffi.rb +226 -0
  29. data/lib/yarp/lex_compat.rb +16 -2
  30. data/lib/yarp/node.rb +594 -1437
  31. data/lib/yarp/ripper_compat.rb +3 -3
  32. data/lib/yarp/serialize.rb +312 -149
  33. data/lib/yarp.rb +167 -2
  34. data/src/enc/yp_unicode.c +9 -0
  35. data/src/node.c +92 -250
  36. data/src/prettyprint.c +81 -206
  37. data/src/serialize.c +124 -149
  38. data/src/unescape.c +29 -35
  39. data/src/util/yp_buffer.c +18 -0
  40. data/src/util/yp_list.c +7 -16
  41. data/src/util/yp_state_stack.c +0 -6
  42. data/src/util/yp_string.c +8 -17
  43. data/src/yarp.c +444 -717
  44. data/yarp.gemspec +5 -5
  45. metadata +6 -6
  46. data/config.h.in +0 -25
  47. data/configure +0 -4487
data/src/util/yp_list.c CHANGED
@@ -1,28 +1,15 @@
1
1
  #include "yarp/util/yp_list.h"
2
2
 
3
- // Initializes a new list.
4
- YP_EXPORTED_FUNCTION void
5
- yp_list_init(yp_list_t *list) {
6
- *list = (yp_list_t) { .head = NULL, .tail = NULL };
7
- }
8
-
9
3
  // Returns true if the given list is empty.
10
4
  YP_EXPORTED_FUNCTION bool
11
5
  yp_list_empty_p(yp_list_t *list) {
12
6
  return list->head == NULL;
13
7
  }
14
8
 
15
- YP_EXPORTED_FUNCTION uint32_t
9
+ // Returns the size of the list.
10
+ YP_EXPORTED_FUNCTION size_t
16
11
  yp_list_size(yp_list_t *list) {
17
- yp_list_node_t *node = list->head;
18
- uint32_t length = 0;
19
-
20
- while (node != NULL) {
21
- length++;
22
- node = node->next;
23
- }
24
-
25
- return length;
12
+ return list->size;
26
13
  }
27
14
 
28
15
  // Append a node to the given list.
@@ -33,7 +20,9 @@ yp_list_append(yp_list_t *list, yp_list_node_t *node) {
33
20
  } else {
34
21
  list->tail->next = node;
35
22
  }
23
+
36
24
  list->tail = node;
25
+ list->size++;
37
26
  }
38
27
 
39
28
  // Deallocate the internal state of the given list.
@@ -47,4 +36,6 @@ yp_list_free(yp_list_t *list) {
47
36
  free(node);
48
37
  node = next;
49
38
  }
39
+
40
+ list->size = 0;
50
41
  }
@@ -1,11 +1,5 @@
1
1
  #include "yarp/util/yp_state_stack.h"
2
2
 
3
- // Initializes the state stack to an empty stack.
4
- void
5
- yp_state_stack_init(yp_state_stack_t *stack) {
6
- *stack = 0;
7
- }
8
-
9
3
  // Pushes a value onto the stack.
10
4
  void
11
5
  yp_state_stack_push(yp_state_stack_t *stack, bool value) {
data/src/util/yp_string.c CHANGED
@@ -97,10 +97,8 @@ yp_string_free(yp_string_t *string) {
97
97
  void *memory = (void *) string->source;
98
98
  #if defined(_WIN32)
99
99
  UnmapViewOfFile(memory);
100
- #elif defined(HAVE_MMAP)
101
- munmap(memory, string->length);
102
100
  #else
103
- free(memory);
101
+ munmap(memory, string->length);
104
102
  #endif
105
103
  }
106
104
  }
@@ -180,28 +178,21 @@ yp_string_mapped_init(yp_string_t *string, const char *filepath) {
180
178
  return true;
181
179
  }
182
180
 
183
- #ifdef HAVE_MMAP
184
181
  source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
185
182
  if (source == MAP_FAILED) {
186
183
  perror("Map failed");
187
184
  return false;
188
185
  }
189
- #else
190
- source = malloc(size);
191
- if (source == NULL) {
192
- return false;
193
- }
194
-
195
- ssize_t read_size = read(fd, (void *) source, size);
196
- if (read_size < 0 || (size_t)read_size != size) {
197
- perror("Read size is incorrect");
198
- free((void *) source);
199
- return false;
200
- }
201
- #endif
202
186
 
203
187
  close(fd);
204
188
  yp_string_mapped_init_internal(string, source, size);
205
189
  return true;
206
190
  #endif
207
191
  }
192
+
193
+ // Returns the size of the yp_string_t struct. This is necessary to allocate the
194
+ // correct amount of memory in the FFI backend.
195
+ YP_EXPORTED_FUNCTION size_t
196
+ yp_string_sizeof(void) {
197
+ return sizeof(yp_string_t);
198
+ }