kanayago 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
 - data/.rubocop.yml +12 -0
 - data/.ruby-version +1 -0
 - data/README.md +20 -29
 - data/Rakefile +43 -96
 - data/ext/kanayago/extconf.rb +6 -0
 - data/ext/kanayago/id.h +12 -5
 - data/ext/kanayago/id_table.h +15 -0
 - data/ext/kanayago/include/ruby/st.h +199 -0
 - data/ext/kanayago/internal/array.h +3 -0
 - data/ext/kanayago/internal/basic_operators.h +1 -0
 - data/ext/kanayago/internal/bignum.h +1 -0
 - data/ext/kanayago/internal/bits.h +82 -0
 - data/ext/kanayago/internal/encoding.h +4 -1
 - data/ext/kanayago/internal/error.h +33 -0
 - data/ext/kanayago/internal/fixnum.h +1 -0
 - data/ext/kanayago/internal/gc.h +47 -11
 - data/ext/kanayago/internal/hash.h +3 -0
 - data/ext/kanayago/internal/imemo.h +93 -32
 - data/ext/kanayago/internal/io.h +30 -7
 - data/ext/kanayago/internal/namespace.h +81 -0
 - data/ext/kanayago/internal/numeric.h +1 -0
 - data/ext/kanayago/internal/parse.h +17 -3
 - data/ext/kanayago/internal/re.h +7 -2
 - data/ext/kanayago/internal/sanitizers.h +88 -39
 - data/ext/kanayago/internal/set_table.h +70 -0
 - data/ext/kanayago/internal/string.h +33 -16
 - data/ext/kanayago/internal/symbol.h +4 -3
 - data/ext/kanayago/internal/thread.h +42 -9
 - data/ext/kanayago/internal/variable.h +13 -11
 - data/ext/kanayago/internal/vm.h +4 -5
 - data/ext/kanayago/internal.h +0 -3
 - data/ext/kanayago/kanayago.c +554 -235
 - data/ext/kanayago/kanayago.h +5 -0
 - data/ext/kanayago/literal_node.c +343 -0
 - data/ext/kanayago/literal_node.h +30 -0
 - data/ext/kanayago/method.h +18 -2
 - data/ext/kanayago/node.c +7 -1
 - data/ext/kanayago/node.h +14 -3
 - data/ext/kanayago/parse.c +7602 -7156
 - data/ext/kanayago/parse.h +39 -39
 - data/ext/kanayago/parser_st.c +2 -1
 - data/ext/kanayago/pattern_node.c +78 -0
 - data/ext/kanayago/pattern_node.h +13 -0
 - data/ext/kanayago/ruby_atomic.h +43 -0
 - data/ext/kanayago/ruby_parser.c +7 -35
 - data/ext/kanayago/rubyparser.h +83 -80
 - data/ext/kanayago/scope_node.c +34 -0
 - data/ext/kanayago/scope_node.h +8 -0
 - data/ext/kanayago/shape.h +321 -111
 - data/ext/kanayago/st.c +905 -21
 - data/ext/kanayago/statement_node.c +795 -0
 - data/ext/kanayago/statement_node.h +66 -0
 - data/ext/kanayago/string_node.c +192 -0
 - data/ext/kanayago/string_node.h +19 -0
 - data/ext/kanayago/symbol.h +2 -9
 - data/ext/kanayago/thread_pthread.h +10 -3
 - data/ext/kanayago/universal_parser.c +1 -20
 - data/ext/kanayago/variable_node.c +72 -0
 - data/ext/kanayago/variable_node.h +12 -0
 - data/ext/kanayago/vm_core.h +205 -71
 - data/lib/kanayago/literal_node.rb +87 -0
 - data/lib/kanayago/pattern_node.rb +19 -0
 - data/lib/kanayago/statement_node.rb +222 -0
 - data/lib/kanayago/string_node.rb +43 -0
 - data/lib/kanayago/variable_node.rb +23 -0
 - data/lib/kanayago/version.rb +1 -1
 - data/lib/kanayago.rb +22 -0
 - data/patch/3.4/copy_target.rb +78 -0
 - data/patch/3.4/kanayago.patch +162 -0
 - data/patch/head/copy_target.rb +84 -0
 - data/patch/head/kanayago.patch +162 -0
 - data/sample/minitest_generator.rb +266 -0
 - data/sample/test_generator.rb +272 -0
 - data/typeprof.conf.json +9 -0
 - metadata +32 -4
 - data/ext/kanayago/parse.tmp.y +0 -16145
 
    
        data/ext/kanayago/parse.h
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            /* A Bison parser, made by Lrama 0. 
     | 
| 
      
 1 
     | 
    
         
            +
            /* A Bison parser, made by Lrama 0.7.0.  */
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            /* Bison interface for Yacc-like parsers in C
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -34,8 +34,8 @@ 
     | 
|
| 
       34 
34 
     | 
    
         
             
            /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
         
     | 
| 
       35 
35 
     | 
    
         
             
               especially those whose name start with YY_ or yy_.  They are
         
     | 
| 
       36 
36 
     | 
    
         
             
               private implementation details that can be changed or removed.  */
         
     | 
| 
       37 
     | 
    
         
            -
            #ifndef  
     | 
| 
       38 
     | 
    
         
            -
            # define  
     | 
