ruby-ll 2.1.3 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e1faade684ee6c30dbceab3e16db55cd11d94a89933649d324009e1fd033f33
4
- data.tar.gz: 2cbd469bbd142d904cbed8feb4557bd813744ab20cb5af9a5decc1f04eaca957
3
+ metadata.gz: 2f42d3fc79c6780a3434b380b418e6adfa3680a7c217686af64d8cafec9c1dbf
4
+ data.tar.gz: 1717b822ca50436a07e00777fc6d15226935c7e3d6126e27669cf80c7690d25b
5
5
  SHA512:
6
- metadata.gz: 3d8910a725c85f891ca9162d7d56893cac42eee64fed9e8cd00ba565e14eb7d34f204ea90ced3b8783b1ab411fb3595fdb849780b7a5babfe4c7674be8822f26
7
- data.tar.gz: f9f08de4719772842c6693dc7fde5212b2eb94d1086a673f1557d6ea97a6f8f7f6ec5403a358a4d13fe0c714cdb6518e488fd460d740b0508a9799c59ffceb74
6
+ metadata.gz: b60a8dac5370391a7824092a8a5ed3a372eed5b0c51de1d9e6fb81eb426008753753270de84bf633d46f39a8c406eac0e3aeb1b5c2fea8b51e93c829d9f6a766
7
+ data.tar.gz: c26bff018b93851ac2e12e54a73569b2ed174f3aa8f00bc6ebcc3778041e4ae3336415975b4e41b5c335478cd29648f44e121a6562a081df27ec71b6cc1fd933
data/ext/c/driver.c CHANGED
@@ -21,8 +21,10 @@ ID id_parser_error;
21
21
  * This function is called automatically when a Driver instance is garbage
22
22
  * collected.
23
23
  */
24
- void ll_driver_free(DriverState *state)
24
+ void ll_driver_free(void *data)
25
25
  {
26
+ DriverState *state = data;
27
+
26
28
  kv_destroy(state->stack);
27
29
  kv_destroy(state->value_stack);
28
30
 
@@ -33,9 +35,10 @@ void ll_driver_free(DriverState *state)
33
35
  * Marks the objects stored in the driver's internal state, preventing them from
34
36
  * being garbage collected until the next GC run.
35
37
  */
36
- void ll_driver_mark(DriverState *state)
38
+ void ll_driver_mark(void *data)
37
39
  {
38
40
  size_t index;
41
+ DriverState *state = data;
39
42
 
40
43
  FOR(index, kv_size(state->value_stack))
41
44
  {
@@ -43,30 +46,61 @@ void ll_driver_mark(DriverState *state)
43
46
  }
44
47
  }
45
48
 
49
+ static const rb_data_type_t ll_driver_type = {
50
+ "LL::Driver",
51
+ {
52
+ ll_driver_mark,
53
+ ll_driver_free,
54
+ NULL,
55
+ },
56
+ NULL,
57
+ NULL,
58
+ RUBY_TYPED_FREE_IMMEDIATELY,
59
+ };
60
+
46
61
  /**
47
62
  * Allocates a new instance of the Driver class and prepares its internal state.
48
63
  */
49
64
  VALUE ll_driver_allocate(VALUE klass)
50
65
  {
51
- DriverState *state = ALLOC(DriverState);
52
- VALUE config = rb_const_get(klass, id_config_const);
66
+ DriverState *state;
67
+ VALUE config;
68
+ VALUE obj = TypedData_Make_Struct(
69
+ klass,
70
+ DriverState,
71
+ &ll_driver_type,
72
+ state
73
+ );
53
74
 
54
- Data_Get_Struct(config, DriverConfig, state->config);
75
+ config = rb_const_get(klass, id_config_const);
76
+
77
+ TypedData_Get_Struct(config, DriverConfig, &ll_driver_config_type, state->config);
55
78
 
56
79
  kv_init(state->stack);
57
80
  kv_init(state->value_stack);
58
81
 
59
- return Data_Wrap_Struct(klass, ll_driver_mark, ll_driver_free, state);
82
+ return obj;
60
83
  }
61
84
 
62
85
  /**
63
- * Callback function for iterating over every input token and actually parsing
64
- * said input.
86
+ * Callback function for iterating over every input token and parsing it.
87
+ *
88
+ * This function is intended to be used as a block callback for Ruby's
89
+ * `rb_block_call`, and processes a single token per invocation.
65
90
  *
66
91
  * @param token An Array containing the token type as a Symbol and its value.
67
92
  * @param self The Driver instance currently in use.
93
+ * @param argc The number of additional arguments passed to the block.
94
+ * @param argv The array of additional arguments passed to the block.
95
+ * @param block_arg The block argument passed from Ruby (if any).
68
96
  */
69
- VALUE ll_driver_each_token(VALUE token, VALUE self)
97
+ VALUE ll_driver_each_token(
98
+ VALUE token,
99
+ VALUE self,
100
+ int argc,
101
+ const VALUE *argv,
102
+ VALUE block_arg
103
+ )
70
104
  {
71
105
  VALUE method;
72
106
  VALUE action_args;
@@ -89,7 +123,7 @@ VALUE ll_driver_each_token(VALUE token, VALUE self)
89
123
  VALUE type = rb_ary_entry(token, 0);
90
124
  VALUE value = rb_ary_entry(token, 1);
91
125
 
92
- Data_Get_Struct(self, DriverState, state);
126
+ TypedData_Get_Struct(self, DriverState, &ll_driver_type, state);
93
127
 
94
128
  while ( 1 )
95
129
  {
@@ -131,8 +165,8 @@ VALUE ll_driver_each_token(VALUE token, VALUE self)
131
165
  self,
132
166
  id_parser_error,
133
167
  4,
134
- INT2NUM(stack_type),
135
- INT2NUM(stack_value),
168
+ LONG2NUM(stack_type),
169
+ LONG2NUM(stack_value),
136
170
  type,
137
171
  value
138
172
  );
@@ -250,8 +284,8 @@ VALUE ll_driver_each_token(VALUE token, VALUE self)
250
284
  self,
251
285
  id_parser_error,
252
286
  4,
253
- INT2NUM(stack_type),
254
- INT2NUM(stack_value),
287
+ LONG2NUM(stack_type),
288
+ LONG2NUM(stack_value),
255
289
  type,
256
290
  value
257
291
  );
@@ -309,7 +343,7 @@ VALUE ll_driver_parse(VALUE self)
309
343
 
310
344
  DriverState *state;
311
345
 
312
- Data_Get_Struct(self, DriverState, state);
346
+ TypedData_Get_Struct(self, DriverState, &ll_driver_type, state);
313
347
 
314
348
  /* EOF rule */
315
349
  kv_push(long, state->stack, T_EOF);
@@ -326,7 +360,7 @@ VALUE ll_driver_parse(VALUE self)
326
360
  id_each_token,
327
361
  0,
328
362
  NULL,
329
- RUBY_METHOD_FUNC(ll_driver_each_token),
363
+ ll_driver_each_token,
330
364
  self
331
365
  );
