ruby2c 1.0.0.9 → 1.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6ae2f91c8e5c83ab77b02d6e779b83aa749f4fe8799c1f875859844c2d0f7a6
4
+ data.tar.gz: 145da4a50b73b15433695d7c1917412eb2da27ad8c954fc9c651ee71511a61e6
5
+ SHA512:
6
+ metadata.gz: af6b9e49cf2b1eb2cf456fde6faa184a2dca2fc0ed61232206aeea83cb8a2b2512aa30164b0dba5ea58005cb16c68516ec695b3b00fd950f695607147b1df0d5
7
+ data.tar.gz: ad870dab2e1d50291e9855a53fae299c20733c11871d5de3f38da1341b82ed7e64dfd76d0d1d5e9c0fa700f2e52fdf87cb853e219f4f80d3ed20d51487b18e3e
@@ -0,0 +1,2 @@
1
+ F��L�fT�v��<h3ڬ~�VPrg�~}�0 Y;���<IX(?7��Z
2
+ ���#_�Q0���/��^��-��ys�F���;��I-8 <`���u�݀�1��ty$��Epƨs1��X:����2��RQ��e�oԜ5�)%�r� �p�N��RɞG�>�`.����N���Ls(��P�X-Ȫ(�n ����i.q���Aj>HW�*�ZS��ȡ2n�X�'�;�g���jn��)A�'�!�;>ľc�,1i�(
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- ���[�v@S��u��X)��0�����"Z�K4H,���!/�5�×с���|��� DX0F�Ӫ�����`"2���);p������Cbx�K�T�j�ȴ,����.Sn*�7���y���{�|5t�"��E��P''a����U���+�ʮ��sޖFl��4I�����B[� �qw�_������
1
+ v��`����͉��GI!������@8sy_��a��@EOu` �������=x_!⏆�� ��7�!r{�M
@@ -1,3 +1,21 @@
1
+ === 1.1.0 / 2019-09-24
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Pushed @@array_types and array_type? up to Sexp (in typed_sexp.rb).
6
+ * Pushed down @@array_types and #array_type? from Sexp to TypedSexp.
7
+ * Renamed Type to CType
8
+ * Renamed TypedSexp#sexp_type to c_type to resolve conflict/confusion w/ Sexp.
9
+
10
+ * 6 bug fixes:
11
+
12
+ * Fixed a test file randomization error (yay!) by requiring typed_sexp in rewriter.
13
+ * Fixed inspect/pretty_print to include line number for typed sexps, just like sexps.
14
+ * Fixed new ruby 2.5 warnings.
15
+ * Fixes for changes to sexp_processor, centered aroud maintaining c_type.
16
+ * Got working with ruby 2.5 parser.
17
+ * Removed obsolete attrset test
18
+
1
19
  === 1.0.0.9 / 2012-11-09
2
20
 
3
21
  * 1 bug fix:
@@ -29,12 +47,12 @@
29
47
 
30
48
  === 1.0.0.6 / 2009-06-23
31
49
 
32
- 1 major enhancement:
50
+ * 1 major enhancement:
33
51
 
34
52
  * Switched from ParseTree to ruby_parser for 1.9 compatibility. woo.
35
53
  * All translate/process methods are gone since we can't reflect at runtime.
36
54
 
37
- 43 minor enhancements:
55
+ * 43 minor enhancements:
38
56
 
39
57
  * Added IterRewriter for finding free variables in iter nodes.
40
58
  * Added dxstr.
@@ -99,104 +117,104 @@
99
117
 
100
118
  * 6 minor enhancements:
101
119
 
102
- * Split RubyToC to RubyToRubyC and RubyToAnsiC.
103
- * Extended Environment to be more flexible for various situations.
104
- * Removed propaganda (bloat) from release.
105
- * Gemified and reorganized things. Support still needs splitting up.
106
- * Flipped a lot of internal naming to use Unique.
107
- * Added ruby_to_c_show (like parse_tree_show).
120
+ * Split RubyToC to RubyToRubyC and RubyToAnsiC.
121
+ * Extended Environment to be more flexible for various situations.
122
+ * Removed propaganda (bloat) from release.
123
+ * Gemified and reorganized things. Support still needs splitting up.
124
+ * Flipped a lot of internal naming to use Unique.
125
+ * Added ruby_to_c_show (like parse_tree_show).
108
126
 
109
- * 4(ish) bug fixes:
127
+ * 4 bug fixes:
110
128
 
111
- * Use ivars instead of cvars so inheritance won't bugger the translator.
112
- * Corrected unsupported node lists in pipeline.
113
- * Fixed bugs for splat args, iters, optional args, method name map.
114
- * Fixed many other bugs.
129
+ * Use ivars instead of cvars so inheritance won't bugger the translator.
130
+ * Corrected unsupported node lists in pipeline.
131
+ * Fixed bugs for splat args, iters, optional args, method name map.
132
+ * Fixed many other bugs.
115
133
 
116
134
  === 1.0.0-beta-4 / 2005-07-13
117
135
 
118
136
  * 1 minor enhancements:
119
137
 
120
- * Added gemspec (hastily).
138
+ * Added gemspec (hastily).
121
139
 
122
140
  * 2 bug fixes:
123
141
 
124
- * Translates bool type to VALUE since we were using Qtrue/Qfalse.
125
- * Fixed rubygems for non-gem systems.
142
+ * Translates bool type to VALUE since we were using Qtrue/Qfalse.
143
+ * Fixed rubygems for non-gem systems.
126
144
 
127
145
  === 1.0.0-beta-3 / 2005-06-08
128
146
 
129
147
  * 16 minor enhancements:
130
148
 
131
- * Added ivar and iasgn support. Needs more work.
132
- * Added limited support for self.
133
- * Added pipeline tests for bools, call_arglist, call_attrasgn, fbody.
134
- * Added process_not to RubyToC.
135
- * Added support for float and symbol literals.
136
- * Added support for gasgn, cvasgn, const (class consts, not classes).
137
- * Improved error handling/reporting, esp in RubyToC.
138
- * In TypeChecker.boostrap, pre-registered all base classes.
139
- * Modified process_class test to include a class const.
140
- * Processing :class now adds class constants to the local var scope.
141
- * Processing :const checks both genv and env now.
142
- * Rearchitected all tests into a pipeline test class.
143
- * Rewrite attrasgn into regular calls.
144
- * Rewrite fbody into a regular defn.
145
- * Rewrote :array inside call to :arglist.
146
- * Rewrote :or nodes in process_case to correctly be binary.
149
+ * Added ivar and iasgn support. Needs more work.
150
+ * Added limited support for self.
151
+ * Added pipeline tests for bools, call_arglist, call_attrasgn, fbody.
152
+ * Added process_not to RubyToC.
153
+ * Added support for float and symbol literals.
154
+ * Added support for gasgn, cvasgn, const (class consts, not classes).
155
+ * Improved error handling/reporting, esp in RubyToC.
156
+ * In TypeChecker.boostrap, pre-registered all base classes.
157
+ * Modified process_class test to include a class const.
158
+ * Processing :class now adds class constants to the local var scope.
159
+ * Processing :const checks both genv and env now.
160
+ * Rearchitected all tests into a pipeline test class.
161
+ * Rewrite attrasgn into regular calls.
162
+ * Rewrite fbody into a regular defn.
163
+ * Rewrote :array inside call to :arglist.
164
+ * Rewrote :or nodes in process_case to correctly be binary.
147
165
 
148
166
  * 1 bug fix:
149
167
 
150
- * Fixed a bug where single line while bodies were missing a semicolon.
168
+ * Fixed a bug where single line while bodies were missing a semicolon.
151
169
 
152
170
  === 1.0.0-beta-2 / 2005-02-15
153
171
 
154
172
  * 1 minor enhancement:
155
173
 
156
- * Added post-condition while/until support and tests.
174
+ * Added post-condition while/until support and tests.
157
175
 
158
176
  * 4 bug fixes:
159
177
 
160
- * Fixed bug:1422: Escape newlines to prevent multi-line strings in C.
161
- * Fixed bug:1429: Arrays of strings are not being properly.
162
- * Fixed bug:1447/1448: Readme file's website and added ParseTree dependency.
178
+ * Fixed bug:1422: Escape newlines to prevent multi-line strings in C.
179
+ * Fixed bug:1429: Arrays of strings are not being properly.
180
+ * Fixed bug:1447/1448: Readme file's website and added ParseTree dependency.
163
181
 
164
182
  === 1.0.0-beta-1 / 2005-02-01
165
183
 
166
184
  * 1 major enhancements:
167
185
 
168
- * Hit 80% non-error conversion threshold for public beta release.
186
+ * Hit 80% non-error conversion threshold for public beta release.
169
187
 
170
188
  * 3 minor enhancements:
171
189
 
172
- * (Mostly) Filled out functionality in Rewriter and TypeChecker.
173
- * Flushed out what we don't do in RubyToC.
174
- * Wrote a ton of rdoc
190
+ * (Mostly) Filled out functionality in Rewriter and TypeChecker.
191
+ * Flushed out what we don't do in RubyToC.
192
+ * Wrote a ton of rdoc
175
193
 
176
194
  === 1.0.0-a2 / 2004-12-31
177
195
 
178
196
  * 7 major enhancements:
179
197
 
180
- * Alpha 2 released to private group for critique.
181
- * Refactored and split out ParseTree package.
182
- * Gemified dependency on ParseTree.
183
- * Added iter rewriting
184
- * Added post type inference rewriting specific to C library.
185
- * Massive increase to the base we can translate.
186
- * We have stabilized the architecture but still have a ways to go.
198
+ * Alpha 2 released to private group for critique.
199
+ * Refactored and split out ParseTree package.
200
+ * Gemified dependency on ParseTree.
201
+ * Added iter rewriting
202
+ * Added post type inference rewriting specific to C library.
203
+ * Massive increase to the base we can translate.
204
+ * We have stabilized the architecture but still have a ways to go.
187
205
 
188
206
  * 2 minor enhancements:
189
207
 
190
- * Added propaganda (presentations).
191
- * Much better test coverage, now with ZenTest compliant naming.
208
+ * Added propaganda (presentations).
209
+ * Much better test coverage, now with ZenTest compliant naming.
192
210
 
193
211
  * 2 bug fixes:
194
212
 
195
- * Gem-proofed makefile.
196
- * Tons of little fixes we didn't bother to track.
213
+ * Gem-proofed makefile.
214
+ * Tons of little fixes we didn't bother to track.
197
215
 
198
216
  === 1.0.0-a1 / 2004-09-24
199
217
 
200
218
  * 1 major enhancement:
201
219
 
202
- * Birthday! Alpha 1 released to private group for critique.
220
+ * Birthday! Alpha 1 released to private group for critique.
data/README.txt CHANGED
@@ -24,7 +24,7 @@ RubyToC has the following modules:
24
24
 
25
25
  * This is a preview release! BETA BETA BETA! Do NOT use this!
26
26
 
27
- == SYNOPSYS:
27
+ == SYNOPSIS:
28
28
 
29
29
  require 'ruby_parser'
30
30
  require 'ruby_to_ruby_c'
data/Rakefile CHANGED
@@ -19,4 +19,6 @@ Hoe.spec "ruby2c" do
19
19
  dependency "sexp_processor", "~> 4.1"
20
20
  end
21
21
 
22
+ ENV["MT_NO_EXPECTATIONS"] = "1"
23
+
22
24
  # vim: syntax=ruby
@@ -16,10 +16,10 @@ class CRewriter < SexpProcessor
16
16
  # generating the appropriate sexp for that rewriting.
17
17
 
18
18
  REWRITES = {
19
- [Type.str, :+, Type.str] => proc { |l,n,r|
20
- t(:call, nil, :strcat, r.unshift(r.shift, l), Type.str)
19
+ [CType.str, :+, CType.str] => proc { |l,n,r|
20
+ t(:call, nil, :strcat, r.unshift(r.shift, l), CType.str)
21
21
  },
22
- [Type.file, :puts, Type.str] => proc { |l,n,r|
22
+ [CType.file, :puts, CType.str] => proc { |l,n,r|
23
23
  t(:call, nil, :fputs, r.push(l))
24
24
  },
25
25
  }
@@ -35,6 +35,18 @@ class CRewriter < SexpProcessor
35
35
  @extra_methods = []
36
36
  end
37
37
 
38
+ # def rewrite exp
39
+ # result = super
40
+ # result.c_type ||= exp.c_type if Sexp === exp and exp.c_type
41
+ # result
42
+ # end
43
+
44
+ def process exp
45
+ result = super
46
+ result.c_type ||= exp.c_type if Sexp === exp and exp.c_type
47
+ result
48
+ end
49
+
38
50
  def free # REFACTOR: this is a violation of responsibility, should be in Env
39
51
  parent = @env.env[0..-2]
40
52
  bound_in_parent = parent.map { |h| h.keys }.flatten
@@ -57,14 +69,14 @@ class CRewriter < SexpProcessor
57
69
  name = exp.shift
58
70
  rhs = process exp.shift
59
71
 
60
- lhs_type = lhs.sexp_type rescue nil
72
+ lhs_type = lhs.c_type rescue nil
61
73
  type_signature = [lhs_type, name]
62
- type_signature += rhs[1..-1].map { |sexp| sexp.sexp_type } unless rhs.nil?
74
+ type_signature += rhs[1..-1].map { |sexp| sexp.c_type }.to_a unless rhs.nil?
63
75
 
64
76
  result = if REWRITES.has_key? type_signature then
65
77
  REWRITES[type_signature].call(lhs, name, rhs)
66
78
  else
67
- t(:call, lhs, name, rhs, exp.sexp_type)
79
+ t(:call, lhs, name, rhs, exp.c_type)
68
80
  end
69
81
 
70
82
  return result
@@ -83,7 +95,7 @@ class CRewriter < SexpProcessor
83
95
  @extra_methods.reverse_each do |defx| methods.unshift defx end
84
96
  @extra_methods.clear
85
97
 
86
- result = t(:class, klassname, superklassname, Type.zclass)
98
+ result = t(:class, klassname, superklassname, CType.zclass)
87
99
  result.push(*methods)
88
100
 
89
101
  return result
@@ -96,7 +108,7 @@ class CRewriter < SexpProcessor
96
108
  iter_method_name = Unique.next
97
109
 
98
110
  value_var_name = Unique.next
99
- value_var_type = Type.unknown
111
+ value_var_type = CType.unknown
100
112
 
101
113
  memo_var_name = Unique.next
102
114
 
@@ -111,8 +123,8 @@ class CRewriter < SexpProcessor
111
123
 
112
124
  var_names = var_names_in vars
113
125
 
114
- frees = t(:array, Type.void)
115
- statics = t(:array, Type.void)
126
+ frees = t(:array, CType.void)
127
+ statics = t(:array, CType.void)
116
128
  defx_body_block = t(:block)
117
129
 
118
130
  # set statics first so block vars can update statics
@@ -132,7 +144,7 @@ class CRewriter < SexpProcessor
132
144
  var_names.first.last)
133
145
 
134
146
  else # expand block args to masgn
135
- value_var_type = Type.value
147
+ value_var_type = CType.value
136
148
  dyn_vars = t(:array)
137
149
 
138
150
  var_names.each do |name, type|
@@ -141,29 +153,29 @@ class CRewriter < SexpProcessor
141
153
 
142
154
  defx_body_block << t(:masgn,
143
155
  dyn_vars,
144
- t(:to_ary, t(:lvar, value_var_name, Type.value)))
156
+ t(:to_ary, t(:lvar, value_var_name, CType.value)))
145
157
  end
146
158
 
147
159
  defx_body_block << body
148
160
 
149
161
  free_vars.each do |name, static_name, type|
150
162
  defx_body_block << t(:lasgn, static_name, t(:lvar, name, type), type)
151
- @extra_methods << t(:static, "static VALUE #{static_name};", Type.fucked)
163
+ @extra_methods << t(:static, "static VALUE #{static_name};", CType.fucked)
152
164
  end
153
165
 
154
- defx_body_block << t(:return, t(:nil, Type.value))
166
+ defx_body_block << t(:return, t(:nil, CType.value))
155
167
 
156
168
  defx = t(:defx,
157
169
  iter_method_name,
158
170
  t(:args,
159
171
  t(value_var_name, value_var_type),
160
- t(memo_var_name, Type.value)),
172
+ t(memo_var_name, CType.value)),
161
173
  t(:scope, defx_body_block),
162
- Type.void)
174
+ CType.void)
163
175
 
