yarp 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -1
  3. data/Makefile +5 -1
  4. data/config.yml +156 -125
  5. data/docs/encoding.md +5 -5
  6. data/docs/serialization.md +2 -2
  7. data/ext/yarp/api_node.c +142 -98
  8. data/ext/yarp/extension.c +21 -7
  9. data/ext/yarp/extension.h +1 -1
  10. data/include/yarp/ast.h +327 -18
  11. data/include/yarp/defines.h +2 -1
  12. data/include/yarp/diagnostic.h +3 -3
  13. data/include/yarp/enc/yp_encoding.h +10 -10
  14. data/include/yarp/parser.h +19 -19
  15. data/include/yarp/regexp.h +1 -1
  16. data/include/yarp/unescape.h +4 -4
  17. data/include/yarp/util/yp_buffer.h +3 -0
  18. data/include/yarp/util/yp_char.h +16 -16
  19. data/include/yarp/util/yp_constant_pool.h +2 -2
  20. data/include/yarp/util/yp_newline_list.h +5 -5
  21. data/include/yarp/util/yp_string.h +4 -4
  22. data/include/yarp/util/yp_string_list.h +0 -3
  23. data/include/yarp/util/yp_strpbrk.h +1 -1
  24. data/include/yarp/version.h +2 -2
  25. data/include/yarp.h +5 -4
  26. data/lib/yarp/desugar_visitor.rb +59 -122
  27. data/lib/yarp/node.rb +230 -240
  28. data/lib/yarp/serialize.rb +16 -16
  29. data/lib/yarp.rb +5 -5
  30. data/src/diagnostic.c +1 -1
  31. data/src/enc/yp_big5.c +15 -42
  32. data/src/enc/yp_euc_jp.c +16 -43
  33. data/src/enc/yp_gbk.c +19 -46
  34. data/src/enc/yp_shift_jis.c +16 -43
  35. data/src/enc/yp_tables.c +36 -38
  36. data/src/enc/yp_unicode.c +20 -25
  37. data/src/enc/yp_windows_31j.c +16 -43
  38. data/src/node.c +1271 -899
  39. data/src/prettyprint.c +87 -48
  40. data/src/regexp.c +21 -21
  41. data/src/serialize.c +28 -15
  42. data/src/unescape.c +151 -121
  43. data/src/util/yp_buffer.c +7 -2
  44. data/src/util/yp_char.c +34 -34
  45. data/src/util/yp_constant_pool.c +4 -4
  46. data/src/util/yp_memchr.c +1 -1
  47. data/src/util/yp_newline_list.c +5 -4
  48. data/src/util/yp_string.c +22 -20
  49. data/src/util/yp_string_list.c +0 -6
  50. data/src/util/yp_strncasecmp.c +3 -6
  51. data/src/util/yp_strpbrk.c +8 -8
  52. data/src/yarp.c +355 -216
  53. data/yarp.gemspec +1 -1
  54. metadata +2 -2
data/src/serialize.c CHANGED
@@ -45,7 +45,7 @@ yp_serialize_string(yp_parser_t *parser, yp_string_t *string, yp_buffer_t *buffe
45
45
  uint32_t length = yp_sizet_to_u32(yp_string_length(string));
46
46
  yp_buffer_append_u8(buffer, 2);
47
47
  yp_buffer_append_u32(buffer, length);
48
- yp_buffer_append_str(buffer, yp_string_source(string), length);
48
+ yp_buffer_append_bytes(buffer, yp_string_source(string), length);
49
49
  break;
50
50
  }
51
51
  case YP_STRING_MAPPED:
@@ -343,7 +343,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
343
343
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->target, buffer);
344
344
  yp_serialize_location(parser, &((yp_call_operator_write_node_t *)node)->operator_loc, buffer);
345
345
  yp_serialize_node(parser, (yp_node_t *)((yp_call_operator_write_node_t *)node)->value, buffer);
346
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_call_operator_write_node_t *)node)->operator_id));
346
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_call_operator_write_node_t *)node)->operator));
347
347
  break;
348
348
  }
349
349
  case YP_NODE_CAPTURE_PATTERN_NODE: {
@@ -401,12 +401,14 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
401
401
  break;
402
402
  }
403
403
  case YP_NODE_CLASS_VARIABLE_AND_WRITE_NODE: {
404
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_and_write_node_t *)node)->name));
404
405
  yp_serialize_location(parser, &((yp_class_variable_and_write_node_t *)node)->name_loc, buffer);
405
406
  yp_serialize_location(parser, &((yp_class_variable_and_write_node_t *)node)->operator_loc, buffer);
406
407
  yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_and_write_node_t *)node)->value, buffer);
407
408
  break;
408
409
  }
409
410
  case YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
411
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_operator_write_node_t *)node)->name));
410
412
  yp_serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->name_loc, buffer);
411
413
  yp_serialize_location(parser, &((yp_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
412
414
  yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_operator_write_node_t *)node)->value, buffer);
@@ -414,18 +416,22 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
414
416
  break;
415
417
  }