| 
      
 37 
     | 
    
         
            +
            #ifndef YY_YY_PARSE_H_INCLUDED
         
     | 
| 
      
 38 
     | 
    
         
            +
            # define YY_YY_PARSE_H_INCLUDED
         
     | 
| 
       39 
39 
     | 
    
         
             
            /* Debug traces.  */
         
     | 
| 
       40 
40 
     | 
    
         
             
            #ifndef YYDEBUG
         
     | 
| 
       41 
41 
     | 
    
         
             
            # define YYDEBUG 0
         
     | 
| 
         @@ -149,39 +149,38 @@ extern int yydebug; 
     | 
|
| 
       149 
149 
     | 
    
         
             
                tASSOC = 327,                  /* "=>"  */
         
     | 
| 
       150 
150 
     | 
    
         
             
                tLPAREN = 328,                 /* "("  */
         
     | 
| 
       151 
151 
     | 
    
         
             
                tLPAREN_ARG = 329,             /* "( arg"  */
         
     | 
| 
       152 
     | 
    
         
            -
                 
     | 
| 
       153 
     | 
    
         
            -
                 
     | 
| 
       154 
     | 
    
         
            -
                 
     | 
| 
       155 
     | 
    
         
            -
                 
     | 
| 
       156 
     | 
    
         
            -
                 
     | 
| 
       157 
     | 
    
         
            -
                 
     | 
| 
       158 
     | 
    
         
            -
                 
     | 
| 
       159 
     | 
    
         
            -
                 
     | 
| 
       160 
     | 
    
         
            -
                 
     | 
| 
       161 
     | 
    
         
            -
                 
     | 
| 
       162 
     | 
    
         
            -
                 
     | 
| 
       163 
     | 
    
         
            -
                 
     | 
| 
       164 
     | 
    
         
            -
                 
     | 
| 
       165 
     | 
    
         
            -
                 
     | 
| 
       166 
     | 
    
         
            -
                 
     | 
| 
       167 
     | 
    
         
            -
                 
     | 
| 
       168 
     | 
    
         
            -
                 
     | 
| 
       169 
     | 
    
         
            -
                 
     | 
| 
       170 
     | 
    
         
            -
                 
     | 
| 
       171 
     | 
    
         
            -
                 
     | 
| 
       172 
     | 
    
         
            -
                 
     | 
| 
       173 
     | 
    
         
            -
                 
     | 
| 
       174 
     | 
    
         
            -
                 
     | 
| 
       175 
     | 
    
         
            -
                 
     | 
| 
       176 
     | 
    
         
            -
                 
     | 
| 
       177 
     | 
    
         
            -
                 
     | 
| 
       178 
     | 
    
         
            -
                 
     | 
| 
       179 
     | 
    
         
            -
                 
     | 
| 
       180 
     | 
    
         
            -
                 
     | 
| 
       181 
     | 
    
         
            -
                 
     | 
| 
       182 
     | 
    
         
            -
                 
     | 
| 
       183 
     | 
    
         
            -
                 
     | 
| 
       184 
     | 
    
         
            -
                tLAST_TOKEN = 362              /* tLAST_TOKEN  */
         
     | 
| 
      
 152 
     | 
    
         
            +
                tLBRACK = 330,                 /* "["  */
         
     | 
| 
      
 153 
     | 
    
         
            +
                tLBRACE = 331,                 /* "{"  */
         
     | 
| 
      
 154 
     | 
    
         
            +
                tLBRACE_ARG = 332,             /* "{ arg"  */
         
     | 
| 
      
 155 
     | 
    
         
            +
                tSTAR = 333,                   /* "*"  */
         
     | 
| 
      
 156 
     | 
    
         
            +
                tDSTAR = 334,                  /* "**arg"  */
         
     | 
| 
      
 157 
     | 
    
         
            +
                tAMPER = 335,                  /* "&"  */
         
     | 
| 
      
 158 
     | 
    
         
            +
                tLAMBDA = 336,                 /* "->"  */
         
     | 
| 
      
 159 
     | 
    
         
            +
                tSYMBEG = 337,                 /* "symbol literal"  */
         
     | 
| 
      
 160 
     | 
    
         
            +
                tSTRING_BEG = 338,             /* "string literal"  */
         
     | 
| 
      
 161 
     | 
    
         
            +
                tXSTRING_BEG = 339,            /* "backtick literal"  */
         
     | 
| 
      
 162 
     | 
    
         
            +
                tREGEXP_BEG = 340,             /* "regexp literal"  */
         
     | 
| 
      
 163 
     | 
    
         
            +
                tWORDS_BEG = 341,              /* "word list"  */
         
     | 
| 
      
 164 
     | 
    
         
            +
                tQWORDS_BEG = 342,             /* "verbatim word list"  */
         
     | 
| 
      
 165 
     | 
    
         
            +
                tSYMBOLS_BEG = 343,            /* "symbol list"  */
         
     | 
| 
      
 166 
     | 
    
         
            +
                tQSYMBOLS_BEG = 344,           /* "verbatim symbol list"  */
         
     | 
| 
      
 167 
     | 
    
         
            +
                tSTRING_END = 345,             /* "terminator"  */
         
     | 
| 
      
 168 
     | 
    
         
            +
                tSTRING_DEND = 346,            /* "'}'"  */
         
     | 
