cplus2ruby 1.0.0 → 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.
data/README CHANGED
@@ -84,7 +84,7 @@ EXAMPLE
84
84
  #
85
85
  # Generate C++ code, compile and load shared library.
86
86
  #
87
- Cplus2Ruby.startup('work/neural')
87
+ Cplus2Ruby.commit('work/neural')
88
88
 
89
89
  n = Neuron.new
90
90
  n.id = "n1"
@@ -189,7 +189,7 @@ FEATURES
189
189
 
190
190
  Compilation flags etc.:
191
191
 
192
- Cplus2Ruby.startup(module_name, force_compilation, cflags, ldflags)
192
+ Cplus2Ruby.commit(module_name, force_compilation, cflags, ldflags)
193
193
 
194
194
  For example:
195
195
 
@@ -197,7 +197,7 @@ FEATURES
197
197
  # force_compilation => true regenerates and recompiles the
198
198
  # C++ code every time.
199
199
  #
200
- Cplus2Ruby.startup("work/mymodule", true, '-DNDEBUG -Winline -Wall', '-lm')
200
+ Cplus2Ruby.commit("work/mymodule", true, '-DNDEBUG -Winline -Wall', '-lm')
201
201
 
202
202
  BUGS
203
203
 
data/cplus2ruby.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = "cplus2ruby"
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
  s.summary = "Gluing C++ and Ruby together in an OO manner"
7
7
  s.files = Dir['**/*']
8
8
  s.add_dependency('facets', '>= 2.3.0')
data/example.rb CHANGED
@@ -34,7 +34,7 @@ if __FILE__ == $0
34
34
  #
35
35
  # Generate C++ code, compile and load shared library.
36
36
  #
37
- Cplus2Ruby.startup('work/neural')
37
+ Cplus2Ruby.commit('work/neural')
38
38
 
39
39
  n = Neuron.new
40
40
  n.id = "n1"
@@ -13,7 +13,7 @@ class Cplus2Ruby::Compiler
13
13
  wrap_cg.write_files(mod_name)
14
14
  end
15
15
 
16
- def startup(file, force_compilation=false, cflags="", libs="", &block)
16
+ def commit(file, force_compilation=false, cflags="", libs="", &block)
17
17
  n = names(file)
18
18
 
19
19
  if not force_compilation
@@ -30,6 +30,8 @@ class Cplus2Ruby::Compiler
30
30
  block.call if block
31
31
  end
32
32
 
33
+ alias startup commit
34
+
33
35
  #
34
36
  # Compiles +file+. Returns the name of the shared object to
35
37
  # use by +require+.
@@ -45,27 +45,34 @@ class Cplus2Ruby::Model
45
45
  usage_cnt
46
46
  end
47
47
 