332
366
 
@@ -1,11 +1,42 @@
1
1
  #include "driver_config.h"
2
2
 
3
+ void ll_driver_config_mark(void *data)
4
+ {
5
+ DriverConfig *config = data;
6
+
7
+ if ( config->terminals != NULL )
8
+ {
9
+ khint_t key;
10
+
11
+ for (
12
+ key = kh_begin(config->terminals);
13
+ key != kh_end(config->terminals);
14
+ key++
15
+ )
16
+ {
17
+ if ( kh_exist(config->terminals, key) )
18
+ {
19
+ rb_gc_mark((VALUE) kh_key(config->terminals, key));
20
+ }
21
+ }
22
+ }
23
+
24
+ if ( config->action_names != NULL )
25
+ {
26
+ rb_gc_mark_locations(
27
+ config->action_names,
28
+ config->action_names + config->actions_count
29
+ );
30
+ }
31
+ }
32
+
3
33
  /**
4
34
  * Releases memory of the DriverConfig struct and its members.
5
35
  */
6
- void ll_driver_config_free(DriverConfig *config)
36
+ void ll_driver_config_free(void *data)
7
37
  {
8
38
  long rindex;
39
+ DriverConfig *config = data;
9
40
 
10
41
  FOR(rindex, config->rules_count)
11
42
  {
@@ -23,22 +54,36 @@ void ll_driver_config_free(DriverConfig *config)
23
54
  free(config->action_names);
24
55
  free(config->action_arg_amounts);
25
56
 
26
- kh_destroy(int64_map, config->terminals);
57
+ if ( config->terminals != NULL )
58
+ {
59
+ kh_destroy(int64_map, config->terminals);
60
+ }
27
61
 
28
62
  free(config);
29
63
  }
30
64
 
65
+ const rb_data_type_t ll_driver_config_type = {
66
+ "LL::DriverConfig",
67
+ {
68
+ ll_driver_config_mark,
69
+ ll_driver_config_free,
70
+ NULL,
71
+ },
72
+ NULL,
73
+ NULL,
74
+ RUBY_TYPED_FREE_IMMEDIATELY,
75
+ };
76
+
31
77
  /**
32
78
  * Allocates a new DriverConfig.
33
79
  */
34
80
  VALUE ll_driver_config_allocate(VALUE klass)
35
81
  {
36
- DriverConfig *config = ALLOC(DriverConfig);
37
-
38
- return Data_Wrap_Struct(
82
+ DriverConfig *config;
83
+ return TypedData_Make_Struct(
39
84
  klass,
40
- NULL,
41
- ll_driver_config_free,
85
+ DriverConfig,
86
+ &ll_driver_config_type,
42
87
  config
43
88
  );
44
89
  }
@@ -59,7 +104,7 @@ VALUE ll_driver_config_set_terminals(VALUE self, VALUE array)
59
104
  DriverConfig *config;
60
105
  long count = RARRAY_LEN(array);
61
106
 
62
- Data_Get_Struct(self, DriverConfig, config);
107
+ TypedData_Get_Struct(self, DriverConfig, &ll_driver_config_type, config);
63
108
 
64
109
  config->terminals = kh_init(int64_map);
65
110
 
@@ -89,7 +134,7 @@ VALUE ll_driver_config_set_rules(VALUE self, VALUE array)
89
134
  VALUE row;
90
135
  long row_count = RARRAY_LEN(array);
91
136
 
92
- Data_Get_Struct(self, DriverConfig, config);
137
+ TypedData_Get_Struct(self, DriverConfig, &ll_driver_config_type, config);
93
138
 
94
139
  config->rules = ALLOC_N(long*, row_count);
95
140
  config->rule_lengths = ALLOC_N(long, row_count);
@@ -129,7 +174,7 @@ VALUE ll_driver_config_set_table(VALUE self, VALUE array)
129
174
  DriverConfig *config;
130
175
  long row_count = RARRAY_LEN(array);
131
176
 
132
- Data_Get_Struct(self, DriverConfig, config);
177
+ TypedData_Get_Struct(self, DriverConfig, &ll_driver_config_type, config);
133
178
 
134
179
  config->table = ALLOC_N(long*, row_count);
135
180
 
@@ -164,7 +209,7 @@ VALUE ll_driver_config_set_actions(VALUE self, VALUE array)
164
209
  DriverConfig *config;
165
210
  long row_count = RARRAY_LEN(array);
166
211
 
167
- Data_Get_Struct(self, DriverConfig, config);
212
+ TypedData_Get_Struct(self, DriverConfig, &ll_driver_config_type, config);
168
213
 
169
214
  config->action_names = ALLOC_N(VALUE, row_count);
170
215
  config->action_arg_amounts = ALLOC_N(long, row_count);
@@ -50,4 +50,6 @@ typedef struct
50
50
 
51
51
  extern void Init_ll_driver_config();
52
52
 
53
+ extern const rb_data_type_t ll_driver_config_type;
54
+
53
55
  #endif
@@ -15,7 +15,7 @@ import org.jruby.RubyFixnum;
15
15
 
16
16
  import org.jruby.anno.JRubyClass;
17
17
  import org.jruby.anno.JRubyMethod;
18
- import org.jruby.runtime.Arity;
18
+ import org.jruby.runtime.Signature;
19
19
  import org.jruby.runtime.Helpers;
20
20
  import org.jruby.runtime.ThreadContext;
21
21
  import org.jruby.runtime.ObjectAllocator;
@@ -307,7 +307,7 @@ public class Driver extends RubyObject
307
307
  CallBlock19.newCallClosure(
308
308
  this,
309
309
  this.metaClass,
310
- Arity.NO_ARGUMENTS,
310
+ Signature.NO_ARGUMENTS,
311
311
  callback,
312
312
  context
313
313
  )
data/lib/ll/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LL
2
- VERSION = '2.1.3'
2
+ VERSION = '2.2.0'
3
3
  end # LL
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ll
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-06-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ast
@@ -193,7 +192,6 @@ homepage: https://github.com/yorickpeterse/ruby-ll
193
192
  licenses:
194
193
  - MPL-2.0
195
194
  metadata: {}
196
- post_install_message:
197
195
  rdoc_options: []
198
196
  require_paths:
199
197
  - lib
@@ -208,8 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
206
  - !ruby/object:Gem::Version
209
207
  version: '0'
210
208
  requirements: []
211
- rubygems_version: 3.4.8
212
- signing_key:
209
+ rubygems_version: 4.0.6
213
210
  specification_version: 4
214
211
  summary: An LL(1) parser generator for Ruby.
215
212
  test_files: []