| 
      
 169 
     | 
    
         
            +
                tSTRING_DBEG = 347,            /* "'#{'"  */
         
     | 
| 
      
 170 
     | 
    
         
            +
                tSTRING_DVAR = 348,            /* tSTRING_DVAR  */
         
     | 
| 
      
 171 
     | 
    
         
            +
                tLAMBEG = 349,                 /* tLAMBEG  */
         
     | 
| 
      
 172 
     | 
    
         
            +
                tLABEL_END = 350,              /* tLABEL_END  */
         
     | 
| 
      
 173 
     | 
    
         
            +
                tIGNORED_NL = 351,             /* tIGNORED_NL  */
         
     | 
| 
      
 174 
     | 
    
         
            +
                tCOMMENT = 352,                /* tCOMMENT  */
         
     | 
| 
      
 175 
     | 
    
         
            +
                tEMBDOC_BEG = 353,             /* tEMBDOC_BEG  */
         
     | 
| 
      
 176 
     | 
    
         
            +
                tEMBDOC = 354,                 /* tEMBDOC  */
         
     | 
| 
      
 177 
     | 
    
         
            +
                tEMBDOC_END = 355,             /* tEMBDOC_END  */
         
     | 
| 
      
 178 
     | 
    
         
            +
                tHEREDOC_BEG = 356,            /* tHEREDOC_BEG  */
         
     | 
| 
      
 179 
     | 
    
         
            +
                tHEREDOC_END = 357,            /* tHEREDOC_END  */
         
     | 
| 
      
 180 
     | 
    
         
            +
                k__END__ = 358,                /* k__END__  */
         
     | 
| 
      
 181 
     | 
    
         
            +
                tLOWEST = 359,                 /* tLOWEST  */
         
     | 
| 
      
 182 
     | 
    
         
            +
                tUMINUS_NUM = 360,             /* tUMINUS_NUM  */
         
     | 
| 
      
 183 
     | 
    
         
            +
                tLAST_TOKEN = 361              /* tLAST_TOKEN  */
         
     | 
| 
       185 
184 
     | 
    
         
             
              };
         
     | 
| 
       186 
185 
     | 
    
         
             
              typedef enum yytokentype yytoken_kind_t;
         
     | 
| 
       187 
186 
     | 
    
         
             
            #endif
         
     | 
| 
         @@ -190,7 +189,7 @@ extern int yydebug; 
     | 
|
| 
       190 
189 
     | 
    
         
             
            #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
         
     | 
| 
       191 
190 
     | 
    
         
             
            union YYSTYPE
         
     | 
| 
       192 
191 
     | 
    
         
             
            {
         
     | 
| 
       193 
     | 
    
         
            -
            #line  
     | 
| 
      
 192 
     | 
    
         
            +
            #line 2670 "parse.y"
         
     | 
| 
       194 
193 
     | 
    
         | 
| 
       195 
194 
     | 
    
         
             
                NODE *node;
         
     | 
| 
       196 
195 
     | 
    
         
             
                rb_node_fcall_t *node_fcall;
         
     | 
| 
         @@ -202,6 +201,7 @@ union YYSTYPE 
     | 
|
| 
       202 
201 
     | 
    
         
             
                rb_node_masgn_t *node_masgn;
         
     | 
| 
       203 
202 
     | 
    
         
             
                rb_node_def_temp_t *node_def_temp;
         
     | 
| 
       204 
203 
     | 
    
         
             
                rb_node_exits_t *node_exits;
         
     | 
| 
      
 204 
     | 
    
         
            +
                struct rb_locations_lambda_body_t *locations_lambda_body;
         
     | 
| 
       205 
205 
     | 
    
         
             
                ID id;
         
     | 
| 
       206 
206 
     | 
    
         
             
                int num;
         
     | 
| 
       207 
207 
     | 
    
         
             
                st_table *tbl;
         
     | 
| 
         @@ -211,7 +211,7 @@ union YYSTYPE 
     | 
|
| 
       211 
211 
     | 
    
         
             
                struct lex_context ctxt;
         
     | 
| 
       212 
212 
     | 
    
         
             
                enum lex_state_e state;
         
     | 
| 
       213 
213 
     | 
    
         | 
| 
       214 
     | 
    
         
            -
            #line 215 " 
     | 
| 
      
 214 
     | 
    
         
            +
            #line 215 "parse.h"
         
     | 
| 
       215 
215 
     | 
    
         | 
| 
       216 
216 
     | 
    
         
             
            };
         
     | 
| 
       217 
217 
     | 
    
         
             
            typedef union YYSTYPE YYSTYPE;
         
     | 
| 
         @@ -240,5 +240,5 @@ int yyparse (struct parser_params *p); 
     | 
|
| 
       240 
240 
     | 
    
         | 
| 
       241 
241 
     | 
    
         | 
| 
       242 
242 
     | 
    
         | 
| 
       243 
     | 
    
         
            -
            #endif /* ! 
     | 
| 
      
 243 
     | 
    
         
            +
            #endif /* !YY_YY_PARSE_H_INCLUDED  */
         
     | 
| 
       244 
244 
     | 
    
         | 
    
        data/ext/kanayago/parser_st.c
    CHANGED
    
    | 
         @@ -154,7 +154,8 @@ nonempty_memcpy(void *dest, const void *src, size_t n) 
     | 