48
- def entities_ordered
49
- entities().sort {|a, b|
50
- if a.ancestors.include?(b)
51
- # a 'after' b (a > b)
52
- 1
53
- elsif b.ancestors.include?(a)
48
+ def cmp_entities(a,b)
49
+ if a.ancestors.include?(b)
50
+ # a 'after' b (a > b)
51
+ 1
52
+ elsif b.ancestors.include?(a)
53
+ -1
54
+ else
55
+ ea = entity_usage(a, b)
56
+ eb = entity_usage(b, a)
57
+
58
+ if ea > 0 and eb == 0
54
59
  -1
60
+ elsif eb > 0 and ea == 0
61
+ 1
55
62
  else
56
- ea = entity_usage(a, b)
57
- eb = entity_usage(b, a)
58
-
59
- if ea > 0 and eb == 0
60
- -1
61
- elsif eb > 0 and ea == 0
62
- 1
63
- else
64
- ao = (a.heritage(:__options__) || {})[:order] || 0
65
- bo = (b.heritage(:__options__) || {})[:order] || 0
66
- ao <=> bo
67
- end
63
+ ao = (a.heritage(:__options__) || {})[:order] || 0
64
+ bo = (b.heritage(:__options__) || {})[:order] || 0
65
+ ao <=> bo
68
66
  end
67
+ end
68
+ end
69
+
70
+ def entities_ordered
71
+ ents = entities()
72
+ ents.sort_by {|entity|
73
+ ents.inject(0) {|accum, e|
74
+ accum + (cmp_entities(entity, e) == 1 ? 1 : 0)
75
+ }
69
76
  }
70
77
  end
71
78
 
@@ -114,9 +121,13 @@ module Cplus2Ruby
114
121
  h.each {|from, to| model.typing.alias_entry(from, to)}
115
122
  end
116
123
 
117
- def self.startup(*args, &block)
124
+ def self.commit(*args, &block)
118
125
  self.model.finish!
119
- Cplus2Ruby::Compiler.new(self.model).startup(*args, &block)
126
+ Cplus2Ruby::Compiler.new(self.model).commit(*args, &block)
127
+ end
128
+
129
+ def self.startup(*args, &block)
130
+ commit(*args, &block)
120
131
  end
121
132
 
122
133
  def self.compile(*args)
data/test/test_mixin.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- $LOAD_PATH.unshift '../src'
2
+ $LOAD_PATH.unshift '../lib'
3
3
  require 'cplus2ruby'
4
4
 
5
5
  module Mixin1; cplus2ruby
@@ -18,7 +18,7 @@ class C < B; cplus2ruby
18
18
  property :z, :int
19
19
  end
20
20
 
21
- Cplus2Ruby.startup('work/test_mixin', true)
21
+ Cplus2Ruby.commit('work/test_mixin', true)
22
22
  t = B.new
23
23
  t.y = 2
24
24
  p t.y
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cplus2ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Neumann
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-16 00:00:00 +01:00
12
+ date: 2008-03-26 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,14 +44,6 @@ files:
44
44
  - lib/cplus2ruby/code_generator.rb
45
45
  - test
46
46
  - test/test_mixin.rb
47
- - test/work
48
- - test/work/test_mixin.h
49
- - test/work/test_mixin.o
50
- - test/work/test_mixin.cc
51
- - test/work/Makefile
52
- - test/work/test_mixin.so
53
- - test/work/test_mixin_wrap.cc
54
- - test/work/test_mixin_wrap.o
55
47
  has_rdoc: false
56
48
  homepage: http://www.ntecs.de/projects/cplus2ruby/
57
49
  post_install_message:
data/test/work/Makefile DELETED
@@ -1,149 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /usr/local/lib/ruby/1.8/i386-freebsd7
8
- hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
10
- prefix = $(DESTDIR)/usr/local
11
- exec_prefix = $(prefix)
12
- sitedir = $(prefix)/lib/ruby/site_ruby
13
- rubylibdir = $(libdir)/ruby/$(ruby_version)
14
- docdir = $(datarootdir)/doc/$(PACKAGE)
15
- dvidir = $(docdir)
16
- datarootdir = $(prefix)/share
17
- archdir = $(rubylibdir)/$(arch)
18
- sbindir = $(exec_prefix)/sbin
19
- psdir = $(docdir)
20
- localedir = $(datarootdir)/locale
21
- htmldir = $(docdir)
22
- datadir = $(datarootdir)
23
- includedir = $(prefix)/include
24
- infodir = $(DESTDIR)/usr/local/info/
25
- sysconfdir = $(prefix)/etc
26
- mandir = $(DESTDIR)/usr/local/man
27
- libdir = $(exec_prefix)/lib
28
- sharedstatedir = $(prefix)/com
29
- oldincludedir = $(DESTDIR)/usr/include
30
- pdfdir = $(docdir)
31
- sitearchdir = $(sitelibdir)/$(sitearch)
32
- bindir = $(exec_prefix)/bin
33
- localstatedir = $(prefix)/var
34
- sitelibdir = $(sitedir)/$(ruby_version)
35
- libexecdir = $(exec_prefix)/libexec
36
-
37
- CC = cc
38
- LIBRUBY = $(LIBRUBY_SO)
39
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
- LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)
41
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
42
-
43
- RUBY_EXTCONF_H =
44
- CFLAGS = -fPIC
45
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
46
- CPPFLAGS =
47
- CXXFLAGS = $(CFLAGS)
48
- DLDFLAGS = -L. -rdynamic -Wl,-soname,$(.TARGET)
49
- LDSHARED = cc -shared
50
- AR = ar
51
- EXEEXT =
52
-
53
- RUBY_INSTALL_NAME = ruby18
54
- RUBY_SO_NAME = ruby18
55
- arch = i386-freebsd7
56
- sitearch = i386-freebsd7
57
- ruby_version = 1.8
58
- ruby = /usr/local/bin/ruby18
59
- RUBY = $(ruby)
60
- RM = rm -f
61
- MAKEDIRS = mkdir -p
62
- INSTALL = /usr/bin/install -c -o root -g wheel
63
- INSTALL_PROG = $(INSTALL) -m 0755
64
- INSTALL_DATA = install -o root -g wheel -m 444
65
- COPY = cp
66
-
67
- #### End of system configuration section. ####
68
-
69
- preload =
70
-
71
- libpath = . $(libdir)
72
- LIBPATH = -L'.' -L'$(libdir)' -Wl,-R'$(libdir)'
73
- DEFFILE =
74
-
75
- CLEANFILES = mkmf.log
76
- DISTCLEANFILES =
77
-
78
- extout =
79
- extout_prefix =
80
- target_prefix =
81
- LOCAL_LIBS =
82
- LIBS = $(LIBRUBYARG_SHARED) -lcrypt -lm -rpath=/usr/lib:/usr/local/lib -pthread -lc -lstdc++
83
- SRCS = test_mixin.cc test_mixin_wrap.cc
84
- OBJS = test_mixin.o test_mixin_wrap.o
85
- TARGET = test_mixin
86
- DLLIB = $(TARGET).so
87
- EXTSTATIC =
88
- STATIC_LIB =
89
-
90
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
91
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
92
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
93
-
94
- TARGET_SO = $(DLLIB)
95
- CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
96
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
97
-
98
- all: $(DLLIB)
99
- static: $(STATIC_LIB)
100
-
101
- clean:
102
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
103
-
104
- distclean: clean
105
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
106
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
107
-
108
- realclean: distclean
109
- install: install-so install-rb
110
-
111
- install-so: $(RUBYARCHDIR)
112
- install-so: $(RUBYARCHDIR)/$(DLLIB)
113
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
114
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
115
- install-rb: pre-install-rb install-rb-default
116
- install-rb-default: pre-install-rb-default
117
- pre-install-rb: Makefile
118
- pre-install-rb-default: Makefile
119
- $(RUBYARCHDIR):
120
- $(MAKEDIRS) $@
121
-
122
- site-install: site-install-so site-install-rb install
123
- site-install-so: install-so
124
- site-install-rb: install-rb
125
-
126
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
127
-
128
- .cc.o:
129
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
130
-
131
- .cxx.o:
132
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
133
-
134
- .cpp.o:
135
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
136
-
137
- .C.o:
138
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
139
-
140
- .c.o:
141
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
142
-
143
- $(DLLIB): $(OBJS)
144
- @-$(RM) $@
145
- $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
146
-
147
-
148
-
149
- $(OBJS): ruby.h defines.h
@@ -1,23 +0,0 @@
1
- #include "test_mixin.h"
2
-
3
-
4
- A::A()
5
- {
6
- this->y = 0;
7
- }
8
-
9
-
10
-
11
- B::B()
12
- {
13
- this->a = 0;
14
- }
15
-
16
-
17
-
18
- C::C()
19
- {
20
- this->z = 0;
21
- }
22
-
23
-
@@ -1,51 +0,0 @@
1
- #include <stdlib.h>
2
- #include "ruby.h"
3
- struct RubyObject {
4
- VALUE __obj__;
5
- RubyObject() { __obj__ = Qnil; }
6
- virtual ~RubyObject() {};
7
- static void __free(void *ptr) { ((RubyObject*)ptr)->__free__(); }
8
- static void __mark(void *ptr) { ((RubyObject*)ptr)->__mark__(); }
9
- virtual void __free__() { delete this; }
10
- virtual void __mark__() { }
11
- };
12
- struct A;
13
- struct B;
14
- struct C;
15
-
16
- struct A : RubyObject
17
- {
18
- typedef RubyObject super;
19
-
20
- A();
21
-
22
-
23
-
24
-
25
- int y;
26
- };
27
-
28
- struct B : A
29
- {
30
- typedef A super;
31
-
32
- B();
33
-
34
-
35
-
36
-
37
- int a;
38
- };
39
-
40
- struct C : B
41
- {
42
- typedef B super;
43
-
44
- C();
45
-
46
-
47
-
48
-
49
- int z;
50
- };
51
-
Binary file
Binary file
@@ -1,105 +0,0 @@
1
- #include "test_mixin.h"
2
-
3
-
4
- static VALUE
5
- A_alloc__(VALUE klass)
6
- {
7
- A *__cobj__;
8
- __cobj__ = new A();
9
- __cobj__->__obj__ = Data_Wrap_Struct(klass, RubyObject::__mark, RubyObject::__free, __cobj__);
10
- return __cobj__->__obj__;
11
- }
12
- static VALUE
13
- A_get__y(VALUE __self__)
14
- {
15
- int __res__;
16
- A *__cobj__;
17
- Check_Type(__self__, T_DATA);
18
- __cobj__ = (A*) DATA_PTR(__self__);
19
- __res__ = __cobj__->y;
20
- return INT2NUM(__res__);
21
- }
22
- static VALUE
23
- A_set__y(VALUE __self__, VALUE __val__)
24
- {
25
- A *__cobj__;
26
- Check_Type(__self__, T_DATA);
27
- __cobj__ = (A*) DATA_PTR(__self__);
28
- ;
29
- __cobj__->y = (int)NUM2INT(__val__);
30
- return Qnil;
31
- }
32
-
33
- static VALUE
34
- B_alloc__(VALUE klass)
35
- {
36
- B *__cobj__;
37
- __cobj__ = new B();
38
- __cobj__->__obj__ = Data_Wrap_Struct(klass, RubyObject::__mark, RubyObject::__free, __cobj__);
39
- return __cobj__->__obj__;
40
- }
41
- static VALUE
42
- B_get__a(VALUE __self__)
43
- {
44
- int __res__;
45
- B *__cobj__;
46
- Check_Type(__self__, T_DATA);
47
- __cobj__ = (B*) DATA_PTR(__self__);
48
- __res__ = __cobj__->a;
49
- return INT2NUM(__res__);
50
- }
51
- static VALUE
52
- B_set__a(VALUE __self__, VALUE __val__)
53
- {
54
- B *__cobj__;
55
- Check_Type(__self__, T_DATA);
56
- __cobj__ = (B*) DATA_PTR(__self__);
57
- ;
58
- __cobj__->a = (int)NUM2INT(__val__);
59
- return Qnil;
60
- }
61
-
62
- static VALUE
63
- C_alloc__(VALUE klass)
64
- {
65
- C *__cobj__;
66
- __cobj__ = new C();
67
- __cobj__->__obj__ = Data_Wrap_Struct(klass, RubyObject::__mark, RubyObject::__free, __cobj__);
68
- return __cobj__->__obj__;
69
- }
70
- static VALUE
71
- C_get__z(VALUE __self__)
72
- {
73
- int __res__;
74
- C *__cobj__;
75
- Check_Type(__self__, T_DATA);
76
- __cobj__ = (C*) DATA_PTR(__self__);
77
- __res__ = __cobj__->z;
78
- return INT2NUM(__res__);
79
- }
80
- static VALUE
81
- C_set__z(VALUE __self__, VALUE __val__)
82
- {
83
- C *__cobj__;
84
- Check_Type(__self__, T_DATA);
85
- __cobj__ = (C*) DATA_PTR(__self__);
86
- ;
87
- __cobj__->z = (int)NUM2INT(__val__);
88
- return Qnil;
89
- }
90
- extern "C" void Init_test_mixin()
91
- {
92
- VALUE klass;
93
- klass = rb_eval_string("A");
94
- rb_define_alloc_func(klass, A_alloc__);
95
- rb_define_method(klass, "y", (VALUE(*)(...))A_get__y, 0);
96
- rb_define_method(klass, "y=", (VALUE(*)(...))A_set__y, 1);
97
- klass = rb_eval_string("B");
98
- rb_define_alloc_func(klass, B_alloc__);
99
- rb_define_method(klass, "a", (VALUE(*)(...))B_get__a, 0);
100
- rb_define_method(klass, "a=", (VALUE(*)(...))B_set__a, 1);
101
- klass = rb_eval_string("C");
102
- rb_define_alloc_func(klass, C_alloc__);
103
- rb_define_method(klass, "z", (VALUE(*)(...))C_get__z, 0);
104
- rb_define_method(klass, "z=", (VALUE(*)(...))C_set__z, 1);
105
- }
Binary file