416
418
  case YP_NODE_CLASS_VARIABLE_OR_WRITE_NODE: {
419
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_or_write_node_t *)node)->name));
417
420
  yp_serialize_location(parser, &((yp_class_variable_or_write_node_t *)node)->name_loc, buffer);
418
421
  yp_serialize_location(parser, &((yp_class_variable_or_write_node_t *)node)->operator_loc, buffer);
419
422
  yp_serialize_node(parser, (yp_node_t *)((yp_class_variable_or_write_node_t *)node)->value, buffer);
420
423
  break;
421
424
  }
422
425
  case YP_NODE_CLASS_VARIABLE_READ_NODE: {
426
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_read_node_t *)node)->name));
423
427
  break;
424
428
  }
425
429
  case YP_NODE_CLASS_VARIABLE_TARGET_NODE: {
430
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_target_node_t *)node)->name));
426
431
  break;
427
432
  }
428
433
  case YP_NODE_CLASS_VARIABLE_WRITE_NODE: {
434
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_class_variable_write_node_t *)node)->name));
429
435
  yp_serialize_location(parser, &((yp_class_variable_write_node_t *)node)->name_loc, buffer);
430
436
  if (((yp_class_variable_write_node_t *)node)->value == NULL) {
431
437
  yp_buffer_append_u8(buffer, 0);
@@ -743,8 +749,8 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
743
749
  }
744
750
  case YP_NODE_GLOBAL_VARIABLE_WRITE_NODE: {
745
751
  yp_serialize_location(parser, &((yp_global_variable_write_node_t *)node)->name_loc, buffer);
746
- yp_serialize_location(parser, &((yp_global_variable_write_node_t *)node)->operator_loc, buffer);
747
752
  yp_serialize_node(parser, (yp_node_t *)((yp_global_variable_write_node_t *)node)->value, buffer);
753
+ yp_serialize_location(parser, &((yp_global_variable_write_node_t *)node)->operator_loc, buffer);
748
754
  break;
749
755
  }
750
756
  case YP_NODE_HASH_NODE: {
@@ -834,12 +840,14 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
834
840
  break;
835
841
  }
836
842
  case YP_NODE_INSTANCE_VARIABLE_AND_WRITE_NODE: {
843
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_and_write_node_t *)node)->name));
837
844
  yp_serialize_location(parser, &((yp_instance_variable_and_write_node_t *)node)->name_loc, buffer);
838
845
  yp_serialize_location(parser, &((yp_instance_variable_and_write_node_t *)node)->operator_loc, buffer);
839
846
  yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_and_write_node_t *)node)->value, buffer);
840
847
  break;
841
848
  }
842
849
  case YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
850
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_operator_write_node_t *)node)->name));
843
851
  yp_serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
844
852
  yp_serialize_location(parser, &((yp_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
845
853
  yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_operator_write_node_t *)node)->value, buffer);
@@ -847,18 +855,22 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
847
855
  break;
848
856
  }
849
857
  case YP_NODE_INSTANCE_VARIABLE_OR_WRITE_NODE: {
858
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_or_write_node_t *)node)->name));
850
859
  yp_serialize_location(parser, &((yp_instance_variable_or_write_node_t *)node)->name_loc, buffer);
851
860
  yp_serialize_location(parser, &((yp_instance_variable_or_write_node_t *)node)->operator_loc, buffer);
852
861
  yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_or_write_node_t *)node)->value, buffer);
853
862
  break;
854
863
  }
855
864
  case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
865
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_read_node_t *)node)->name));
856
866
  break;
857
867
  }
858
868
  case YP_NODE_INSTANCE_VARIABLE_TARGET_NODE: {
869
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_target_node_t *)node)->name));
859
870
  break;
860
871
  }
861
872
  case YP_NODE_INSTANCE_VARIABLE_WRITE_NODE: {
873
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_instance_variable_write_node_t *)node)->name));
862
874
  yp_serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->name_loc, buffer);
863
875
  yp_serialize_node(parser, (yp_node_t *)((yp_instance_variable_write_node_t *)node)->value, buffer);
864
876
  yp_serialize_location(parser, &((yp_instance_variable_write_node_t *)node)->operator_loc, buffer);
@@ -980,7 +992,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
980
992
  yp_serialize_location(parser, &((yp_local_variable_and_write_node_t *)node)->name_loc, buffer);
981
993
  yp_serialize_location(parser, &((yp_local_variable_and_write_node_t *)node)->operator_loc, buffer);
982
994
  yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_and_write_node_t *)node)->value, buffer);
983
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_and_write_node_t *)node)->constant_id));
995
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_and_write_node_t *)node)->name));
984
996
  yp_buffer_append_u32(buffer, ((yp_local_variable_and_write_node_t *)node)->depth);
985
997
  break;
986
998
  }
@@ -988,8 +1000,8 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
988
1000
  yp_serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->name_loc, buffer);
989
1001
  yp_serialize_location(parser, &((yp_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
990
1002
  yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_operator_write_node_t *)node)->value, buffer);
991
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->constant_id));
992
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->operator_id));
1003
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->name));
1004
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_operator_write_node_t *)node)->operator));
993
1005
  yp_buffer_append_u32(buffer, ((yp_local_variable_operator_write_node_t *)node)->depth);