|
| 
       154 
154 
     | 
    
         
             
                _Pragma("GCC diagnostic push") \
         
     | 
| 
       155 
155 
     | 
    
         
             
                _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
         
     | 
| 
       156 
156 
     | 
    
         
             
                __attribute__((__no_sanitize__(x))) y; \
         
     | 
| 
       157 
     | 
    
         
            -
                _Pragma("GCC diagnostic pop")
         
     | 
| 
      
 157 
     | 
    
         
            +
                _Pragma("GCC diagnostic pop") \
         
     | 
| 
      
 158 
     | 
    
         
            +
                y
         
     | 
| 
       158 
159 
     | 
    
         
             
            #endif
         
     | 
| 
       159 
160 
     | 
    
         | 
| 
       160 
161 
     | 
    
         
             
            #ifndef NO_SANITIZE
         
     | 
| 
         @@ -0,0 +1,78 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include "pattern_node.h"
         
     | 
| 
      
 2 
     | 
    
         
            +
            #include "internal/ruby_parser.h"
         
     | 
| 
      
 3 
     | 
    
         
            +
            #include "kanayago.h"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            VALUE rb_cInNode;
         
     | 
| 
      
 6 
     | 
    
         
            +
            VALUE rb_cArrayPatternNode;
         
     | 
| 
      
 7 
     | 
    
         
            +
            VALUE rb_cHashPatternNode;
         
     | 
| 
      
 8 
     | 
    
         
            +
            VALUE rb_cFindPatternNode;
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            VALUE
         
     | 
| 
      
 11 
     | 
    
         
            +
            in_node_new(const NODE *node)
         
     | 
| 
      
 12 
     | 
    
         
            +
            {
         
     | 
| 
      
 13 
     | 
    
         
            +
                VALUE obj = rb_class_new_instance(0, 0, rb_cInNode);
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@head"), ast_to_node_instance(RNODE_IN(node)->nd_head));
         
     | 
| 
      
 16 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@body"), ast_to_node_instance(RNODE_IN(node)->nd_body));
         
     | 
| 
      
 17 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@next"), ast_to_node_instance(RNODE_IN(node)->nd_next));
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                return obj;
         
     | 
| 
      
 20 
     | 
    
         
            +
            }
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            VALUE
         
     | 
| 
      
 23 
     | 
    
         
            +
            array_pattern_node_new(const NODE *node)
         
     | 
| 
      
 24 
     | 
    
         
            +
            {
         
     | 
| 
      
 25 
     | 
    
         
            +
                VALUE obj = rb_class_new_instance(0, 0, rb_cArrayPatternNode);
         
     | 
| 
      
 26 
     | 
    
         
            +
                NODE *rest_arg = RNODE_ARYPTN(node)->rest_arg;
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pconst"), ast_to_node_instance(RNODE_ARYPTN(node)->nd_pconst));
         
     | 
| 
      
 29 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pre_args"), ast_to_node_instance(RNODE_ARYPTN(node)->pre_args));
         
     | 
| 
      
 30 
     | 
    
         
            +
                // rest_arg can be NODE_SPECIAL_NO_NAME_REST (-1), which should be preserved as a special marker
         
     | 
| 
      
 31 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@rest_arg"),
         
     | 
| 
      
 32 
     | 
    
         
            +
                            (rest_arg == (NODE *)-1) ? INT2FIX(-1) : ast_to_node_instance(rest_arg));
         
     | 
| 
      
 33 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@post_args"), ast_to_node_instance(RNODE_ARYPTN(node)->post_args));
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                return obj;
         
     | 
| 
      
 36 
     | 
    
         
            +
            }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            VALUE
         
     | 
| 
      
 39 
     | 
    
         
            +
            hash_pattern_node_new(const NODE *node)
         
     | 
| 
      
 40 
     | 
    
         
            +
            {
         
     | 
| 
      
 41 
     | 
    
         
            +
                VALUE obj = rb_class_new_instance(0, 0, rb_cHashPatternNode);
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pconst"), ast_to_node_instance(RNODE_HSHPTN(node)->nd_pconst));
         
     | 
| 
      
 44 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pkwargs"), ast_to_node_instance(RNODE_HSHPTN(node)->nd_pkwargs));
         
     | 
| 
      
 45 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pkwrestarg"), ast_to_node_instance(RNODE_HSHPTN(node)->nd_pkwrestarg));
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                return obj;
         
     | 
| 
      
 48 
     | 
    
         
            +
            }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
            VALUE
         
     | 
| 
      
 51 
     | 
    
         
            +
            find_pattern_node_new(const NODE *node)
         
     | 
| 
      
 52 
     | 
    
         
            +
            {
         
     | 
| 
      
 53 
     | 
    
         
            +
                VALUE obj = rb_class_new_instance(0, 0, rb_cFindPatternNode);
         
     | 
| 
      
 54 
     | 
    
         
            +
                NODE *pre_rest_arg = RNODE_FNDPTN(node)->pre_rest_arg;
         
     | 
| 
      
 55 
     | 
    
         
            +
                NODE *post_rest_arg = RNODE_FNDPTN(node)->post_rest_arg;
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pconst"), ast_to_node_instance(RNODE_FNDPTN(node)->nd_pconst));
         
     | 
| 
      
 58 
     | 
    
         
            +
                // rest args can be NODE_SPECIAL_NO_NAME_REST (-1)
         
     | 
| 
      
 59 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@pre_rest_arg"),
         
     | 
| 
      
 60 
     | 
    
         
            +
                            (pre_rest_arg == (NODE *)-1) ? INT2FIX(-1) : ast_to_node_instance(pre_rest_arg));
         
     | 
