cgen 0.16.3 → 0.16.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/lib/cgen/cgen.rb +25 -19
- data/rakefile +3 -3
- data/test/test-attribute.rb +15 -6
- metadata +8 -8
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
cgen 0.16.4
|
2
|
+
|
3
|
+
- api addition: module and symbol declarations can optionally be sent
|
4
|
+
to other file rather than libmain; this supports better separate
|
5
|
+
compilation (in redshift)
|
6
|
+
|
7
|
+
- generated main file is now called libmain.c
|
8
|
+
|
1
9
|
cgen 0.16.3
|
2
10
|
|
3
11
|
- misc fixes for 1.9 compatibility
|
data/lib/cgen/cgen.rb
CHANGED
@@ -418,7 +418,7 @@ require 'cgen/inherit'
|
|
418
418
|
# way that makes clear that the problem is really with commit.
|
419
419
|
module CGenerator
|
420
420
|
|
421
|
-
VERSION = '0.16.
|
421
|
+
VERSION = '0.16.4'
|
422
422
|
|
423
423
|
class Accumulator ## should be a mixin? "Cumulative"?
|
424
424
|
|
@@ -614,7 +614,7 @@ class Library < Template
|
|
614
614
|
"\n Name must be a C identifier."
|
615
615
|
end
|
616
616
|
|
617
|
-
@include_file, @source_file = add_file
|
617
|
+
@include_file, @source_file = add_file "libmain"
|
618
618
|
@include_file.include '<ruby.h>'
|
619
619
|
|
620
620
|
@init_library_function = define_c_function "Init_" + name
|
@@ -886,18 +886,23 @@ class Library < Template
|
|
886
886
|
def makedepend
|
887
887
|
return if /mswin/i =~ RUBY_PLATFORM ## what else can we do?
|
888
888
|
build_wrapper do
|
889
|
+
cpat = "*.c"
|
890
|
+
chpat = "*.[ch]"
|
891
|
+
dep = "depend"
|
892
|
+
return if Dir[cpat].all? {|f| test ?<, f, dep}
|
893
|
+
|
889
894
|
cfg = Config::CONFIG
|
890
895
|
dirs = [cfg["sitearchdir"], cfg["archdir"], cfg["includedir"]]
|
891
896
|
|
892
897
|
case cfg["CC"]
|
893
898
|
when /gcc/
|
894
899
|
makedepend_cmd =
|
895
|
-
"#{cfg["CC"]} -MM
|
900
|
+
"#{cfg["CC"]} -MM #{cpat} -I#{dirs.join " -I"} >#{dep} 2>#{@logname}"
|
896
901
|
|
897
902
|
else
|
898
903
|
makedepend_cmd =
|
899
|
-
"touch
|
900
|
-
makedepend -
|
904
|
+
"touch #{dep} && \
|
905
|
+
makedepend -f#{dep} #{cpat} -I#{dirs.join " -I"} >#{@logname} 2>&1"
|
901
906
|
end
|
902
907
|
|
903
908
|
result = system makedepend_cmd
|
@@ -1028,6 +1033,7 @@ class Library < Template
|
|
1028
1033
|
c_name = spec[:c_name]
|
1029
1034
|
mod = spec[:mod]
|
1030
1035
|
rb_name = spec[:rb_name]
|
1036
|
+
cfile = spec[:cfile]
|
1031
1037
|
|
1032
1038
|
meth_rec =
|
1033
1039
|
if c_name
|
@@ -1047,7 +1053,7 @@ class Library < Template
|
|
1047
1053
|
|
1048
1054
|
kind = @name.to_s.sub(/\Arb_define_/, "")
|
1049
1055
|
if mod
|
1050
|
-
meth_rec[:mod_c_name] ||= @parent.declare_module(mod) ## @parent ?
|
1056
|
+
meth_rec[:mod_c_name] ||= @parent.declare_module(mod, cfile) ## @parent ?
|
1051
1057
|
meth_rec[:c_name] ||=
|
1052
1058
|
("#{CGenerator::make_c_name rb_name}" +
|
1053
1059
|
"_#{meth_rec[:mod_c_name]}_#{kind}").intern
|
@@ -1200,20 +1206,20 @@ class Library < Template
|
|
1200
1206
|
#
|
1201
1207
|
# The second declaration notices that the library already has a variable that
|
1202
1208
|
# will be initialized to the ID of the symbol, and uses it.
|
1203
|
-
def declare_module mod
|
1209
|
+
def declare_module mod, cfile = nil
|
1204
1210
|
c_name = "module_#{CGenerator::make_c_name mod.to_s}"
|
1205
1211
|
declare mod => "VALUE #{c_name}"
|
1206
|
-
declare_extern mod => "extern VALUE #{c_name}"
|
1212
|
+
(cfile || self).declare_extern mod => "extern VALUE #{c_name}"
|
1207
1213
|
setup mod => "#{c_name} = rb_path2class(\"#{mod}\")"
|
1208
1214
|
c_name.intern
|
1209
1215
|
end
|
1210
1216
|
alias declare_class declare_module
|
1211
1217
|
|
1212
1218
|
# See #declare_module.
|
1213
|
-
def declare_symbol sym
|
1219
|
+
def declare_symbol sym, cfile = nil
|
1214
1220
|
c_name = "ID_#{CGenerator::make_c_name sym}"
|
1215
1221
|
declare sym => "ID #{c_name}"
|
1216
|
-
declare_extern sym => "extern ID #{c_name}"
|
1222
|
+
(cfile || self).declare_extern sym => "extern ID #{c_name}"
|
1217
1223
|
setup sym => "#{c_name} = rb_intern(\"#{sym}\")"
|
1218
1224
|
c_name.intern
|
1219
1225
|
end
|
@@ -1221,10 +1227,10 @@ class Library < Template
|
|
1221
1227
|
# Like Library#declare_symbol, but converts the ID to a VALUE at library
|
1222
1228
|
# initialization time. Useful for looking up hash values keyed by symbol
|
1223
1229
|
# objects, for example. +sym+ is a string or symbol.
|
1224
|
-
def literal_symbol sym
|
1230
|
+
def literal_symbol sym, cfile = nil
|
1225
1231
|
c_name = "SYM_#{CGenerator::make_c_name sym}"
|
1226
1232
|
declare sym => "VALUE #{c_name}"
|
1227
|
-
declare_extern sym => "extern VALUE #{c_name}"
|
1233
|
+
(cfile || self).declare_extern sym => "extern VALUE #{c_name}"
|
1228
1234
|
setup sym => "#{c_name} = ID2SYM(rb_intern(\"#{sym}\"))"
|
1229
1235
|
c_name.intern
|
1230
1236
|
end
|
@@ -1328,10 +1334,10 @@ class CFile < CFragment
|
|
1328
1334
|
|
1329
1335
|
attr_reader :include_file
|
1330
1336
|
|
1331
|
-
def initialize name, library, include_file = nil
|
1337
|
+
def initialize name, library, include_file = nil, bare = !!include_file
|
1332
1338
|
super name, library
|
1333
1339
|
@include_file = include_file
|
1334
|
-
if
|
1340
|
+
if bare
|
1335
1341
|
add preamble!, include!, declare!, define!
|
1336
1342
|
else
|
1337
1343
|
## it's a little hacky to decide in this way that this is a .h file
|
@@ -1416,7 +1422,7 @@ class CFile < CFragment
|
|
1416
1422
|
unless subclass <= Method ## should use assert
|
1417
1423
|
raise "#{subclass.name} is not <= Method"
|
1418
1424
|
end
|
1419
|
-
c_name =
|
1425
|
+
c_name = rb_define_method :mod => mod, :rb_name => name, :cfile => self
|
1420
1426
|
define c_name, subclass
|
1421
1427
|
end
|
1422
1428
|
|
@@ -1424,7 +1430,7 @@ class CFile < CFragment
|
|
1424
1430
|
# Used to break large projects up into many files.
|
1425
1431
|
def define_c_module_function mod, name, subclass = ModuleFunction
|
1426
1432
|
raise unless subclass <= ModuleFunction
|
1427
|
-
c_name =
|
1433
|
+
c_name = rb_define_module_function :mod => mod, :rb_name => name, :cfile => self
|
1428
1434
|
define c_name, subclass
|
1429
1435
|
end
|
1430
1436
|
|
@@ -1432,7 +1438,7 @@ class CFile < CFragment
|
|
1432
1438
|
# Used to break large projects up into many files.
|
1433
1439
|
def define_c_global_function name, subclass = GlobalFunction
|
1434
1440
|
raise unless subclass <= GlobalFunction
|
1435
|
-
c_name =
|
1441
|
+
c_name = rb_define_global_function :rb_name => name, :cfile => self
|
1436
1442
|
define c_name, subclass
|
1437
1443
|
end
|
1438
1444
|
|
@@ -1440,13 +1446,13 @@ class CFile < CFragment
|
|
1440
1446
|
# Used to break large projects up into many files.
|
1441
1447
|
def define_c_singleton_method mod, name, subclass = SingletonMethod
|
1442
1448
|
raise unless subclass <= SingletonMethod
|
1443
|
-
c_name =
|
1449
|
+
c_name = rb_define_singleton_method :mod => mod, :rb_name => name, :cfile => self
|
1444
1450
|
define c_name, subclass
|
1445
1451
|
end
|
1446
1452
|
alias define_c_class_method define_c_singleton_method
|
1447
1453
|
|
1448
1454
|
def define_alloc_func klass
|
1449
|
-
klass_c_name = declare_class klass
|
1455
|
+
klass_c_name = declare_class klass, self # cfile
|
1450
1456
|
c_name = "alloc_func_#{klass_c_name}"
|
1451
1457
|
library.init_library_function.body \
|
1452
1458
|
%{rb_define_alloc_func(#{klass_c_name}, #{c_name})}
|
data/rakefile
CHANGED
@@ -11,9 +11,7 @@ Bones {
|
|
11
11
|
name 'cgen'
|
12
12
|
authors 'Joel VanderWerf'
|
13
13
|
email 'vjoel@users.sourceforge.net'
|
14
|
-
|
15
|
-
# url 'http://rubygems.org/gems/cgen'
|
16
|
-
url 'http://gemcutter.org/gems/cgen'
|
14
|
+
url 'http://rubyforge.org/projects/cgen'
|
17
15
|
rubyforge.name 'cgen'
|
18
16
|
version CGenerator::VERSION
|
19
17
|
readme_file 'README.txt'
|
@@ -32,6 +30,8 @@ END
|
|
32
30
|
test.files = Dir["test/test-*.rb"]
|
33
31
|
}
|
34
32
|
|
33
|
+
task 'gem:release' => 'rubyforge:release' # to release to rubyforge as well
|
34
|
+
|
35
35
|
task :release => ["rubyforge:release", "rubyforge:doc_release"]
|
36
36
|
|
37
37
|
# EOF
|
data/test/test-attribute.rb
CHANGED
@@ -53,6 +53,12 @@ class ObjectAttributeTest < AttributeTest
|
|
53
53
|
def make_thing c
|
54
54
|
@oas.x = c.new
|
55
55
|
end
|
56
|
+
|
57
|
+
def make_things c, n
|
58
|
+
10.times do
|
59
|
+
make_thing c
|
60
|
+
end
|
61
|
+
end
|
56
62
|
|
57
63
|
def trash_thing
|
58
64
|
@oas.x = nil
|
@@ -62,9 +68,8 @@ class ObjectAttributeTest < AttributeTest
|
|
62
68
|
@oas = ObjectAttributeSample.new
|
63
69
|
c = Class.new
|
64
70
|
|
65
|
-
10
|
66
|
-
|
67
|
-
end
|
71
|
+
make_things c, 10
|
72
|
+
|
68
73
|
GC.start
|
69
74
|
assert_equal(1, ObjectSpace.each_object(c) {})
|
70
75
|
end
|
@@ -130,6 +135,12 @@ class ShadowObjectAttributeTest < AttributeTest
|
|
130
135
|
def make_thing c
|
131
136
|
@sas.x = c.new
|
132
137
|
end
|
138
|
+
|
139
|
+
def make_things c, n
|
140
|
+
n.times do
|
141
|
+
make_thing c
|
142
|
+
end
|
143
|
+
end
|
133
144
|
|
134
145
|
def trash_thing
|
135
146
|
@sas.x = nil
|
@@ -141,9 +152,7 @@ class ShadowObjectAttributeTest < AttributeTest
|
|
141
152
|
|
142
153
|
GC.start
|
143
154
|
n = ObjectSpace.each_object(c) {}
|
144
|
-
10
|
145
|
-
make_thing c
|
146
|
-
end
|
155
|
+
make_things c, 10
|
147
156
|
GC.start
|
148
157
|
assert_equal(n+1, ObjectSpace.each_object(c) {})
|
149
158
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 87
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 16
|
9
|
-
-
|
10
|
-
version: 0.16.
|
9
|
+
- 4
|
10
|
+
version: 0.16.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joel VanderWerf
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-26 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 25
|
30
30
|
segments:
|
31
31
|
- 3
|
32
32
|
- 4
|
33
|
-
-
|
34
|
-
version: 3.4.
|
33
|
+
- 7
|
34
|
+
version: 3.4.7
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
description: |
|
@@ -89,7 +89,7 @@ files:
|
|
89
89
|
- test/test-cshadow.rb
|
90
90
|
- test/test.rb
|
91
91
|
has_rdoc: true
|
92
|
-
homepage: http://
|
92
|
+
homepage: http://rubyforge.org/projects/cgen
|
93
93
|
licenses: []
|
94
94
|
|
95
95
|
post_install_message:
|