994
1006
  break;
995
1007
  }
@@ -997,25 +1009,25 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
997
1009
  yp_serialize_location(parser, &((yp_local_variable_or_write_node_t *)node)->name_loc, buffer);
998
1010
  yp_serialize_location(parser, &((yp_local_variable_or_write_node_t *)node)->operator_loc, buffer);
999
1011
  yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_or_write_node_t *)node)->value, buffer);
1000
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_or_write_node_t *)node)->constant_id));
1012
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_or_write_node_t *)node)->name));
1001
1013
  yp_buffer_append_u32(buffer, ((yp_local_variable_or_write_node_t *)node)->depth);
1002
1014
  break;
1003
1015
  }
1004
1016
  case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
1005
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_read_node_t *)node)->constant_id));
1017
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_read_node_t *)node)->name));
1006
1018
  yp_buffer_append_u32(buffer, ((yp_local_variable_read_node_t *)node)->depth);
1007
1019
  break;
1008
1020
  }
1009
1021
  case YP_NODE_LOCAL_VARIABLE_TARGET_NODE: {
1010
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_target_node_t *)node)->constant_id));
1022
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_target_node_t *)node)->name));
1011
1023
  yp_buffer_append_u32(buffer, ((yp_local_variable_target_node_t *)node)->depth);
1012
1024
  break;
1013
1025
  }
1014
1026
  case YP_NODE_LOCAL_VARIABLE_WRITE_NODE: {
1015
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_write_node_t *)node)->constant_id));
1027
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_local_variable_write_node_t *)node)->name));
1016
1028
  yp_buffer_append_u32(buffer, ((yp_local_variable_write_node_t *)node)->depth);
1017
- yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value, buffer);
1018
1029
  yp_serialize_location(parser, &((yp_local_variable_write_node_t *)node)->name_loc, buffer);
1030
+ yp_serialize_node(parser, (yp_node_t *)((yp_local_variable_write_node_t *)node)->value, buffer);
1019
1031
  yp_serialize_location(parser, &((yp_local_variable_write_node_t *)node)->operator_loc, buffer);
1020
1032
  break;
1021
1033
  }
@@ -1100,10 +1112,11 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1100
1112
  break;
1101
1113
  }
1102
1114
  case YP_NODE_NUMBERED_REFERENCE_READ_NODE: {
1115
+ yp_buffer_append_u32(buffer, ((yp_numbered_reference_read_node_t *)node)->number);
1103
1116
  break;
1104
1117
  }
1105
1118
  case YP_NODE_OPTIONAL_PARAMETER_NODE: {
1106
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_optional_parameter_node_t *)node)->constant_id));
1119
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_optional_parameter_node_t *)node)->name));
1107
1120
  yp_serialize_location(parser, &((yp_optional_parameter_node_t *)node)->name_loc, buffer);
1108
1121
  yp_serialize_location(parser, &((yp_optional_parameter_node_t *)node)->operator_loc, buffer);
1109
1122
  yp_serialize_node(parser, (yp_node_t *)((yp_optional_parameter_node_t *)node)->value, buffer);
@@ -1247,7 +1260,7 @@ yp_serialize_node(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer) {
1247
1260
  break;
1248
1261
  }
1249
1262
  case YP_NODE_REQUIRED_PARAMETER_NODE: {
1250
- yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_required_parameter_node_t *)node)->constant_id));
1263
+ yp_buffer_append_u32(buffer, yp_sizet_to_u32(((yp_required_parameter_node_t *)node)->name));
1251
1264
  break;
1252
1265
  }
1253
1266
  case YP_NODE_RESCUE_MODIFIER_NODE: {
@@ -1643,7 +1656,7 @@ serialize_token(void *data, yp_parser_t *parser, yp_token_t *token) {
1643
1656
  }
1644
1657
 
1645
1658
  YP_EXPORTED_FUNCTION void
1646
- yp_lex_serialize(const char *source, size_t size, const char *filepath, yp_buffer_t *buffer) {
1659
+ yp_lex_serialize(const uint8_t *source, size_t size, const char *filepath, yp_buffer_t *buffer) {
1647
1660
  yp_parser_t parser;
1648
1661
  yp_parser_init(&parser, source, size, filepath);
1649
1662
 
@@ -1670,7 +1683,7 @@ yp_lex_serialize(const char *source, size_t size, const char *filepath, yp_buffe
1670
1683
  // Parse and serialize both the AST and the tokens represented by the given
1671
1684
  // source to the given buffer.
1672
1685
  YP_EXPORTED_FUNCTION void
1673
- yp_parse_lex_serialize(const char *source, size_t size, yp_buffer_t *buffer, const char *metadata) {
1686
+ yp_parse_lex_serialize(const uint8_t *source, size_t size, yp_buffer_t *buffer, const char *metadata) {
1674
1687
  yp_parser_t parser;
1675
1688
  yp_parser_init(&parser, source, size, NULL);
1676
1689
  if (metadata) yp_parser_metadata(&parser, metadata);