| 
      
 61 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@args"), ast_to_node_instance(RNODE_FNDPTN(node)->args));
         
     | 
| 
      
 62 
     | 
    
         
            +
                rb_ivar_set(obj, rb_intern("@post_rest_arg"),
         
     | 
| 
      
 63 
     | 
    
         
            +
                            (post_rest_arg == (NODE *)-1) ? INT2FIX(-1) : ast_to_node_instance(post_rest_arg));
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                return obj;
         
     | 
| 
      
 66 
     | 
    
         
            +
            }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            void
         
     | 
| 
      
 69 
     | 
    
         
            +
            Init_PatternNode(VALUE module)
         
     | 
| 
      
 70 
     | 
    
         
            +
            {
         
     | 
| 
      
 71 
     | 
    
         
            +
                rb_cInNode = rb_define_class_under(module, "InNode", rb_cObject);
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                rb_cArrayPatternNode = rb_define_class_under(module, "ArrayPatternNode", rb_cObject);
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                rb_cHashPatternNode = rb_define_class_under(module, "HashPatternNode", rb_cObject);
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                rb_cFindPatternNode = rb_define_class_under(module, "FindPatternNode", rb_cObject);
         
     | 
| 
      
 78 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #ifndef KANAYAGO_PATTERN_NODE_H
         
     | 
| 
      
 2 
     | 
    
         
            +
            #define KANAYAGO_PATTERN_NODE_H
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            #include "kanayago.h"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            VALUE in_node_new(const NODE *);
         
     | 
| 
      
 7 
     | 
    
         
            +
            VALUE array_pattern_node_new(const NODE *);
         
     | 
| 
      
 8 
     | 
    
         
            +
            VALUE hash_pattern_node_new(const NODE *);
         
     | 
| 
      
 9 
     | 
    
         
            +
            VALUE find_pattern_node_new(const NODE *);
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            void Init_PatternNode(VALUE);
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            #endif
         
     | 
    
        data/ext/kanayago/ruby_atomic.h
    CHANGED
    
    | 
         @@ -1,5 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #ifndef INTERNAL_ATOMIC_H
         
     | 
| 
      
 2 
     | 
    
         
            +
            #define INTERNAL_ATOMIC_H
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
       1 
4 
     | 
    
         
             
            #include "ruby/atomic.h"
         
     | 
| 
       2 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
            #define RUBY_ATOMIC_VALUE_LOAD(x) rbimpl_atomic_value_load(&(x), RBIMPL_ATOMIC_SEQ_CST)
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       3 
8 
     | 
    
         
             
            /* shim macros only */
         
     | 
| 
       4 
9 
     | 
    
         
             
            #define ATOMIC_ADD(var, val) RUBY_ATOMIC_ADD(var, val)
         
     | 
| 
       5 
10 
     | 
    
         
             
            #define ATOMIC_CAS(var, oldval, newval) RUBY_ATOMIC_CAS(var, oldval, newval)
         
     | 
| 
         @@ -21,3 +26,41 @@ 
     | 
|
| 
       21 
26 
     | 
    
         
             
            #define ATOMIC_SUB(var, val) RUBY_ATOMIC_SUB(var, val)
         
     | 
| 
       22 
27 
     | 
    
         
             
            #define ATOMIC_VALUE_CAS(var, oldval, val) RUBY_ATOMIC_VALUE_CAS(var, oldval, val)
         
     | 
| 
       23 
28 
     | 
    
         
             
            #define ATOMIC_VALUE_EXCHANGE(var, val) RUBY_ATOMIC_VALUE_EXCHANGE(var, val)
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            #define ATOMIC_LOAD_RELAXED(var) rbimpl_atomic_load(&(var), RBIMPL_ATOMIC_RELAXED)
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            typedef RBIMPL_ALIGNAS(8) uint64_t rbimpl_atomic_uint64_t;
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            static inline uint64_t
         
     | 
| 
      
 35 
     | 
    
         
            +
            rbimpl_atomic_u64_load_relaxed(const volatile rbimpl_atomic_uint64_t *value)
         
     | 
| 
      
 36 
     | 
    
         
            +
            {
         
     | 
| 
      
 37 
     | 
    
         
            +
            #if defined(HAVE_GCC_ATOMIC_BUILTINS_64)
         
     | 
| 
      
 38 
     | 
    
         
            +
                return __atomic_load_n(value, __ATOMIC_RELAXED);
         
     | 
| 
      
 39 
     | 
    
         
            +
            #elif defined(_WIN32)
         
     | 
| 
      
 40 
     | 
    
         
            +
                uint64_t val = *value;
         
     | 
| 
      
 41 
     | 
    
         
            +
                return InterlockedCompareExchange64(RBIMPL_CAST((uint64_t *)value), val, val);
         
     | 
| 
      
 42 
     | 
    
         
            +
            #elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
         
     | 
| 
      
 43 
     | 
    
         
            +
                uint64_t val = *value;
         
     | 
| 
      
 44 
     | 
    
         
            +
                return atomic_cas_64(value, val, val);
         
     | 
| 
      
 45 
     | 
    
         
            +
            #else
         
     | 
| 
      
 46 
     | 
    
         
            +
                return *value;
         
     | 
| 
      
 47 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 48 
     | 
    
         
            +
            }
         
     | 
| 
      
 49 
     | 
    
         
            +
            #define ATOMIC_U64_LOAD_RELAXED(var) rbimpl_atomic_u64_load_relaxed(&(var))
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            static inline void
         
     | 
| 
      
 52 
     | 
    
         
            +
            rbimpl_atomic_u64_set_relaxed(volatile rbimpl_atomic_uint64_t *address, uint64_t value)
         
     | 
| 
      
 53 
     | 
    
         
            +
            {
         
     | 
| 
      
 54 
     | 
    
         
            +
            #if defined(HAVE_GCC_ATOMIC_BUILTINS_64)
         
     | 
| 
      
 55 
     | 
    
         
            +
                __atomic_store_n(address, value, __ATOMIC_RELAXED);
         
     | 
| 
      
 56 
     | 
    
         
            +
            #elif defined(_WIN32)
         
     | 
| 
      
 57 
     | 
    
         
            +
                InterlockedExchange64(address, value);
         
     | 
| 
      
 58 
     | 
    
         
            +
            #elif defined(__sun) && defined(HAVE_ATOMIC_H) && (defined(_LP64) || defined(_I32LPx))
         
     | 
| 
      
 59 
     | 
    
         
            +
                atomic_swap_64(address, value);
         
     | 
| 
      
 60 
     | 
    
         
            +
            #else
         
     | 
| 
      
 61 
     | 
    
         
            +
                *address = value;
         
     | 
| 
      
 62 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 63 
     | 
    
         
            +
            }
         
     | 
| 
      
 64 
     | 
    
         
            +
            #define ATOMIC_U64_SET_RELAXED(var, val) rbimpl_atomic_u64_set_relaxed(&(var), val)
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            #endif
         
     | 
    
        data/ext/kanayago/ruby_parser.c
    CHANGED
    
    | 
         @@ -34,12 +34,6 @@ 
     | 
|
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
            #define parser_encoding const void
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
            static int
         
     | 
| 
       38 
     | 
    
         
            -
            is_ascii_string2(VALUE str)
         
     | 
| 
       39 
     | 
    
         
            -
            {
         
     | 
| 
       40 
     | 
    
         
            -
                return is_ascii_string(str);
         
     | 
| 
       41 
     | 
    
         
            -
            }
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
37 
     | 
    
         
             
            RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 6, 0)
         
     | 
