cumo 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/3rd_party/LICENSE.txt +60 -0
  4. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
  5. data/LICENSE.txt +1 -62
  6. data/README.md +33 -29
  7. data/bench/cumo_bench.rb +47 -25
  8. data/bench/numo_bench.rb +27 -25
  9. data/docs/src-tree.md +16 -0
  10. data/ext/cumo/cuda/cublas.c +69 -219
  11. data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
  12. data/ext/cumo/cuda/runtime.c +2 -14
  13. data/ext/cumo/cumo.c +16 -16
  14. data/ext/cumo/include/cumo.h +2 -2
  15. data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
  16. data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
  17. data/ext/cumo/include/cumo/indexer.h +46 -63
  18. data/ext/cumo/include/cumo/intern.h +58 -112
  19. data/ext/cumo/include/cumo/narray.h +214 -185
  20. data/ext/cumo/include/cumo/narray_kernel.h +66 -37
  21. data/ext/cumo/include/cumo/ndloop.h +42 -42
  22. data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
  23. data/ext/cumo/include/cumo/template.h +56 -51
  24. data/ext/cumo/include/cumo/template_kernel.h +31 -31
  25. data/ext/cumo/include/cumo/types/bit.h +3 -3
  26. data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
  27. data/ext/cumo/include/cumo/types/complex.h +126 -126
  28. data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
  29. data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
  30. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
  31. data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
  32. data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
  33. data/ext/cumo/include/cumo/types/int_macro.h +1 -1
  34. data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
  35. data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
  36. data/ext/cumo/include/cumo/types/scomplex.h +5 -5
  37. data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
  38. data/ext/cumo/narray/array.c +143 -143
  39. data/ext/cumo/narray/data.c +184 -184
  40. data/ext/cumo/narray/gen/cogen.rb +5 -2
  41. data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
  42. data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
  43. data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
  44. data/ext/cumo/narray/gen/erbln.rb +132 -0
  45. data/ext/cumo/narray/gen/erbpp2.rb +18 -13
  46. data/ext/cumo/narray/gen/narray_def.rb +3 -3
  47. data/ext/cumo/narray/gen/spec.rb +2 -2
  48. data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
  49. data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
  50. data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
  51. data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
  52. data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
  53. data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
  54. data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
  55. data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
  56. data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
  57. data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
  58. data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
  59. data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
  60. data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
  61. data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
  62. data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
  63. data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
  64. data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
  65. data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
  66. data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
  67. data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
  68. data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
  69. data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
  70. data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
  71. data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
  72. data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
  73. data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
  74. data/ext/cumo/narray/gen/tmpl/each.c +9 -9
  75. data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
  76. data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
  77. data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
  78. data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
  79. data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
  80. data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
  81. data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
  82. data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
  83. data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
  84. data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
  85. data/ext/cumo/narray/gen/tmpl/format.c +11 -11
  86. data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
  87. data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
  88. data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
  89. data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
  90. data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
  91. data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
  92. data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
  93. data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
  94. data/ext/cumo/narray/gen/tmpl/median.c +10 -10
  95. data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
  96. data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
  97. data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
  98. data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
  99. data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
  100. data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
  101. data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
  102. data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
  103. data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
  104. data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
  105. data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
  106. data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
  107. data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
  108. data/ext/cumo/narray/gen/tmpl/store.c +6 -6
  109. data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
  110. data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
  111. data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
  112. data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
  113. data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
  114. data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
  115. data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
  116. data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
  117. data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
  118. data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
  119. data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
  120. data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
  121. data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
  122. data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
  123. data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
  124. data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
  125. data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
  126. data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
  127. data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
  128. data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
  129. data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
  130. data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
  131. data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
  132. data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
  133. data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
  134. data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
  135. data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
  136. data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
  137. data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
  138. data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
  139. data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
  140. data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
  141. data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
  142. data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
  143. data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
  144. data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
  145. data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
  146. data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
  147. data/ext/cumo/narray/index.c +213 -213
  148. data/ext/cumo/narray/math.c +27 -27
  149. data/ext/cumo/narray/narray.c +484 -484
  150. data/ext/cumo/narray/ndloop.c +259 -258
  151. data/ext/cumo/narray/rand.c +3 -3
  152. data/ext/cumo/narray/step.c +70 -70
  153. data/ext/cumo/narray/struct.c +139 -139
  154. metadata +6 -7
  155. data/ext/cumo/include/cumo/intern_fwd.h +0 -38
  156. data/lib/erbpp.rb +0 -294
  157. data/lib/erbpp/line_number.rb +0 -137
  158. data/lib/erbpp/narray_def.rb +0 -381
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cumo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
@@ -63,6 +63,7 @@ extra_rdoc_files: []
63
63
  files:
64
64
  - ".gitignore"
65
65
  - ".travis.yml"
66
+ - 3rd_party/LICENSE.txt
66
67
  - 3rd_party/mkmf-cu/.gitignore
67
68
  - 3rd_party/mkmf-cu/Gemfile
68
69
  - 3rd_party/mkmf-cu/LICENSE
@@ -86,6 +87,7 @@ files:
86
87
  - bin/console
87
88
  - bin/setup
88
89
  - cumo.gemspec
90
+ - docs/src-tree.md
89
91
  - ext/cumo/cuda/cublas.c
90
92
  - ext/cumo/cuda/driver.c
91
93
  - ext/cumo/cuda/memory_pool.cpp
@@ -108,7 +110,6 @@ files:
108
110
  - ext/cumo/include/cumo/cuda/runtime.h
109
111
  - ext/cumo/include/cumo/indexer.h
110
112
  - ext/cumo/include/cumo/intern.h
111
- - ext/cumo/include/cumo/intern_fwd.h
112
113
  - ext/cumo/include/cumo/intern_kernel.h
113
114
  - ext/cumo/include/cumo/narray.h
114
115
  - ext/cumo/include/cumo/narray_kernel.h
@@ -184,6 +185,7 @@ files:
184
185
  - ext/cumo/narray/gen/def/uint32.rb
185
186
  - ext/cumo/narray/gen/def/uint64.rb
186
187
  - ext/cumo/narray/gen/def/uint8.rb
188
+ - ext/cumo/narray/gen/erbln.rb
187
189
  - ext/cumo/narray/gen/erbpp2.rb
188
190
  - ext/cumo/narray/gen/narray_def.rb
189
191
  - ext/cumo/narray/gen/spec.rb
@@ -320,9 +322,6 @@ files:
320
322
  - lib/cumo/linalg.rb
321
323
  - lib/cumo/narray.rb
322
324
  - lib/cumo/narray/extra.rb
323
- - lib/erbpp.rb
324
- - lib/erbpp/line_number.rb
325
- - lib/erbpp/narray_def.rb
326
325
  - numo-narray-version
327
326
  - run.gdb
328
327
  homepage: https://github.com/sonots/cumo
@@ -345,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
345
344
  version: '0'
346
345
  requirements: []
347
346
  rubyforge_project:
348
- rubygems_version: 2.6.11
347
+ rubygems_version: 2.7.6
349
348
  signing_key:
350
349
  specification_version: 4
351
350
  summary: Cumo is CUDA aware numerical library whose interface is highly compatible
