ruby-ll 2.1.4 → 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: 1d49084634bb74f2dbcb1a7b5879b4dc04834eaa5b8fb9b6320f27bb5b3a163a
4
- data.tar.gz: 6bb604c577c149786c6786620eb7051ded78c0abbecfaa948dcaa668b276cad8
3
+ metadata.gz: 2f42d3fc79c6780a3434b380b418e6adfa3680a7c217686af64d8cafec9c1dbf
4
+ data.tar.gz: 1717b822ca50436a07e00777fc6d15226935c7e3d6126e27669cf80c7690d25b
5
5
  SHA512:
6
- metadata.gz: 699326ad786887699f305388f7dca6dab8da10492f4f2dc49f7633cce7a8125c087f78a1a3bc31a8547c916ca51175801090c4eecd852a8a6b790a039af9da8a
7
- data.tar.gz: 1cbb1b087c2b404b3fc942f148a5c6d9aa0b4289132193cd73a10cef7758e489881733e04e622b49ca4480c878f51955944d287334c2fc2f7e8f79bbad385012
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,20 +46,40 @@ 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
+ );
74
+
75
+ config = rb_const_get(klass, id_config_const);
53
76
 
54
- Data_Get_Struct(config, DriverConfig, state->config);
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
  /**
@@ -100,7 +123,7 @@ VALUE ll_driver_each_token(
100
123
  VALUE type = rb_ary_entry(token, 0);
101
124
  VALUE value = rb_ary_entry(token, 1);
102
125
 
103
- Data_Get_Struct(self, DriverState, state);
126
+ TypedData_Get_Struct(self, DriverState, &ll_driver_type, state);
104
127
 
105
128
  while ( 1 )
106
129
  {
@@ -142,8 +165,8 @@ VALUE ll_driver_each_token(
142
165
  self,
143
166
  id_parser_error,
144
167
  4,
145
- INT2NUM(stack_type),
146
- INT2NUM(stack_value),
168
+ LONG2NUM(stack_type),
169
+ LONG2NUM(stack_value),
147
170
  type,
148
171
  value
149
172
  );
@@ -261,8 +284,8 @@ VALUE ll_driver_each_token(
261
284
  self,
262
285
  id_parser_error,
263
286
  4,
264
- INT2NUM(stack_type),
265
- INT2NUM(stack_value),
287
+ LONG2NUM(stack_type),
288
+ LONG2NUM(stack_value),
266
289
  type,
267
290
  value
268
291
  );
@@ -320,7 +343,7 @@ VALUE ll_driver_parse(VALUE self)
320
343
 
321
344
  DriverState *state;
322
345
 
323
- Data_Get_Struct(self, DriverState, state);
346
+ TypedData_Get_Struct(self, DriverState, &ll_driver_type, state);
324
347
 
325
348
  /* EOF rule */
326
349
  kv_push(long, state->stack, T_EOF);
@@ -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.4'
2
+ VERSION = '2.2.0'
3
3
  end # LL
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ll
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  requirements: []
209
- rubygems_version: 3.6.9
209
+ rubygems_version: 4.0.6
210
210
  specification_version: 4
211
211
  summary: An LL(1) parser generator for Ruby.
212
212
  test_files: []