164
176
  @extra_methods << defx
165
177
 
166
- args = t(:args, frees, statics, Type.void)
178
+ args = t(:args, frees, statics, CType.void)
167
179
 
168
180
  return t(:iter, call, args, iter_method_name)
169
181
  end
@@ -172,27 +184,27 @@ class CRewriter < SexpProcessor
172
184
  name = exp.shift
173
185
  value = process(exp.shift)
174
186
 
175
- @env.add name, exp.sexp_type
187
+ @env.add name, exp.c_type
176
188
  @env.set_val name, true
177
189
 
178
- return t(:lasgn, name, value, exp.sexp_type)
190
+ return t(:lasgn, name, value, exp.c_type)
179
191
  end
180
192
 
181
193
  def process_lvar(exp)
182
194
  name = exp.shift
183
195
 
184
- @env.add name, Type.value
196
+ @env.add name, CType.value
185
197
  @env.lookup name rescue @env.set_val name, false
186
198
 
187
- return t(:lvar, name, exp.sexp_type)
199
+ return t(:lvar, name, exp.c_type)
188
200
  end
189
201
 
190
202
  def var_names_in(exp)
191
- return [[exp.last, exp.sexp_type]] if exp.length == 2 and not Sexp === exp.last
203
+ return [[exp.last, exp.c_type]] if exp.length == 2 and not Sexp === exp.last
192
204
 