@@ -1,38 +0,0 @@
1
- #ifndef CUMO_INTERN_NARRAY_H
2
- #define CUMO_INTERN_NARRAY_H
3
-
4
- /* Add cumo_ prefix to avoid C symbol collisions with Numo without modifying C implementations */
5
-
6
- #define na_debug_flag cumo_na_debug_flag
7
- extern int cumo_na_debug_flag;
8
-
9
- #define mCumo rb_mCumo
10
- extern VALUE rb_mCumo;
11
- #define cNArray cumo_cNArray
12
- extern VALUE cumo_cNArray;
13
- #define nary_eCastError cumo_nary_eCastError
14
- extern VALUE cumo_nary_eCastError;
15
- #define nary_eShapeError cumo_nary_eShapeError
16
- extern VALUE cumo_nary_eShapeError;
17
- #define nary_eOperationError cumo_nary_eOperationError
18
- extern VALUE cumo_nary_eOperationError;
19
- #define nary_eDimensionError cumo_nary_eDimensionError
20
- extern VALUE cumo_nary_eDimensionError;
21
- #define nary_eValueError cumo_nary_eValueError
22
- extern VALUE cumo_nary_eValueError;
23
- #define na_data_type cumo_na_data_type
24
- extern const rb_data_type_t cumo_na_data_type;
25
-
26
- #define na_cStep cumo_na_cStep
27
- extern VALUE cumo_na_cStep;
28
-
29
- #define sym_reduce cumo_sym_reduce
30
- extern VALUE cumo_sym_reduce;
31
- #define sym_option cumo_sym_option
32
- extern VALUE cumo_sym_option;
33
- #define sym_loop_opt cumo_sym_loop_opt
34
- extern VALUE cumo_sym_loop_opt;
35
- #define sym_init cumo_sym_init
36
- extern VALUE cumo_sym_init;
37
-
38
- #endif /* CUMO_INTERN_NARRAY_H */
@@ -1,294 +0,0 @@
1
- require "erb"
2
-
3
- class ErbPP
4
- ATTRS = []
5
-
6
- class ParamNotSetError < StandardError; end
7
-
8
- def self.define_attrs(attrs)
9
- attrs.each do |attr|
10
- ivar = ("@"+attr).to_sym
11
- define_method(attr){|*a| attr_method(ivar,*a)}
12
- end
13
- end
14
-
15
- def attr_method(ivar,arg=nil)
16
- if arg.nil?
17
- instance_variable_get(ivar)
18
- else
19
- instance_variable_set(ivar,arg)
20
- end
21
- end
22
-
23
- def initialize(parent,erb_path,opts={})
24
- parents.push(parent) if parent
25
- @erb_path = erb_path
26
- @tmpl = @erb_path
27
-
28
- @opts = opts
29
- if @opts.class != Hash
30
- raise ArgumentError, "option is not Hash"
31
- end
32
-
33
- @opts.each do |k,v|
34
- ivar = ("@"+k.to_s).to_sym
35
- instance_variable_set(ivar,v)
36
- end
37
- end
38
-
39
- def load_erb
40
- safe_level = nil
41
- trim_mode = '%<>'
42
- @erb = ERB.new(File.read(@erb_path),safe_level,trim_mode)
43
- @erb.filename = @erb_path
44
- end
45
-
46
- def parents
47
- @parents ||= []
48
- end
49
-
50
- def search_method_in_parents(_meth_id)
51
- parents.each do |x|
52
- if x.has_attr? _meth_id
53
- return x
54
- end
55
- end
56
- parents.each do |x|
57
- if f = x.search_method_in_parents(_meth_id)
58
- return f
59
- end
60
- end
61
- nil
62
- end
63
-
64
- def attrs
65
- self.class::ATTRS
66
- end
67
-
68
- def has_attr?(_meth_id)
69
- respond_to?(_meth_id) or attrs.include?(_meth_id.to_s)
70
- end
71
-
72
- def check_params(*params)
73
- params.each do |x|
74
- val = send(x)
75
- if !val # || val.empty?
76
- raise ParamNotSetError,"parameter #{x.to_s} is not set"
77
- end
78
- end
79
- end
80
-
81
- alias method_missing_alias method_missing
82
-
83
- def method_missing(_meth_id, *args, &block)
84
- ivar = "@"+_meth_id.to_s
85
- if args.empty? and instance_variable_defined?(ivar)
86
- parm = instance_variable_get(ivar)
87
- if parm.nil?
88
- raise ParamNotSetError,"parameter #{_meth_id.to_s} is not set"
89
- end
90
- parm
91
- elsif args.size == 1 and attrs.include?(_meth_id.to_s)
92
- instance_variable_set(ivar,args.first)
93
- elsif x = search_method_in_parents(_meth_id)
94
- x.send(_meth_id, *args, &block)
95
- else
96
- method_missing_alias(_meth_id, *args)
97
- end
98
- end
99
-
100
- def run
101
- load_erb unless @erb
102
- @erb.run(binding)
103
- end
104
-
105
- def result
106
- load_erb unless @erb
107
- @erb.result(binding)
108
- end
109
- end
110
-
111
- # ----------------------------------------------------------------------
112
-
113
- class IdVar
114
- DEFS = []
115
-
116
- def id_decl
117
- "static ID #{@id_var};"
118
- end
119
-
120
- def id_assign
121
- "#{@id_var} = rb_intern(\"#{@name}\");"
122
- end
123
-
124
- def initialize(parent,name,var=nil)
125
- @name = name
126
- var = name if var.nil?
127
- @id_var = "id_"+var.gsub(/\?/,"_p").gsub(/\!/,"_bang")
128
- DEFS.push(self)
129
- end
130
-
131
- def self.declaration
132
- DEFS.map do |x|
133
- x.id_decl
134
- end
135
- end
136
-
137
- def self.assignment
138
- DEFS.map do |x|
139
- x.id_assign
140
- end
141
- end
142
- end
143
-
144
- # ----------------------------------------------------------------------
145
-
146
- class Function < ErbPP
147
- DEFS = []
148
-
149
- attrs = %w[
150
- singleton
151
- meth
152
- n_arg
153
- ]
154
- define_attrs attrs
155
-
156
- def id_op
157
- if op.size == 1
158
- "'#{op}'"
159
- else
160
- "id_#{method}"
161
- end
162
- end
163
-
164
- def method
165
- meth.gsub(/\?/,"_p").gsub(/\!/,"_bang")
166
- end
167
-
168
- def initialize(parent,tmpl,**opts)
169
- super
170
- @aliases = opts[:aliases] || []
171
- parent.tmpl_dirs.each do |d|
172
- @erb_path = File.join(d, tmpl+".c")
173
- break if File.exist?(@erb_path)
174
- end
175
- DEFS.push(self)
176
- end
177
-
178
- def c_method
179
- "#{m_prefix}#{method}"
180
- end
181
-
182
- def c_iter
183
- begin
184
- t = "_"+type_name
185
- rescue
186
- t = ""
187
- end
188
- "iter#{t}_#{method}"
189
- end
190
- alias c_iterator c_iter
191
-
192
- def c_func
193
- s = singleton ? "_s" : ""
194
- begin
195
- t = "_"+type_name
196
- rescue
197
- t = ""
198
- end
199
- "cumo#{t}#{s}_#{method}"
200
- end
201
- alias c_function c_func
202
- alias c_instance_method c_func
203
-
204
- def op_map
205
- @op || meth
206
- end
207
-
208
- def code
209
- result + "\n\n"
210
- end
211
-
212
- def definition
213
- return nil if n_arg <= -9
214
- s = singleton ? "_singleton" : ""
215
- check_params(:mod_var, :op_map, :c_func, :n_arg)
216
- m = op_map
217
- a = ["rb_define#{s}_method(#{mod_var}, \"#{m}\", #{c_func}, #{n_arg});"]
218
- @aliases.map{|x| a << "rb_define_alias(#{mod_var}, \"#{x}\", \"#{m}\");"}
219
- a
220
- end
221
-
222
- def self.codes
223
- a = []
224
- DEFS.each do |i|
225
- x = i.code
226
- a.push(x) if x
227
- end
228
- a
229
- end
230
-
231
- def self.definitions
232
- a = []
233
- DEFS.each do |i|
234
- case x = i.definition
235
- when Array
236
- a.concat(x)
237
- when String
238
- a.push(x)
239
- else
240
- raise "unknown definition: #{x}" if x
241
- end
242
- end
243
- a
244
- end
245
- end
246
-
247
- class ModuleFunction < Function
248
- def definition
249
- m = op_map
250
- "rb_define_module_function(#{mod_var}, \"#{m}\", #{c_func}, #{n_arg});"
251
- end
252
- end
253
-
254
- class NodefFunction < Function
255
- def definition
256
- nil
257
- end
258
- end
259
-
260
- class Alias < ErbPP
261
- def initialize(parent, dst, src)
262
- super(parent,nil)
263
- @dst = dst
264
- @src = src
265
- Function::DEFS.push(self)
266
- end
267
-
268
- def code
269
- nil
270
- end
271
-
272
- def definition
273
- "rb_define_alias(#{mod_var}, \"#{dst}\", \"#{src}\");"
274
- end
275
- end
276
-
277
- class Const < ErbPP
278
- def initialize(parent,name,value,desc)
279
- super(parent,nil)
280
- @name = name
281
- @value = value
282
- @desc = desc
283
- Function::DEFS.push(self)
284
- end
285
-
286
- def code
287
- nil
288
- end
289
-
290
- def definition
291
- "/*"+desc+"*/\n "+
292
- "rb_define_const(#{mod_var},\"#{name}\",#{value});"
293
- end
294
- end
@@ -1,137 +0,0 @@
1
- class CountLnString < String
2
-
3
- def initialize(filename)
4
- @filename = filename
5
- @lnchar = "\n"
6
- @buf = ""
7
- @str = ""
8
- @countln = 1
9
- @current = 1
10
- super("\n"+report_line)
11
- end
12
-
13
- def report_line
14
- "#line #{@current} \"#{@filename}\"\n"
15
- end
16
-
17
- def concat0(s)
18
- ln(caller[0])
19
- @buf.concat(s)
20
- @str.concat(s)
21
- end
22
-
23
- def concat1(s)
24
- ln(caller[0])
25
- @buf.concat(s)
26
- end
27
-
28
- def ln(status=nil)
29
- case status
30
- when /:(\d+):/
31
- n = $1.to_i
32
- else
33
- n = status.to_i
34
- end
35
- return if n == @current
36
- if @current != @countln || @postpone
37
- if /\A\s*\z/ =~ @str || /\A#line / =~ @buf
38
- @postpone = true
39
- elsif @in_comment
40
- @postpone = false
41
- else
42
- if self[-1] != "\n"
43
- concat("\n")
44
- end
45
- concat(report_line)
46
- @postpone = false
47
- end
48
- end
49
- concat(@buf)
50
-
51
- b = @buf.gsub(/".*?(?<!\\)"/,'""')
52
- /^.*(\/\*)(.*?)$/ =~ b
53
- x = $2
54
- /^.*(\*\/)(.*?)$/ =~ b
55
- y = $2
56
- if x
57
- if y
58
- if x.size < y.size
59
- #:in_comment
60
- @in_comment = true
61
- else
62
- #:out_comment
63
- @in_comment = false
64
- end
65
- else
66
- #:in_comment
67
- @in_comment = true
68
- end
69
- else
70
- if y
71
- #:out_comment
72
- @in_comment = false
73
- else
74
- #:keep
75
- end
76
- end
77
-
78
- @countln = @current + @buf.count(@lnchar)
79
- @current = n
80
- @buf = ""
81
- @str = ""
82
- end
83
-
84
- def d(s)
85
- p [s, [x,y], r]
86
- r
87
- end
88
-
89
- def final
90
- concat(@buf)
91
- end
92
-
93
- end
94
-
95
- class ERB
96
- alias result_orig result
97
-
98
- def result(b=new_toplevel)
99
- src = src_with_cpp_line
100
- if @safe_level
101
- proc {
102
- $SAFE = @safe_level
103
- eval(src, b, (@filename || '(erb)'), 0)
104
- }.call
105
- else
106
- #open("tmpout","w"){|f| f.write src} if /dtype/=~@filename
107
- eval(src, b, (@filename || '(erb)'), 0)
108
- end
109
- end
110
-
111
- alias src_orig src
112
-
113
- def src
114
- src_with_cpp_line
115
- end
116
-
117
- def src_with_cpp_line
118
- @src.each_line.with_index.map do |line, num|
119
- # ruby ver 2.4 or earlier
120
- line.gsub!(/_erbout.concat "/,'_erbout.concat0 "')
121
- line.gsub!(/_erbout.concat\(/,'_erbout.concat1(')
122
- # ruby ver 2.5
123
- line.gsub!(/_erbout\.<<\(-/,'_erbout.concat0(-')
124
- line.gsub!(/_erbout\.<<\(\(/, '_erbout.concat1((')
125
- if num==0
126
- # skip
127
- elsif num==1
128
- f = @filename.dump
129
- line.sub!(/_erbout = (\+?''|String\.new);/, "_erbout = CountLnString.new(#{f});")
130
- elsif /^; _erbout\.force_encoding/ =~ line
131
- line.sub!(/^;/,";_erbout.ln(#{num});")
132
- end
133
- line
134
- end.join+";_erbout.final;"
135
- end
136
-
137
- end