| 
       44 
38 
     | 
    
         
             
            static VALUE
         
     | 
| 
       45 
39 
     | 
    
         
             
            syntax_error_append(VALUE exc, VALUE file, int line, int column,
         
     | 
| 
         @@ -144,12 +138,6 @@ utf8_encoding(void) 
     | 
|
| 
       144 
138 
     | 
    
         
             
                return rb_utf8_encoding();
         
     | 
| 
       145 
139 
     | 
    
         
             
            }
         
     | 
| 
       146 
140 
     | 
    
         | 
| 
       147 
     | 
    
         
            -
            static VALUE
         
     | 
| 
       148 
     | 
    
         
            -
            enc_associate(VALUE obj, parser_encoding *enc)
         
     | 
| 
       149 
     | 
    
         
            -
            {
         
     | 
| 
       150 
     | 
    
         
            -
                return rb_enc_associate(obj, enc);
         
     | 
| 
       151 
     | 
    
         
            -
            }
         
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
141 
     | 
    
         
             
            static parser_encoding *
         
     | 
| 
       154 
142 
     | 
    
         
             
            ascii8bit_encoding(void)
         
     | 
| 
       155 
143 
     | 
    
         
             
            {
         
     | 
| 
         @@ -186,12 +174,6 @@ intern3(const char *name, long len, parser_encoding *enc) 
     | 
|
| 
       186 
174 
     | 
    
         
             
                return rb_intern3(name, len, enc);
         
     | 
| 
       187 
175 
     | 
    
         
             
            }
         
     | 
| 
       188 
176 
     | 
    
         | 
| 
       189 
     | 
    
         
            -
            static parser_encoding *
         
     | 
| 
       190 
     | 
    
         
            -
            usascii_encoding(void)
         
     | 
| 
       191 
     | 
    
         
            -
            {
         
     | 
| 
       192 
     | 
    
         
            -
                return rb_usascii_encoding();
         
     | 
| 
       193 
     | 
    
         
            -
            }
         
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
177 
     | 
    
         
             
            static int
         
     | 
| 
       196 
178 
     | 
    
         
             
            enc_symname_type(const char *name, long len, parser_encoding *enc, unsigned int allowed_attrset)
         
     | 
| 
       197 