193
205
  var_names = []
194
206
  exp.each_of_type :dasgn_curr do |sexp|
195
- var_names << [sexp.sexp_body.first, sexp.sexp_type]
207
+ var_names << [sexp.sexp_body.first, sexp.c_type]
196
208
  end
197
209
  return var_names
198
210
  end
@@ -10,8 +10,8 @@ class R2CEnvironment < RubyParserStuff::Environment
10
10
  def add(id, type, depth = 0)
11
11
  raise "Adding illegal identifier #{id.inspect}" unless
12
12
  Symbol === id
13
- raise ArgumentError, "type must be a valid Type instance" unless
14
- Type === type
13
+ raise ArgumentError, "type must be a valid Type instance: #{type.inspect}" unless
14
+ CType === type
15
15
 
16
16
  @env[depth][id.to_s.sub(/^\*/, '').intern][TYPE] = type
17
17
  end
@@ -31,7 +31,7 @@ class R2CEnvironment < RubyParserStuff::Environment
31
31
 
32
32
  def lookup(name)
33
33
  # HACK: if name is :self, cheat for now until we have full defn remapping
34
- return Type.fucked if name == :self
34
+ return CType.fucked if name == :self
35
35
 
36
36
  return self._get(name)[TYPE]
37
37
  end
@@ -1,9 +1,10 @@
1
-
2
1
  begin require 'rubygems'; rescue LoadError; end
