summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--Rakefile10
-rw-r--r--build_config.rb10
-rw-r--r--doc/compile/README.md294
-rw-r--r--doc/mrbgems/README.md165
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/README.md (renamed from doc/mrbgems/c_and_ruby_extension_example/README.md)0
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake (renamed from doc/mrbgems/c_and_ruby_extension_example/mrbgem.rake)0
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb (renamed from doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb)0
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/src/example.c (renamed from doc/mrbgems/c_and_ruby_extension_example/src/example.c)5
-rw-r--r--examples/mrbgems/c_and_ruby_extension_example/test/example.rb (renamed from doc/mrbgems/c_and_ruby_extension_example/test/example.rb)0
-rw-r--r--examples/mrbgems/c_extension_example/README.md (renamed from doc/mrbgems/c_extension_example/README.md)0
-rw-r--r--examples/mrbgems/c_extension_example/mrbgem.rake (renamed from doc/mrbgems/c_extension_example/mrbgem.rake)0
-rw-r--r--examples/mrbgems/c_extension_example/src/example.c (renamed from doc/mrbgems/c_extension_example/src/example.c)5
-rw-r--r--examples/mrbgems/c_extension_example/test/example.c (renamed from doc/mrbgems/c_extension_example/test/example.c)0
-rw-r--r--examples/mrbgems/c_extension_example/test/example.rb (renamed from doc/mrbgems/c_extension_example/test/example.rb)0
-rw-r--r--examples/mrbgems/ruby_extension_example/README.md (renamed from doc/mrbgems/ruby_extension_example/README.md)0
-rw-r--r--examples/mrbgems/ruby_extension_example/mrbgem.rake (renamed from doc/mrbgems/ruby_extension_example/mrbgem.rake)0
-rw-r--r--examples/mrbgems/ruby_extension_example/mrblib/example.rb (renamed from doc/mrbgems/ruby_extension_example/mrblib/example.rb)0
-rw-r--r--examples/mrbgems/ruby_extension_example/test/example.rb (renamed from doc/mrbgems/ruby_extension_example/test/example.rb)0
-rw-r--r--include/mruby/string.h1
-rw-r--r--mrblib/mrblib.rake2
-rw-r--r--src/array.c2
-rw-r--r--src/class.c7
-rw-r--r--src/codegen.c35
-rw-r--r--src/dump.c8
-rw-r--r--src/init.c9
-rw-r--r--src/init_ext.c16
-rw-r--r--src/load.c2
-rw-r--r--src/object.c2
-rw-r--r--src/parse.y24
-rw-r--r--src/range.c6
-rw-r--r--src/state.c7
-rw-r--r--src/string.c22
-rw-r--r--src/struct.c4
-rw-r--r--src/vm.c2
-rw-r--r--tasks/libmruby.rake9
-rw-r--r--tasks/mrbgem_spec.rake10
-rw-r--r--tasks/mrbgems.rake8
-rw-r--r--tasks/mruby_build.rake25
-rw-r--r--tasks/mruby_build_commands.rake42
-rw-r--r--tasks/mruby_build_gem.rake6
-rw-r--r--tasks/ruby_ext.rake8
-rw-r--r--tasks/toolchains/clang.rake4
-rw-r--r--tasks/toolchains/gcc.rake4
-rw-r--r--tasks/toolchains/vs2012.rake4
-rw-r--r--test/mrbtest.rake8
-rw-r--r--test/t/range.rb15
-rw-r--r--tools/mirb/mirb.rake4
-rw-r--r--tools/mrbc/mrbc.c5
-rw-r--r--tools/mruby/mruby.rake4
50 files changed, 379 insertions, 417 deletions
diff --git a/README.md b/README.md
index 69ca995df..93a9c0f01 100644
--- a/README.md
+++ b/README.md
@@ -67,7 +67,7 @@ Or
mruby contains a package manager called *mrbgems*. To create extensions
in C and/or Ruby you should create a *GEM*. You will find a complete
-documentation with examples under *doc/mrbgems*.
+documentation with examples under *examples/mrbgems*.
## License
diff --git a/Rakefile b/Rakefile
index f0991d323..6a04ef87c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -31,6 +31,7 @@ depfiles = MRuby.targets['host'].bins.map do |bin|
install_path = MRuby.targets['host'].exefile("bin/#{bin}")
file install_path => MRuby.targets['host'].exefile("build/host/bin/#{bin}") do |t|
+ FileUtils.rm t.name, :force => true
FileUtils.cp t.prerequisites.first, t.name
end
@@ -42,7 +43,14 @@ depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
}.flatten
desc "build all targets, install (locally) in-repo"
-task :all => depfiles
+task :all => depfiles do
+ puts
+ puts "Build summary:"
+ puts
+ MRuby.each_target do
+ print_build_summary
+ end
+end
desc "run all mruby tests"
task :test => MRuby.targets.values.map { |t| t.exefile("#{t.build_dir}/test/mrbtest") } do
diff --git a/build_config.rb b/build_config.rb
index 1c177fdac..eeaa255ab 100644
--- a/build_config.rb
+++ b/build_config.rb
@@ -3,11 +3,11 @@ MRuby::Build.new do |conf|
toolchain :gcc
# Use mrbgems
- # conf.gem 'doc/mrbgems/ruby_extension_example'
- # conf.gem 'doc/mrbgems/c_extension_example' do |g|
+ # conf.gem 'examples/mrbgems/ruby_extension_example'
+ # conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
- # conf.gem 'doc/mrbgems/c_and_ruby_extension_example'
+ # conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
# conf.gem :git => '[email protected]:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v'
@@ -29,7 +29,9 @@ MRuby::Build.new do |conf|
# conf.linker do |linker|
# linker.command = ENV['LD'] || 'gcc'
# linker.flags = [ENV['LDFLAGS'] || []]
+ # linker.flags_before_libraries = []
# linker.libraries = %w()
+ # linker.flags_after_libraries = []
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
@@ -72,5 +74,5 @@ end
# conf.cc.flags << "-m32"
# conf.linker.flags << "-m32"
#
-# conf.gem 'doc/mrbgems/c_and_ruby_extension_example'
+# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# end
diff --git a/doc/compile/README.md b/doc/compile/README.md
index a1c915a0e..a86ddbe62 100644
--- a/doc/compile/README.md
+++ b/doc/compile/README.md
@@ -23,11 +23,9 @@ Inside of the root directory of the mruby source exist a file
called *build_config.rb*. This file contains the build configuration
of mruby and looks like this for example:
-```
-MRuby::Build.new do |conf|
- toolchain :gcc
-end
-```
+ MRuby::Build.new do |conf|
+ toolchain :gcc
+ end
All tools necessary to compile mruby can be set or modified here. In case
you want to maintain an additional *build_config.rb* you can define a
@@ -51,26 +49,20 @@ configurates the build environment for specific compiler infrastructures.
Toolchain configuration for the GNU C Compiler.
-```
-toolchain :gcc
-```
+ toolchain :gcc
#### clang
Toolchain configuration for the LLVM C Compiler clang. Mainly equal to the
GCC toolchain.
-```
-toolchain :clang
-```
+ toolchain :clang
#### Visual Studio 2012
Toolchain configuration for Visual Studio 2012 on Windows.
-```
-toolchain :vs2012
-```
+ toolchain :vs2012
### Binaries
@@ -81,106 +73,92 @@ process. The following tools can be selected:
* mirb (mruby interactive shell
To select all define an array in ```conf.bins```:
-```
-conf.bins = %(mrbc mruby mirb)
-```
+
+ conf.bins = %(mrbc mruby mirb)
### File Separator
Some environments require a different file separator character. It is possible to
set the character via ```conf.file_separator```.
-```
-conf.file_separator = '/'
-```
+ conf.file_separator = '/'
### C Compiler
Configuration of the C compiler binary, flags and include paths.
-```
-conf.cc do |cc|
- cc.command = ...
- cc.flags = ...
- cc.include_paths = ...
- cc.defines = ...
- cc.option_include_path = ...
- cc.option_define = ...
- cc.compile_options = ...
-end
-```
+ conf.cc do |cc|
+ cc.command = ...
+ cc.flags = ...
+ cc.include_paths = ...
+ cc.defines = ...
+ cc.option_include_path = ...
+ cc.option_define = ...
+ cc.compile_options = ...
+ end
### Linker
Configuration of the Linker binary, flags and library paths.
-```
-conf.linker do |linker|
- linker.command = ...
- linker.flags = ...
- linker.libraries = ...
- linker.library_paths = ....
- linker.option_library = ...
- linker.option_library_path = ...
- linker.link_options = ...
-end
-```
+ conf.linker do |linker|
+ linker.command = ...
+ linker.flags = ...
+ linker.flags_before_libraries = ...
+ linker.libraries = ...
+ linker.flags_after_libraries = ...
+ linker.library_paths = ....
+ linker.option_library = ...
+ linker.option_library_path = ...
+ linker.link_options = ...
+ end
### Archiver
Configuration of the Archiver binary and flags.
-```
-conf.archiver do |archiver|
- archiver.command = ...
- archiver.archive_options = ...
-end
-```
+ conf.archiver do |archiver|
+ archiver.command = ...
+ archiver.archive_options = ...
+ end
### Parser Generator
Configuration of the Parser Generator binary and flags.
-```
-conf.yacc do |yacc|
- yacc.command = ...
- yacc.compile_options = ...
-end
-```
+ conf.yacc do |yacc|
+ yacc.command = ...
+ yacc.compile_options = ...
+ end
### GPerf
Configuration of the GPerf binary and flags.
-```
-conf.gperf do |gperf|
- gperf.command = ...
- gperf.compile_options = ...
-end
-```
+
+ conf.gperf do |gperf|
+ gperf.command = ...
+ gperf.compile_options = ...
+ end
### File Extensions
-```
-conf.exts do |exts
- exts.object = ...
- exts.executable = ...
- exts.library = ...
-end
-```
+ conf.exts do |exts
+ exts.object = ...
+ exts.executable = ...
+ exts.library = ...
+ end
### Mrbgems
Integrate GEMs in the build process.
-```
-# Integrate GEM with additional configuration
-conf.gem 'path/to/gem' do |g|
- g.cc.flags << ...
-end
+ # Integrate GEM with additional configuration
+ conf.gem 'path/to/gem' do |g|
+ g.cc.flags << ...
+ end
-# Integrate GEM without additional configuration
-conf.gem 'path/to/another/gem'
-```
+ # Integrate GEM without additional configuration
+ conf.gem 'path/to/another/gem'
## Cross-Compilation
@@ -190,14 +168,12 @@ achive this the *build_config.rb* needs to contain an instance of
tools and flags for the target platform. An example could look
like this:
-```
-MRuby::CrossBuild.new('32bit') do |conf|
- toolchain :gcc
+ MRuby::CrossBuild.new('32bit') do |conf|
+ toolchain :gcc
- conf.cc.flags << "-m32"
- conf.linker.flags << "-m32
-end
-```
+ conf.cc.flags << "-m32"
+ conf.linker.flags << "-m32
+ end
All configuration options of ```MRuby::Build``` can also be used
in ```MRuby::CrossBuild```.
@@ -207,29 +183,27 @@ in ```MRuby::CrossBuild```.
During the build process the directory *build* will be created in the
root directory. The structure of this directory will look like this:
-```
-+- build
- |
- +- host
- |
- +- bin <- Binaries (mirb, mrbc and mruby)
- |
- +- lib <- Libraries (libmruby.a and libmruby_core.a)
- |
- +- mrblib
- |
- +- src
- |
- +- test <- mrbtest tool
- |
- +- tools
- |
- +- mirb
- |
- +- mrbc
- |
- +- mruby
-```
+ +- build
+ |
+ +- host
+ |
+ +- bin <- Binaries (mirb, mrbc and mruby)
+ |
+ +- lib <- Libraries (libmruby.a and libmruby_core.a)
+ |
+ +- mrblib
+ |
+ +- src
+ |
+ +- test <- mrbtest tool
+ |
+ +- tools
+ |
+ +- mirb
+ |
+ +- mrbc
+ |
+ +- mruby
The compilation workflow will look like this:
* compile all files under *src* (object files will be stored
@@ -261,48 +235,46 @@ link with *build/host/lib/libmruby.a*
In case of a cross-compilation to *i386* the *build* directory structure looks
like this:
-```
-+- build
- |
- +- host
- | |
- | +- bin <- Native Binaries
- | |
- | +- lib <- Native Libraries
- | |
- | +- mrblib
- | |
- | +- src
- | |
- | +- test <- Native mrbtest tool
- | |
- | +- tools
- | |
- | +- mirb
- | |
- | +- mrbc
- | |
- | +- mruby
- +- i386
- |
- +- bin <- Cross-compiled Binaries
- |
- +- lib <- Cross-compiled Libraries
- |
- +- mrblib
- |
- +- src
- |
- +- test <- Cross-compiled mrbtest tool
- |
- +- tools
- |
- +- mirb
- |
- +- mrbc
- |
- +- mruby
-```
+ +- build
+ |
+ +- host
+ | |
+ | +- bin <- Native Binaries
+ | |
+ | +- lib <- Native Libraries
+ | |
+ | +- mrblib
+ | |
+ | +- src
+ | |
+ | +- test <- Native mrbtest tool
+ | |
+ | +- tools
+ | |
+ | +- mirb
+ | |
+ | +- mrbc
+ | |
+ | +- mruby
+ +- i386
+ |
+ +- bin <- Cross-compiled Binaries
+ |
+ +- lib <- Cross-compiled Libraries
+ |
+ +- mrblib
+ |
+ +- src
+ |
+ +- test <- Cross-compiled mrbtest tool
+ |
+ +- tools
+ |
+ +- mirb
+ |
+ +- mrbc
+ |
+ +- mruby
An extra directory is created for the target platform. In case you
compile for *i386* a directory called *i386* is created under the
@@ -329,23 +301,23 @@ link with *build/i386/lib/libmruby.a*
link with *build/i386/lib/libmruby_core.a*
```
- _____________________________________________________________
-| Native Compilation for Host System |
-| _____ ______ _____ ____ ____ _____ |
-|| CC | -> |AR | -> |GEN | -> |CC | -> |CC | -> |AR ||
-|| *.c | |core.a| |y.tab| |mrbc| |*.rb| |lib.a||
-| ----- ------ ----- ---- ---- ----- |
- -------------------------------------------------------------
+ _______________________________________________________________
+| Native Compilation for Host System |
+| _____ ______ _____ ____ ____ _____ |
+| | CC | -> |AR | -> |GEN | -> |CC | -> |CC | -> |AR | |
+| | *.c | |core.a| |y.tab| |mrbc| |*.rb| |lib.a| |
+| ----- ------ ----- ---- ---- ----- |
+ ---------------------------------------------------------------
||
\||/
\/
- ______________________________________________________________
-| Cross Compilation for Target System |
-| _____ _____ _____ ____ ______ _____ |
-|| CC | -> |AR | -> |CC | -> |CC | -> |AR | -> |CC ||
-|| *.c | |lib.a| |mruby| |mirb| |core.a| |mrbc ||
-| ----- ----- ----- ---- ------ ----- |
- --------------------------------------------------------------
+ ________________________________________________________________
+| Cross Compilation for Target System |
+| _____ _____ _____ ____ ______ _____ |
+| | CC | -> |AR | -> |CC | -> |CC | -> |AR | -> |CC | |
+| | *.c | |lib.a| |mruby| |mirb| |core.a| |mrbc | |
+| ----- ----- ----- ---- ------ ----- |
+ ----------------------------------------------------------------
```
## Test Environment
diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md
index 9e930d8b2..6c473b57d 100644
--- a/doc/mrbgems/README.md
+++ b/doc/mrbgems/README.md
@@ -11,44 +11,34 @@ extension integrated.
To add a GEM into the build_config.rb add the following line for example:
-```
-conf.gem '/path/to/your/gem/dir'
-```
+ conf.gem '/path/to/your/gem/dir'
You can also use a relative path which would be relative from the mruby root:
-```
-conf.gem 'doc/mrbgems/ruby_extension_example'
-```
+ conf.gem 'examples/mrbgems/ruby_extension_example'
A remote GIT repository location for a GEM is also supported:
-```
-conf.gem :git => 'https://github.com/masuidrive/mrbgems-example.git', :branch => 'master'
-```
+ conf.gem :git => 'https://github.com/masuidrive/mrbgems-example.git', :branch => 'master'
-```
-conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
-```
+ conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
## GEM Structure
The maximal GEM structure looks like this:
-```
-+- GEM_NAME <- Name of GEM
- |
- +- mrblib/ <- Source for Ruby extension
- |
- +- src/ <- Source for C extension
- |
- +- test/ <- Test code (Ruby)
- |
- +- mrbgem.rake <- GEM Specification
- |
- +- README.md <- Readme for GEM
-```
+ +- GEM_NAME <- Name of GEM
+ |
+ +- mrblib/ <- Source for Ruby extension
+ |
+ +- src/ <- Source for C extension
+ |
+ +- test/ <- Test code (Ruby)
+ |
+ +- mrbgem.rake <- GEM Specification
+ |
+ +- README.md <- Readme for GEM
The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src*
contains C files to extend mruby. The folder *test* contains C and pure Ruby files
@@ -61,12 +51,10 @@ of your GEM.
mrbgems expects a specifcation file called *mrbgem.rake* inside of your
GEM direcotry. A typical GEM specification could look like this for example:
-```
-MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
- spec.license = 'MIT'
- spec.authors = 'mruby developers'
-end
-```
+ MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
+ spec.license = 'MIT'
+ spec.authors = 'mruby developers'
+ end
The mrbgems build process will use this specification to compile Object and Ruby
files. The compilation results will be add to *lib/libmruby.a*. This file is used
@@ -98,31 +86,39 @@ mrbgems expects that you have implemented a C method called
by the name of your GEM. If you call your GEM *c_extension_example*, your
initialisation method could look like this:
-```
-void
-mrb_c_extension_example_gem_init(mrb_state* mrb) {
- struct RClass *class_cextension = mrb_define_module(mrb, "CExtension");
- mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, ARGS_NONE());
-}
-```
+ void
+ mrb_c_extension_example_gem_init(mrb_state* mrb) {
+ struct RClass *class_cextension = mrb_define_module(mrb, "CExtension");
+ mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, ARGS_NONE());
+ }
+
+### Finalize
+
+mrbgems expects that you have implemented a C method called
+```mrb_YOURGEMNAME_gem_final(mrb_state)```. ```YOURGEMNAME``` will be replaced
+by the name of your GEM. If you call your GEM *c_extension_example*, your
+finalizer method could look like this:
+
+ void
+ mrb_c_extension_example_gem_final(mrb_state* mrb) {
+ free(someone);
+ }
### Example
-```
-+- c_extension_example/
- |
- +- src/
- | |
- | +- example.c <- C extension source
- |
- +- test/
- | |
- | +- example.rb <- Test code for C extension
- |
- +- mrbgem.rake <- GEM specification
- |
- +- README.md
-```
+ +- c_extension_example/
+ |
+ +- src/
+ | |
+ | +- example.c <- C extension source
+ |
+ +- test/
+ | |
+ | +- example.rb <- Test code for C extension
+ |
+ +- mrbgem.rake <- GEM specification
+ |
+ +- README.md
## Ruby Extension
@@ -136,21 +132,19 @@ none
### Example
-```
-+- ruby_extension_example/
- |
- +- mrblib/
- | |
- | +- example.rb <- Ruby extension source
- |
- +- test/
- | |
- | +- example.rb <- Test code for Ruby extension
- |
- +- mrbgem.rake <- GEM specification
- |
- +- README.md
-```
+ +- ruby_extension_example/
+ |
+ +- mrblib/
+ | |
+ | +- example.rb <- Ruby extension source
+ |
+ +- test/
+ | |
+ | +- example.rb <- Test code for Ruby extension
+ |
+ +- mrbgem.rake <- GEM specification
+ |
+ +- README.md
## C and Ruby Extension
@@ -164,21 +158,20 @@ See C and Ruby example.
### Example
-```
-+- c_and_ruby_extension_example/
- |
- +- mrblib/
- | |
- | +- example.rb <- Ruby extension source
- |
- +- src/
- | |
- | +- example.c <- C extension source
- |
- +- test/
- | |
- | +- example.rb <- Test code for C and Ruby extension
- |
- +- mrbgem.rake <- GEM specification
- |
- +- README.md
+ +- c_and_ruby_extension_example/
+ |
+ +- mrblib/
+ | |
+ | +- example.rb <- Ruby extension source
+ |
+ +- src/
+ | |
+ | +- example.c <- C extension source
+ |
+ +- test/
+ | |
+ | +- example.rb <- Test code for C and Ruby extension
+ |
+ +- mrbgem.rake <- GEM specification
+ |
+ +- README.md
diff --git a/doc/mrbgems/c_and_ruby_extension_example/README.md b/examples/mrbgems/c_and_ruby_extension_example/README.md
index 0b428b0b6..0b428b0b6 100644
--- a/doc/mrbgems/c_and_ruby_extension_example/README.md
+++ b/examples/mrbgems/c_and_ruby_extension_example/README.md
diff --git a/doc/mrbgems/c_and_ruby_extension_example/mrbgem.rake b/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
index 64fa1972f..64fa1972f 100644
--- a/doc/mrbgems/c_and_ruby_extension_example/mrbgem.rake
+++ b/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake
diff --git a/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb b/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb
index d3899c301..d3899c301 100644
--- a/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb
+++ b/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb
diff --git a/doc/mrbgems/c_and_ruby_extension_example/src/example.c b/examples/mrbgems/c_and_ruby_extension_example/src/example.c
index 3d3cb20c9..7651ae5c0 100644
--- a/doc/mrbgems/c_and_ruby_extension_example/src/example.c
+++ b/examples/mrbgems/c_and_ruby_extension_example/src/example.c
@@ -13,3 +13,8 @@ mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) {
struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension");
mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, ARGS_NONE());
}
+
+void
+mrb_c_and_ruby_extension_example_gem_final(mrb_state* mrb) {
+ // finalizer
+}
diff --git a/doc/mrbgems/c_and_ruby_extension_example/test/example.rb b/examples/mrbgems/c_and_ruby_extension_example/test/example.rb
index fffad710f..fffad710f 100644
--- a/doc/mrbgems/c_and_ruby_extension_example/test/example.rb
+++ b/examples/mrbgems/c_and_ruby_extension_example/test/example.rb
diff --git a/doc/mrbgems/c_extension_example/README.md b/examples/mrbgems/c_extension_example/README.md
index 3803c2065..3803c2065 100644
--- a/doc/mrbgems/c_extension_example/README.md
+++ b/examples/mrbgems/c_extension_example/README.md
diff --git a/doc/mrbgems/c_extension_example/mrbgem.rake b/examples/mrbgems/c_extension_example/mrbgem.rake
index 6bcb6e105..6bcb6e105 100644
--- a/doc/mrbgems/c_extension_example/mrbgem.rake
+++ b/examples/mrbgems/c_extension_example/mrbgem.rake
diff --git a/doc/mrbgems/c_extension_example/src/example.c b/examples/mrbgems/c_extension_example/src/example.c
index 11f54e6d2..fa166186d 100644
--- a/doc/mrbgems/c_extension_example/src/example.c
+++ b/examples/mrbgems/c_extension_example/src/example.c
@@ -13,3 +13,8 @@ mrb_c_extension_example_gem_init(mrb_state* mrb) {
struct RClass *class_cextension = mrb_define_module(mrb, "CExtension");
mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, ARGS_NONE());
}
+
+void
+mrb_c_extension_example_gem_final(mrb_state* mrb) {
+ // finalizer
+}
diff --git a/doc/mrbgems/c_extension_example/test/example.c b/examples/mrbgems/c_extension_example/test/example.c
index ab410333d..ab410333d 100644
--- a/doc/mrbgems/c_extension_example/test/example.c
+++ b/examples/mrbgems/c_extension_example/test/example.c
diff --git a/doc/mrbgems/c_extension_example/test/example.rb b/examples/mrbgems/c_extension_example/test/example.rb
index 367d18029..367d18029 100644
--- a/doc/mrbgems/c_extension_example/test/example.rb
+++ b/examples/mrbgems/c_extension_example/test/example.rb
diff --git a/doc/mrbgems/ruby_extension_example/README.md b/examples/mrbgems/ruby_extension_example/README.md
index 906a0d8f2..906a0d8f2 100644
--- a/doc/mrbgems/ruby_extension_example/README.md
+++ b/examples/mrbgems/ruby_extension_example/README.md
diff --git a/doc/mrbgems/ruby_extension_example/mrbgem.rake b/examples/mrbgems/ruby_extension_example/mrbgem.rake
index 0a1e62b1c..0a1e62b1c 100644
--- a/doc/mrbgems/ruby_extension_example/mrbgem.rake
+++ b/examples/mrbgems/ruby_extension_example/mrbgem.rake
diff --git a/doc/mrbgems/ruby_extension_example/mrblib/example.rb b/examples/mrbgems/ruby_extension_example/mrblib/example.rb
index b07a2b580..b07a2b580 100644
--- a/doc/mrbgems/ruby_extension_example/mrblib/example.rb
+++ b/examples/mrbgems/ruby_extension_example/mrblib/example.rb
diff --git a/doc/mrbgems/ruby_extension_example/test/example.rb b/examples/mrbgems/ruby_extension_example/test/example.rb
index 0c1b63469..0c1b63469 100644
--- a/doc/mrbgems/ruby_extension_example/test/example.rb
+++ b/examples/mrbgems/ruby_extension_example/test/example.rb
diff --git a/include/mruby/string.h b/include/mruby/string.h
index cd2c83dcd..4ff0f1ee1 100644
--- a/include/mruby/string.h
+++ b/include/mruby/string.h
@@ -68,7 +68,6 @@ int mrb_str_offset(mrb_state *mrb, mrb_value str, int pos);
mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); /* mrb_str_dup */
mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
mrb_value mrb_str_cat2(mrb_state *mrb, mrb_value str, const char *ptr);
-mrb_value mrb_str_catf(mrb_state *mrb, mrb_value str, const char *format, ...);
mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck);
double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, int badcheck);
mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
diff --git a/mrblib/mrblib.rake b/mrblib/mrblib.rake
index 46d8c5a79..5b4070745 100644
--- a/mrblib/mrblib.rake
+++ b/mrblib/mrblib.rake
@@ -7,7 +7,7 @@ MRuby.each_target do
mrbc_, *rbfiles = t.prerequisites
FileUtils.mkdir_p File.dirname(t.name)
open(t.name, 'w') do |f|
- _pp "GEN *.rb > #{t.name}"
+ _pp "GEN", "*.rb", "#{t.name}"
f.puts File.read("#{dir}/init_mrblib.c")
mrbc.run f, rbfiles, 'mrblib_irep'
end
diff --git a/src/array.c b/src/array.c
index d4f5d1c5e..a358e1207 100644
--- a/src/array.c
+++ b/src/array.c
@@ -66,7 +66,7 @@ mrb_ary_new(mrb_state *mrb)
static inline void
array_copy(mrb_value *dst, const mrb_value *src, size_t size)
{
- int i;
+ size_t i;
for (i = 0; i < size; i++) {
dst[i] = src[i];
diff --git a/src/class.c b/src/class.c
index b24dd8a08..530fc5ce4 100644
--- a/src/class.c
+++ b/src/class.c
@@ -1211,7 +1211,12 @@ const char*
mrb_class_name(mrb_state *mrb, struct RClass* c)
{
mrb_value path = mrb_class_path(mrb, c);
- if (mrb_nil_p(path)) return 0;
+ if (mrb_nil_p(path)) {
+ char buf[32];
+
+ snprintf(buf, 32, "#<Class:%p>", c);
+ path = mrb_str_new_cstr(mrb, buf);
+ }
return mrb_str_ptr(path)->ptr;
}
diff --git a/src/codegen.c b/src/codegen.c
index 5c3614814..5803a9c25 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -4,7 +4,6 @@
** See Copyright Notice in mruby.h
*/
-#undef CODEGEN_TEST
#define CODEGEN_DUMP
#include "mruby.h"
@@ -2538,7 +2537,7 @@ codedump(mrb_state *mrb, int n)
void
codedump_all(mrb_state *mrb, int start)
{
- int i;
+ size_t i;
for (i=start; i<mrb->irep_len; i++) {
codedump(mrb, i);
@@ -2577,35 +2576,3 @@ mrb_generate_code(mrb_state *mrb, parser_state *p)
return start;
}
-
-#ifdef CODEGEN_TEST
-int
-main()
-{
- mrb_state *mrb = mrb_open();
- int n;
-
-#if 1
- n = mrb_compile_string(mrb, "p(__FILE__)\np(__LINE__)");
-#else
- n = mrb_compile_string(mrb, "\
-def fib(n)\n\
- if n<2\n\
- n\n\
- else\n\
- fib(n-2)+fib(n-1)\n\
- end\n\
-end\n\
-p(fib(30), \"\\n\")\n\
-");
-#endif
- printf("ret: %d\n", n);
-#ifdef CODEGEN_DUMP
- codedump_all(mrb, n);
-#endif
- mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[0]), mrb_nil_value());
- mrb_close(mrb);
-
- return 0;
-}
-#endif
diff --git a/src/dump.c b/src/dump.c
index 884a9141f..e0d755c8c 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -59,7 +59,7 @@ static inline int uint16_dump(uint16_t,char*,int);
static inline int uint32_dump(uint32_t,char*,int);
static char* str_dump(char*,char*,uint16_t,int);
static uint16_t str_dump_len(char*,uint16_t, int);
-static uint32_t get_irep_header_size(mrb_state*,mrb_irep*,int);
+static uint32_t get_irep_header_size(mrb_state*,int);
static uint32_t get_iseq_block_size(mrb_state*,mrb_irep*,int);
static uint32_t get_pool_block_size(mrb_state*,mrb_irep*,int);
static uint32_t get_syms_block_size(mrb_state*,mrb_irep*,int);
@@ -202,7 +202,7 @@ str_dump_len(char *str, uint16_t len, int type)
}
static uint32_t
-get_irep_header_size(mrb_state *mrb, mrb_irep *irep, int type)
+get_irep_header_size(mrb_state *mrb, int type)
{
uint32_t size = 0;
@@ -305,7 +305,7 @@ get_irep_record_size(mrb_state *mrb, int irep_no, int type)
mrb_irep *irep = mrb->irep[irep_no];
size += DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, type); /* rlen */
- size += get_irep_header_size(mrb, irep, type);
+ size += get_irep_header_size(mrb, type);
size += get_iseq_block_size(mrb, irep, type);
size += get_pool_block_size(mrb, irep, type);
size += get_syms_block_size(mrb, irep, type);
@@ -480,7 +480,7 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
int result;
switch (section) {
- case DUMP_IREP_HEADER: buf_size = get_irep_header_size(mrb, irep, type); break;
+ case DUMP_IREP_HEADER: buf_size = get_irep_header_size(mrb, type); break;
case DUMP_ISEQ_BLOCK: buf_size = get_iseq_block_size(mrb, irep, type); break;
case DUMP_POOL_BLOCK: buf_size = get_pool_block_size(mrb, irep, type); break;
case DUMP_SYMS_BLOCK: buf_size = get_syms_block_size(mrb, irep, type); break;
diff --git a/src/init.c b/src/init.c
index 48008b150..73ff8fce2 100644
--- a/src/init.c
+++ b/src/init.c
@@ -28,6 +28,7 @@ void mrb_init_time(mrb_state*);
void mrb_init_math(mrb_state*);
void mrb_init_mrblib(mrb_state*);
void mrb_init_mrbgems(mrb_state*);
+void mrb_final_mrbgems(mrb_state*);
#define DONE mrb_gc_arena_restore(mrb, 0);
void
@@ -70,3 +71,11 @@ mrb_init_core(mrb_state *mrb)
mrb_init_mrbgems(mrb); DONE;
#endif
}
+
+void
+mrb_final_core(mrb_state *mrb)
+{
+#ifndef DISABLE_GEMS
+ mrb_final_mrbgems(mrb); DONE;
+#endif
+} \ No newline at end of file
diff --git a/src/init_ext.c b/src/init_ext.c
deleted file mode 100644
index 96ee34da1..000000000
--- a/src/init_ext.c
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
-** init_ext.c - initialize extend libraries
-**
-** See Copyright Notice in mruby.h
-*/
-
-#include "mruby.h"
-
-void
-mrb_init_ext(mrb_state *mrb)
-{
-#ifdef INCLUDE_SOCKET
- extern void mrb_init_socket(mrb_state *mrb);
- mrb_init_socket(mrb);
-#endif
-}
diff --git a/src/load.c b/src/load.c
index 504246799..78ece114f 100644
--- a/src/load.c
+++ b/src/load.c
@@ -138,7 +138,7 @@ load_rite_irep_record(mrb_state *mrb, RiteFILE* rfp, unsigned char* dst, uint32_
int i;
uint32_t blocklen;
uint16_t offset, pdl, snl, clen;
- unsigned char hex2[2], hex4[4], hex8[8], hcrc[4];
+ unsigned char hex2[2] = {0}, hex4[4] = {0}, hex8[8] = {0}, hcrc[4] = {0};
unsigned char *pStart;
char *char_buf;
uint16_t buf_size =0;
diff --git a/src/object.c b/src/object.c
index 99034e3be..f8ebd44bc 100644
--- a/src/object.c
+++ b/src/object.c
@@ -395,7 +395,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
{
const struct types *type = builtin_types;
struct RString *s;
- int xt;
+ enum mrb_vtype xt;
xt = mrb_type(x);
if ((xt != t) || (xt == MRB_TT_DATA)) {
diff --git a/src/parse.y b/src/parse.y
index 1ca3385f5..9ee9c9bec 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -5,7 +5,6 @@
*/
%{
-#undef PARSER_TEST
#undef PARSER_DEBUG
#define YYDEBUG 1
@@ -5648,26 +5647,3 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
}
#endif
}
-
-#ifdef PARSER_TEST
-int
-main()
-{
- mrb_state *mrb = mrb_open();
- int n;
-
- n = mrb_compile_string(mrb, "\
-def fib(n)\n\
- if n<2\n\
- n\n\
- else\n\
- fib(n-2)+fib(n-1)\n\
- end\n\
-end\n\
-print(fib(20), \"\\n\")\n\
-");
- printf("ret: %d\n", n);
-
- return 0;
-}
-#endif
diff --git a/src/range.c b/src/range.c
index ef92ed822..2cdc34f5c 100644
--- a/src/range.c
+++ b/src/range.c
@@ -43,8 +43,8 @@ mrb_range_new(mrb_state *mrb, mrb_value beg, mrb_value end, int excl)
struct RRange *r;
r = (struct RRange*)mrb_obj_alloc(mrb, MRB_TT_RANGE, RANGE_CLASS);
- r->edges = (struct mrb_range_edges *)mrb_malloc(mrb, sizeof(struct mrb_range_edges));
range_check(mrb, beg, end);
+ r->edges = (struct mrb_range_edges *)mrb_malloc(mrb, sizeof(struct mrb_range_edges));
r->edges->beg = beg;
r->edges->end = end;
r->excl = excl;
@@ -333,7 +333,7 @@ range_to_s(mrb_state *mrb, mrb_value range)
}
static mrb_value
-inspect_range(mrb_state *mrb, mrb_value range, mrb_value dummy, int recur)
+inspect_range(mrb_state *mrb, mrb_value range, int recur)
{
mrb_value str, str2;
struct RRange *r = mrb_range_ptr(range);
@@ -368,7 +368,7 @@ inspect_range(mrb_state *mrb, mrb_value range, mrb_value dummy, int recur)
static mrb_value
range_inspect(mrb_state *mrb, mrb_value range)
{
- return inspect_range(mrb, range, range, 0);
+ return inspect_range(mrb, range, 0);
}
/* 15.2.14.4.14(x) */
diff --git a/src/state.c b/src/state.c
index c1ad4c6ad..53773ac89 100644
--- a/src/state.c
+++ b/src/state.c
@@ -11,7 +11,7 @@
void mrb_init_heap(mrb_state*);
void mrb_init_core(mrb_state*);
-void mrb_init_ext(mrb_state*);
+void mrb_final_core(mrb_state*);
mrb_state*
mrb_open_allocf(mrb_allocf f, void *ud)
@@ -27,7 +27,6 @@ mrb_open_allocf(mrb_allocf f, void *ud)
mrb_init_heap(mrb);
mrb_init_core(mrb);
- mrb_init_ext(mrb);
return mrb;
}
@@ -86,7 +85,9 @@ void mrb_free_heap(mrb_state *mrb);
void
mrb_close(mrb_state *mrb)
{
- int i;
+ size_t i;
+
+ mrb_final_core(mrb);
/* free */
mrb_gc_free_gv(mrb);
diff --git a/src/string.c b/src/string.c
index 144c4bd2a..df74bb3c8 100644
--- a/src/string.c
+++ b/src/string.c
@@ -6,7 +6,6 @@
#include "mruby.h"
-#include <stdarg.h>
#include <string.h>
#include "mruby/string.h"
#include <ctype.h>
@@ -2854,27 +2853,6 @@ mrb_str_cat2(mrb_state *mrb, mrb_value str, const char *ptr)
return mrb_str_cat(mrb, str, ptr, strlen(ptr));
}
-static mrb_value
-mrb_str_vcatf(mrb_state *mrb, mrb_value str, const char *fmt, va_list ap)
-{
- mrb_string_value(mrb, &str);
- mrb_str_resize(mrb, str, (char*)RSTRING_END(str) - RSTRING_PTR(str));
-
- return str;
-}
-
-mrb_value
-mrb_str_catf(mrb_state *mrb, mrb_value str, const char *format, ...)
-{
- va_list ap;
-
- va_start(ap, format);
- str = mrb_str_vcatf(mrb, str, format, ap);
- va_end(ap);
-
- return str;
-}
-
mrb_value
mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2)
{
diff --git a/src/struct.c b/src/struct.c
index 85d0fa094..1396cd728 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -463,7 +463,7 @@ mrb_struct_initialize(mrb_state *mrb, mrb_value self, mrb_value values)
}
static mrb_value
-inspect_struct(mrb_state *mrb, mrb_value s, mrb_value dummy, int recur)
+inspect_struct(mrb_state *mrb, mrb_value s, int recur)
{
const char *cn = mrb_class_name(mrb, mrb_obj_class(mrb, s));
mrb_value members, str = mrb_str_new(mrb, "#<struct ", 9);
@@ -521,7 +521,7 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_value dummy, int recur)
static mrb_value
mrb_struct_inspect(mrb_state *mrb, mrb_value s)
{
- return inspect_struct(mrb, s, s, 0);
+ return inspect_struct(mrb, s, 0);
}
/* 15.2.18.4.9 */
diff --git a/src/vm.c b/src/vm.c
index 696b566c8..ca31f6675 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -58,7 +58,7 @@ The value below allows about 60000 recursive calls in the simplest case. */
static inline void
stack_copy(mrb_value *dst, const mrb_value *src, size_t size)
{
- int i;
+ size_t i;
for (i = 0; i < size; i++) {
dst[i] = src[i];
diff --git a/tasks/libmruby.rake b/tasks/libmruby.rake
index 108f42f59..4cfebacaf 100644
--- a/tasks/libmruby.rake
+++ b/tasks/libmruby.rake
@@ -2,14 +2,17 @@ MRuby.each_target do
file libfile("#{build_dir}/lib/libmruby") => libmruby.flatten do |t|
archiver.run t.name, t.prerequisites
open("#{build_dir}/lib/libmruby.flags.mak", 'w') do |f|
- f.puts 'CFLAGS = "%s"' % cc.all_flags.gsub('"', '\\"')
+ f.puts 'MRUBY_CFLAGS = "%s"' % cc.all_flags.gsub('"', '\\"')
gem_flags = gems.map { |g| g.linker.flags }
gem_library_paths = gems.map { |g| g.linker.library_paths }
- f.puts 'LDFLAGS = "%s"' % linker.all_flags(gem_library_paths, gem_flags).gsub('"', '\\"')
+ f.puts 'MRUBY_LDFLAGS = "%s"' % linker.all_flags(gem_library_paths, gem_flags).gsub('"', '\\"')
+
+ gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
+ f.puts 'MRUBY_LDFLAGS_BEFORE_LIBS = "%s"' % [linker.flags_before_libraries, gem_flags_before_libraries].flatten.join(' ').gsub('"', '\\"')
gem_libraries = gems.map { |g| g.linker.libraries }
- f.puts 'LIBS = "%s"' % linker.library_flags(gem_libraries).gsub('"', '\\"')
+ f.puts 'MRUBY_LIBS = "%s"' % linker.library_flags(gem_libraries).gsub('"', '\\"')
end
end
end
diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake
index 906f47ad0..0e228629b 100644
--- a/tasks/mrbgem_spec.rake
+++ b/tasks/mrbgem_spec.rake
@@ -6,7 +6,7 @@ module MRuby
class << self
attr_accessor :current
end
- LinkerConfig = Struct.new(:libraries, :library_paths, :flags)
+ LinkerConfig = Struct.new(:libraries, :library_paths, :flags, :flags_before_libraries, :flags_after_libraries)
class Specification
include Rake::DSL
@@ -43,7 +43,7 @@ module MRuby
MRuby::Build::COMMANDS.each do |command|
instance_variable_set("@#{command}", @build.send(command).clone)
end
- @linker = LinkerConfig.new([], [], [])
+ @linker = LinkerConfig.new([], [], [], [])
@rbfiles = Dir.glob("#{dir}/mrblib/*.rb")
@objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map do |f|
@@ -105,6 +105,8 @@ module MRuby
print_gem_init_header f
build.mrbc.run f, rbfiles, "gem_mrblib_irep_#{funcname}" unless rbfiles.empty?
f.puts %Q[void mrb_#{funcname}_gem_init(mrb_state *mrb);]
+ f.puts %Q[void mrb_#{funcname}_gem_final(mrb_state *mrb);]
+ f.puts %Q[]
f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_init(mrb_state *mrb) {]
f.puts %Q[ int ai = mrb_gc_arena_save(mrb);]
f.puts %Q[ mrb_#{funcname}_gem_init(mrb);] if objs != [objfile("#{build_dir}/gem_init")]
@@ -117,6 +119,10 @@ module MRuby
end
f.puts %Q[ mrb_gc_arena_restore(mrb, ai);]
f.puts %Q[}]
+ f.puts %Q[]
+ f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_final(mrb_state *mrb) {]
+ f.puts %Q[ mrb_#{funcname}_gem_final(mrb);] if objs != [objfile("#{build_dir}/gem_init")]
+ f.puts %Q[}]
end
end # generate_gem_init
diff --git a/tasks/mrbgems.rake b/tasks/mrbgems.rake
index dc5e67eef..9d8798ef3 100644
--- a/tasks/mrbgems.rake
+++ b/tasks/mrbgems.rake
@@ -24,10 +24,18 @@ MRuby.each_target do
f.puts %Q[#include "mruby.h"]
f.puts %Q[]
f.puts %Q[#{gems.map{|g| "void GENERATED_TMP_mrb_%s_gem_init(mrb_state* mrb);" % g.funcname}.join("\n")}]
+ f.puts %Q[]
+ f.puts %Q[#{gems.map{|g| "void GENERATED_TMP_mrb_%s_gem_final(mrb_state* mrb);" % g.funcname}.join("\n")}]
+ f.puts %Q[]
f.puts %Q[void]
f.puts %Q[mrb_init_mrbgems(mrb_state *mrb) {]
f.puts %Q[#{gems.map{|g| "GENERATED_TMP_mrb_%s_gem_init(mrb);" % g.funcname}.join("\n")}]
f.puts %Q[}]
+ f.puts %Q[]
+ f.puts %Q[void]
+ f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {]
+ f.puts %Q[#{gems.map{|g| "GENERATED_TMP_mrb_%s_gem_final(mrb);" % g.funcname}.join("\n")}]
+ f.puts %Q[}]
end
end
end
diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake
index b9e0d2749..cd9f77fc4 100644
--- a/tasks/mruby_build.rake
+++ b/tasks/mruby_build.rake
@@ -29,10 +29,6 @@ module MRuby
conf.instance_eval(&@initializer)
end
- def toolchain(name)
- @@toolchains[name.to_s].setup(self)
- end
-
def self.load
Dir.glob("#{File.dirname(__FILE__)}/toolchains/*.rake").each do |file|
Kernel.load file
@@ -93,7 +89,9 @@ module MRuby
end
def toolchain(name)
- Toolchain.toolchains[name.to_s].setup(self)
+ tc = Toolchain.toolchains[name.to_s]
+ fail "Unknown #{name} toolchain" unless tc
+ tc.setup(self)
end
def build_dir
@@ -101,7 +99,7 @@ module MRuby
end
def mrbcfile
- exefile("build/host/bin/mrbc")
+ MRuby.targets['host'].exefile("build/host/bin/mrbc")
end
def compilers
@@ -148,6 +146,21 @@ module MRuby
sh "#{filename mrbtest}"
puts
end
+
+ def print_build_summary
+ puts "================================================"
+ puts " Config Name: #{@name}"
+ puts " Output Directory: #{self.build_dir}"
+ puts " Binaries: #{@bins.join(', ')}" unless @bins.empty?
+ unless @gems.empty?
+ puts " Included Gems:"
+ @gems.map(&:name).each do |name|
+ puts " #{name}"
+ end
+ end
+ puts "================================================"
+ puts
+ end
end # Build
class CrossBuild < Build
diff --git a/tasks/mruby_build_commands.rake b/tasks/mruby_build_commands.rake
index 8ffafe9b0..20203ad7e 100644
--- a/tasks/mruby_build_commands.rake
+++ b/tasks/mruby_build_commands.rake
@@ -48,7 +48,9 @@ module MRuby
def all_flags(_defineds=[], _include_paths=[], _flags=[])
define_flags = [defines, _defineds].flatten.map{ |d| option_define % d }
- include_path_flags = [include_paths, _include_paths].flatten.map{ |f| option_include_path % filename(f) }
+ include_path_flags = [include_paths, _include_paths].flatten.map do |f|
+ option_include_path % filename(f)
+ end
[flags, define_flags, include_path_flags, _flags].flatten.join(' ')
end
@@ -58,8 +60,8 @@ module MRuby
include_path_flags = [include_paths, _include_paths, File.dirname(infile)].flatten.map do |f|
option_include_path % filename(f)
end
- _pp "CC #{filename(infile)} > #{filename(outfile)}"
- _run compile_options, { :flags => (flags + define_flags + include_path_flags + _flags).join(' '),
+ _pp "CC", infile, outfile
+ _run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) }
end
@@ -104,36 +106,42 @@ module MRuby
end
class Command::Linker < Command
- attr_accessor :flags, :libraries, :library_paths
+ attr_accessor :flags, :library_paths, :flags_before_libraries, :libraries, :flags_after_libraries
attr_accessor :link_options, :option_library, :option_library_path
def initialize(build)
super
@command = ENV['LD'] || 'gcc'
@flags = (ENV['LDFLAGS'] || [])
+ @flags_before_libraries, @flags_after_libraries = [], []
@libraries = []
@library_paths = []
@option_library = '-l%s'
@option_library_path = '-L%s'
- @link_options = "%{flags} -o %{outfile} %{objs} %{libs}"
+ @link_options = "%{flags} -o %{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}"
end
def all_flags(_library_paths=[], _flags=[])
- library_path_flags = [library_paths, _library_paths].flatten.map{ |f| option_library_path % filename(f) }
+ library_path_flags = [library_paths, _library_paths].flatten.map do |f|
+ option_library_path % filename(f)
+ end
[flags, library_path_flags, _flags].flatten.join(' ')
end
def library_flags(_libraries)
- [libraries, _libraries].flatten.reverse.map{ |d| option_library % d }.join(' ')
+ [libraries, _libraries].flatten.map{ |d| option_library % d }.join(' ')
end
- def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[])
+ def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[], _flags_before_libraries=[], _flags_after_libraries=[])
FileUtils.mkdir_p File.dirname(outfile)
- library_flags = [libraries, _libraries].flatten.reverse.map{ |d| option_library % d }
- library_path_flags = [library_paths, _library_paths].flatten.map{ |f| option_library_path % filename(f) }
- _pp "LD #{filename(outfile)}"
- _run link_options, { :flags => (flags + library_path_flags + _flags).join(' '),
+ library_flags = [libraries, _libraries].flatten.map { |d| option_library % d }
+ library_path_flags = [library_paths, _library_paths].flatten.map { |f| option_library_path % filename(f) }
+
+ _pp "LD", outfile
+ _run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => filename(outfile) , :objs => filename(objfiles).join(' '),
+ :flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
+ :flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
:libs => library_flags.join(' ') }
end
end
@@ -149,7 +157,7 @@ module MRuby
def run(outfile, objfiles)
FileUtils.mkdir_p File.dirname(outfile)
- _pp "AR #{filename(outfile)}"
+ _pp "AR", outfile
_run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).join(' ') }
end
end
@@ -165,7 +173,7 @@ module MRuby
def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile)
- _pp "YACC #{filename(infile)} > #{filename(outfile)}"
+ _pp "YACC", infile, outfile
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end
end
@@ -181,7 +189,7 @@ module MRuby
def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile)
- _pp "GPERF #{filename(infile)} > #{filename(outfile)}"
+ _pp "GPERF", infile, outfile
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end
end
@@ -198,7 +206,7 @@ module MRuby
end
def run_clone(dir, url, _flags = [])
- _pp "GIT #{url} > #{filename(dir)}"
+ _pp "GIT", url, dir
_run clone_options, { :flags => [flags, _flags].flatten.join(' '), :url => url, :dir => filename(dir) }
end
end
@@ -214,7 +222,7 @@ module MRuby
@command ||= @build.mrbcfile
IO.popen("#{filename @command} #{@compile_options % {:funcname => funcname}}", 'r+') do |io|
[infiles].flatten.each do |f|
- _pp " MRBC #{f}"
+ _pp "MRBC", "#{f}", nil, :indent => 2
io.write IO.read(f)
end
io.close_write
diff --git a/tasks/mruby_build_gem.rake b/tasks/mruby_build_gem.rake
index ae0a79447..80990773d 100644
--- a/tasks/mruby_build_gem.rake
+++ b/tasks/mruby_build_gem.rake
@@ -2,7 +2,11 @@ module MRuby
module LoadGems
def gem(gemdir, &block)
gemdir = load_external_gem(gemdir) if gemdir.is_a?(Hash)
- load File.join(gemdir, "mrbgem.rake")
+ gemrake = File.join(gemdir, "mrbgem.rake")
+
+ fail "Can't find #{gemrake}" unless File.exists?(gemrake)
+ load gemrake
+
Gem.current.dir = gemdir
Gem.current.build = MRuby::Build.current
Gem.current.build_config_initializer = block
diff --git a/tasks/ruby_ext.rake b/tasks/ruby_ext.rake
index 2536a2e4b..6817f6018 100644
--- a/tasks/ruby_ext.rake
+++ b/tasks/ruby_ext.rake
@@ -57,6 +57,10 @@ else
$pp_show = false if $verbose
end
-def _pp(msg)
- puts msg if $pp_show
+def _pp(cmd, src, tgt=nil, options={})
+ return unless $pp_show
+
+ width = 5
+ template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s"
+ puts template % [cmd, src, tgt ? "-> #{tgt}" : nil]
end
diff --git a/tasks/toolchains/clang.rake b/tasks/toolchains/clang.rake
index 01dd5f234..1785c4c79 100644
--- a/tasks/toolchains/clang.rake
+++ b/tasks/toolchains/clang.rake
@@ -1,6 +1,8 @@
MRuby::Toolchain.new(:clang) do |conf|
toolchain :gcc
- conf.cc.command = ENV['CC'] || 'clang'
+ [conf.cc, conf.cxx, conf.objc].each do |cc|
+ cc.command = ENV['CC'] || 'clang'
+ end
conf.linker.command = ENV['LD'] || 'clang'
end
diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake
index c624c8fc9..2c160683d 100644
--- a/tasks/toolchains/gcc.rake
+++ b/tasks/toolchains/gcc.rake
@@ -1,5 +1,5 @@
MRuby::Toolchain.new(:gcc) do |conf|
- conf.cc do |cc|
+ [conf.cc, conf.cxx, conf.objc].each do |cc|
cc.command = ENV['CC'] || 'gcc'
cc.flags = [ENV['CFLAGS'] || %w(-g -O3 -Wall -Werror-implicit-function-declaration)]
cc.include_paths = ["#{root}/include"]
@@ -16,6 +16,6 @@ MRuby::Toolchain.new(:gcc) do |conf|
linker.library_paths = []
linker.option_library = '-l%s'
linker.option_library_path = '-L%s'
- linker.link_options = '%{flags} -o %{outfile} %{objs} %{libs}'
+ linker.link_options = '%{flags} -o %{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}'
end
end
diff --git a/tasks/toolchains/vs2012.rake b/tasks/toolchains/vs2012.rake
index c3599a59b..e3b80b98b 100644
--- a/tasks/toolchains/vs2012.rake
+++ b/tasks/toolchains/vs2012.rake
@@ -1,5 +1,5 @@
MRuby::Toolchain.new(:vs2012) do |conf|
- conf.cc do |cc|
+ [conf.cc, conf.cxx].each do |cc|
cc.command = ENV['CC'] || 'cl.exe'
cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /D_DEBUG /MDd /Zi /Od /RTC1 /DDISABLE_GEMS /DHAVE_STRING_H /DNO_GETTIMEOFDAY /D_CRT_SECURE_NO_WARNINGS)]
cc.include_paths = ["#{root}/include"]
@@ -16,7 +16,7 @@ MRuby::Toolchain.new(:vs2012) do |conf|
linker.library_paths = %w()
linker.option_library = '%s'
linker.option_library_path = '/LIBPATH:%s'
- linker.link_options = "%{flags} /OUT:%{outfile} %{objs} %{libs}"
+ linker.link_options = "%{flags} /OUT:%{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}"
end
conf.archiver do |archiver|
diff --git a/test/mrbtest.rake b/test/mrbtest.rake
index 76ddc30f8..4d4a7e57c 100644
--- a/test/mrbtest.rake
+++ b/test/mrbtest.rake
@@ -10,16 +10,18 @@ MRuby.each_target do
objs = [objfile("#{build_dir}/#{dir}/driver"), mlib].flatten
- file exec => objs + gems.map(&:testlib) + [libfile("#{build_dir}/lib/libmruby")] do |t|
+ file exec => objs + gems.map(&:testlib).flatten + [libfile("#{build_dir}/lib/libmruby")] do |t|
gem_flags = gems.map { |g| g.linker.flags }
+ gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
+ gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
gem_libraries = gems.map { |g| g.linker.libraries }
gem_library_paths = gems.map { |g| g.linker.library_paths }
- linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags
+ linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries
end
file mlib => [clib]
file clib => [mrbcfile, init, asslib] + mrbs do |t|
- _pp "GEN *.rb > #{clib}"
+ _pp "GEN", "*.rb", "#{clib}"
open(clib, 'w') do |f|
f.puts IO.read(init)
mrbc.run f, [asslib] + mrbs, 'mrbtest_irep'
diff --git a/test/t/range.rb b/test/t/range.rb
index 691ca7898..21bcb5c55 100644
--- a/test/t/range.rb
+++ b/test/t/range.rb
@@ -48,14 +48,13 @@ assert('Range#include', '15.2.14.4.8') do
a.include?(5) and not a.include?(20)
end
-# TODO SEGFAULT ATM
-#assert('Range#initialize', '15.2.14.4.9') do
-# a = Range.new(1, 10, true)
-# b = Range.new(1, 10, false)
-#
-# a == (1..10) and a.exclude_end? and b == (1..10) and
-# not b.exclude_end?
-#end
+assert('Range#initialize', '15.2.14.4.9') do
+ a = Range.new(1, 10, true)
+ b = Range.new(1, 10, false)
+
+ a == (1...10) and a.exclude_end? and b == (1..10) and
+ not b.exclude_end?
+end
assert('Range#last', '15.2.14.4.10') do
(1..10).last == 10
diff --git a/tools/mirb/mirb.rake b/tools/mirb/mirb.rake
index 0c340a2f5..46e69136e 100644
--- a/tools/mirb/mirb.rake
+++ b/tools/mirb/mirb.rake
@@ -7,9 +7,11 @@ MRuby.each_target do
file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
gem_flags = gems.map { |g| g.linker.flags }
+ gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
+ gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
gem_libraries = gems.map { |g| g.linker.libraries }
gem_library_paths = gems.map { |g| g.linker.library_paths }
- linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags
+ linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries
end
end
end
diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c
index 4dc9871c7..63762143a 100644
--- a/tools/mrbc/mrbc.c
+++ b/tools/mrbc/mrbc.c
@@ -231,4 +231,9 @@ void
mrb_init_mrbgems(mrb_state *mrb)
{
}
+
+void
+mrb_final_mrbgems(mrb_state *mrb)
+{
+}
#endif
diff --git a/tools/mruby/mruby.rake b/tools/mruby/mruby.rake
index df31b0343..fccebff63 100644
--- a/tools/mruby/mruby.rake
+++ b/tools/mruby/mruby.rake
@@ -7,9 +7,11 @@ MRuby.each_target do
file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
gem_flags = gems.map { |g| g.linker.flags }
+ gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
+ gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
gem_libraries = gems.map { |g| g.linker.libraries }
gem_library_paths = gems.map { |g| g.linker.library_paths }
- linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags
+ linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries
end
end
end