179 
     | 
    
         
             
            {
         
     | 
| 
         @@ -203,6 +185,7 @@ typedef struct { 
     | 
|
| 
       203 
185 
     | 
    
         
             
                rb_encoding *enc;
         
     | 
| 
       204 
186 
     | 
    
         
             
                NODE *succ_block;
         
     | 
| 
       205 
187 
     | 
    
         
             
                const rb_code_location_t *loc;
         
     | 
| 
      
 188 
     | 
    
         
            +
                rb_parser_assignable_func assignable;
         
     | 
| 
       206 
189 
     | 
    
         
             
            } reg_named_capture_assign_t;
         
     | 
| 
       207 
190 
     | 
    
         | 
| 
       208 
191 
     | 
    
         
             
            static int
         
     | 
| 
         @@ -216,11 +199,12 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end, 
     | 
|
| 
       216 
199 
     | 
    
         
             
                long len = name_end - name;
         
     | 
| 
       217 
200 
     | 
    
         
             
                const char *s = (const char *)name;
         
     | 
| 
       218 
201 
     | 
    
         | 
| 
       219 
     | 
    
         
            -
                return rb_reg_named_capture_assign_iter_impl(p, s, len, enc, &arg->succ_block, loc);
         
     | 
| 
      
 202 
     | 
    
         
            +
                return rb_reg_named_capture_assign_iter_impl(p, s, len, enc, &arg->succ_block, loc, arg->assignable);
         
     | 
| 
       220 
203 
     | 
    
         
             
            }
         
     | 
| 
       221 
204 
     | 
    
         | 
| 
       222 
205 
     | 
    
         
             
            static NODE *
         
     | 