3
2
  require 'sexp'
4
3
  require 'sexp_processor'
5
4
  require 'unique'
6
5
 
6
+ require 'typed_sexp' # ensure @@array_types is defined
7
+
7
8
  class Sexp
8
9
  # add arglist because we introduce the new array type in this file
9
10
  @@array_types << :arglist
@@ -31,4 +32,3 @@ class Rewriter < SexpProcessor
31
32
  exp
32
33
  end
33
34
  end
34
-
@@ -20,7 +20,7 @@ require 'r2cenvironment'
20
20
 
21
21
  class RubyToAnsiC < SexpProcessor
22
22
 
23
- VERSION = '1.0.0.9'
23
+ VERSION = '1.1.0'
24
24
 
25
25
  # TODO: remove me
26
26
  def no(exp) # :nodoc:
@@ -160,7 +160,7 @@ typedef char * str;
160
160
  until exp.empty? do
161
161
  arg = exp.shift
162
162
  name = arg.first.to_s.sub(/^\*/, '').intern
163
- type = arg.sexp_type
163
+ type = arg.c_type
164
164
  @env.add name, type
165
165
  args << "#{self.class.c_type(type)} #{name}"
166
166
  end
@@ -212,10 +212,6 @@ typedef char * str;
212
212
  receiver = exp.shift
213
213
  name = exp.shift
214
214
 
215
- receiver_type = Type.unknown
216
- unless receiver.nil? then
217
- receiver_type = receiver.sexp_type
218
- end
219
215
  receiver = process receiver
220
216
 
221
217
  case name
@@ -304,7 +300,7 @@ typedef char * str;
304
300
 
305
301
  def process_dasgn_curr(exp) # TODO: audit against obfuscator
306
302
  var = exp.shift
307
- @env.add var.to_sym, exp.sexp_type
303
+ @env.add var.to_sym, exp.c_type
308
304
  return var.to_s
309
305
  end
310
306
 
@@ -323,7 +319,7 @@ typedef char * str;
323
319
  name = name.to_s.sub(/(.*)\?$/, 'is_\1').intern
324
320
  args = process exp.shift
325
321
  body = process exp.shift
326
- function_type = exp.sexp_type
322
+ function_type = exp.c_type
327
323
 
328
324
  ret_type = self.class.c_type function_type.list_type.return_type
329
325
 
@@ -351,7 +347,7 @@ typedef char * str;
351
347
 
352
348
  def process_dvar(exp)
353
349
  var = exp.shift
354
- @env.add var.to_sym, exp.sexp_type
350
+ @env.add var.to_sym, exp.c_type
355
351
  return var.to_s