| 
       223 
     | 
    
         
            -
            reg_named_capture_assign(struct parser_params* p, VALUE regexp, const rb_code_location_t *loc 
     | 
| 
      
 206 
     | 
    
         
            +
            reg_named_capture_assign(struct parser_params* p, VALUE regexp, const rb_code_location_t *loc,
         
     | 
| 
      
 207 
     | 
    
         
            +
                                     rb_parser_assignable_func assignable)
         
     | 
| 
       224 
208 
     | 
    
         
             
            {
         
     | 
| 
       225 
209 
     | 
    
         
             
                reg_named_capture_assign_t arg;
         
     | 
| 
       226 
210 
     | 
    
         | 
| 
         @@ -228,6 +212,7 @@ reg_named_capture_assign(struct parser_params* p, VALUE regexp, const rb_code_lo 
     | 
|
| 
       228 
212 
     | 
    
         
             
                arg.enc = rb_enc_get(regexp);
         
     | 
| 
       229 
213 
     | 
    
         
             
                arg.succ_block = 0;
         
     | 
| 
       230 
214 
     | 
    
         
             
                arg.loc = loc;
         
     | 
| 
      
 215 
     | 
    
         
            +
                arg.assignable = assignable;
         
     | 
| 
       231 
216 
     | 
    
         
             
                onig_foreach_name(RREGEXP_PTR(regexp), reg_named_capture_assign_iter, &arg);
         
     | 
| 
       232 
217 
     | 
    
         | 
| 
       233 
218 
     | 
    
         
             
                if (!arg.succ_block) return 0;
         
     | 
| 
         @@ -339,7 +324,7 @@ xmalloc_mul_add(size_t x, size_t y, size_t z) 
     | 
|
| 
       339 
324 
     | 
    
         
             
            static VALUE
         
     | 
| 
       340 
325 
     | 
    
         
             
            suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
         
     | 
| 
       341 
326 
     | 
    
         
             
            {
         
     | 
| 
       342 
     | 
    
         
            -
                return  
     | 
| 
      
 327 
     | 
    
         
            +
                return func(arg);
         
     | 
| 
       343 
328 
     | 
    
         
             
            }
         
     | 
| 
       344 
329 
     | 
    
         | 
| 
       345 
330 
     | 
    
         
             
            static ID
         
     | 
| 
         @@ -385,8 +370,6 @@ static const rb_parser_config_t rb_global_parser_config = { 
     | 
|
| 
       385 
370 
     | 
    
         | 
| 
       386 
371 
     | 
    
         
             
                .attr_get = rb_attr_get,
         
     | 
| 
       387 
372 
     | 
    
         | 
| 
       388 
     | 
    
         
            -
                .ary_new = rb_ary_new,
         
     | 
| 
       389 
     | 
    
         
            -
                .ary_push = rb_ary_push,
         
     | 
| 
       390 
373 
     | 
    
         
             
                .ary_new_from_args = rb_ary_new_from_args,
         
     | 
| 
       391 
374 
     | 
    
         
             
                .ary_unshift = rb_ary_unshift,
         
     | 
| 
       392 
375 
     | 
    
         | 
| 
         @@ -405,25 +388,18 @@ static const rb_parser_config_t rb_global_parser_config = { 
     | 
|
| 
       405 
388 
     | 
    
         
             
                .id2name = rb_id2name,
         
     | 
| 
       406 
389 
     | 
    
         
             
                .id2str = rb_id2str,
         
     | 
| 
       407 
390 
     | 
    
         
             
                .id2sym = rb_id2sym,
         
     | 
| 
       408 
     | 
    
         
            -
                .sym2id = rb_sym2id,
         
     | 
| 
       409 
391 
     | 
    
         | 
| 
       410 
392 
     | 
    
         
             
                .str_catf = rb_str_catf,
         
     | 
| 
       411 
393 
     | 
    
         
             
                .str_cat_cstr = rb_str_cat_cstr,
         
     | 
| 
       412 
     | 
    
         
            -
                .str_modify = rb_str_modify,
         
     | 
| 
       413 
     | 
    
         
            -
                .str_set_len = rb_str_set_len,
         
     | 
| 
       414 
     | 
    
         
            -
                .str_cat = rb_str_cat,
         
     | 
| 
       415 
394 
     | 
    
         
             
                .str_resize = rb_str_resize,
         
     | 
| 
       416 
395 
     | 
    
         
             
                .str_new = rb_str_new,
         
     | 
| 
       417 
396 
     | 
    
         
             
                .str_new_cstr = rb_str_new_cstr,
         
     | 
| 
       418 
397 
     | 
    
         
             
                .str_to_interned_str = rb_str_to_interned_str,
         
     | 
| 
       419 
     | 
    
         
            -
                .is_ascii_string = is_ascii_string2,
         
     | 
| 
       420 
398 
     | 
    
         
             
                .enc_str_new = enc_str_new,
         
     | 
| 
       421 
399 
     | 
    
         
             
                .str_vcatf = rb_str_vcatf,
         
     | 
| 
       422 
400 
     | 
    
         
             
                .rb_sprintf = rb_sprintf,
         
     | 
| 
       423 
401 
     | 
    
         
             
                .rstring_ptr = RSTRING_PTR,
         
     | 
| 
       424 
     | 
    
         
            -
                .rstring_end = RSTRING_END,
         
     | 
| 
       425 
402 
     | 
    
         
             
                .rstring_len = RSTRING_LEN,
         
     | 
| 
       426 
     | 
    
         
            -
                .obj_as_string = rb_obj_as_string,
         
     | 
| 
       427 
403 
     | 
    
         | 
| 
       428 
404 
     | 
    
         
             
                .int2num = rb_int2num_inline,
         
     | 
| 
       429 
405 
     | 
    
         | 
| 
         @@ -446,7 +422,6 @@ static const rb_parser_config_t rb_global_parser_config = { 
     | 
|
| 
       446 
422 
     | 
    
         
             
                .enc_get = enc_get,
         
     | 
| 
       447 
423 
     | 
    
         
             
                .enc_asciicompat = enc_asciicompat,
         
     | 
| 
       448 
424 
     | 
    
         
             
                .utf8_encoding = utf8_encoding,
         
     | 
| 
       449 
     | 
    
         
            -
                .enc_associate = enc_associate,
         
     | 
| 
       450 
425 
     | 
    
         
             
                .ascii8bit_encoding = ascii8bit_encoding,
         
     | 
| 
       451 
426 
     | 
    
         
             
                .enc_codelen = enc_codelen,
         
     | 
| 
       452 
427 
     | 
    
         
             
                .enc_mbcput = enc_mbcput,
         
     | 
| 
         @@ -455,7 +430,6 @@ static const rb_parser_config_t rb_global_parser_config = { 
     | 
|
| 
       455 
430 
     | 
    
         
             
                .enc_isspace = enc_isspace,
         
     | 
| 
       456 
431 
     | 
    
         
             
                .enc_coderange_7bit = ENC_CODERANGE_7BIT,
         
     | 
| 
       457 
432 
     | 
    
         
             
                .enc_coderange_unknown = ENC_CODERANGE_UNKNOWN,
         
     | 
| 
       458 
     | 
    
         
            -
                .usascii_encoding = usascii_encoding,
         
     | 
| 
       459 
433 
     | 
    
         
             
                .enc_mbminlen = enc_mbminlen,
         
     | 
| 
       460 
434 
     | 
    
         
             
                .enc_isascii = enc_isascii,
         
     | 
| 
       461 
435 
     | 
    
         
             
                .enc_mbc_to_codepoint = enc_mbc_to_codepoint,
         
     | 
| 
         @@ -469,7 +443,6 @@ static const rb_parser_config_t rb_global_parser_config = { 
     | 
|
| 
       469 
443 
     | 
    
         | 
| 
       470 
444 
     | 
    
         
             
                .errinfo = rb_errinfo,
         
     | 
| 
       471 
445 
     | 
    
         
             
                .set_errinfo = rb_set_errinfo,
         
     | 
| 
       472 
     | 
    
         
            -
                .exc_raise = rb_exc_raise,
         
     | 
| 
       473 
446 
     | 
    
         
             
                .make_exception = rb_make_exception,
         
     | 
| 
       474 
447 
     | 
    
         | 
| 
       475 
448 
     | 
    
         
             
                .sized_xfree = ruby_sized_xfree,
         
     | 
| 
         @@ -774,8 +747,7 @@ ast_free(void *ptr) 
     | 
|
| 
       774 
747 
     | 
    
         
             
                rb_ast_free(ast);
         
     | 
| 
       775 
748 
     | 
    
         
             
            }
         
     | 
| 
       776 
749 
     | 
    
         | 
| 
       777 
     | 
    
         
            -
             
     | 
| 
       778 
     | 
    
         
            -
            const rb_data_type_t ast_data_type = {
         
     | 
| 
      
 750 
     | 
    
         
            +
            static const rb_data_type_t ast_data_type = {
         
     | 
| 
       779 
751 
     | 
    
         
             
                "AST",
         
     | 
| 
       780 
752 
     | 
    
         
             
                {
         
     | 
| 
       781 
753 
     | 
    
         
             
                    NULL,
         
     |