356
352
  end
357
353
 
@@ -378,7 +374,7 @@ typedef char * str;
378
374
 
379
375
  def process_gvar(exp)
380
376
  name = exp.shift
381
- type = exp.sexp_type
377
+ type = exp.c_type
382
378
  case name
383
379
  when :$stderr then
384
380
  "stderr"
@@ -486,21 +482,21 @@ typedef char * str;
486
482
  arg_count = value.length - 1 if value.first == :array
487
483
  args = value
488
484
 
489
- exp_type = exp.sexp_type
485
+ exp_type = exp.c_type
490
486
  @env.add var.to_sym, exp_type
491
487
 
492
488
  if exp_type.list? then
493
489
  assert_type args, :array
494
490
 
495
- raise "array must be of one type" unless args.sexp_type == Type.homo
491
+ raise "array must be of one type" unless args.c_type == CType.homo
496
492
 
497
493
  # HACK: until we figure out properly what to do w/ zarray
498
494
  # before we know what its type is, we will default to long.
499
- array_type = args.sexp_types.empty? ? 'void *' : self.class.c_type(args.sexp_types.first)
495
+ array_type = args.c_types.empty? ? 'void *' : self.class.c_type(args.c_types.first)
500
496
 
501
497
  args.shift # :arglist
502
498
  # TODO: look into alloca
503
- out << "#{var} = (#{array_type}) malloc(sizeof(#{array_type}) * #{args.length});\n"
499
+ out << "#{var} = (#{array_type}) malloc(sizeof(#{array_type}) * #{arg_count});\n"
504
500
  args.each_with_index do |o,i|
505
501
  out << "#{var}[#{i}] = #{process o};\n"
506
502
  end
@@ -522,11 +518,11 @@ typedef char * str;
522
518
  # TODO what about floats and big numbers?
523
519
 
524
520
  value = exp.shift
525
- sexp_type = exp.sexp_type
526
- case sexp_type
527
- when Type.long, Type.float then
521
+ c_type = exp.c_type
522
+ case c_type
523
+ when CType.long, CType.float then
528
524
  return value.to_s
529
- when Type.symbol then
525
+ when CType.symbol then
530
526
  return value.to_s.inspect # HACK wrong! write test!
531
527
  else
532
528
  raise "Bug! no: Unknown literal #{value}:#{value.class}"