mruby.sh

[CW 25] mruby news

written by Daniel Bovensiepen on 2012-06-22 19:06 UTC

What happened this week on the mruby front?

Struct

Big work was done on the Struct library. This class doesn’t SEGV anymore, additional test cases were added and the possibility to add or remove this library from the mruby-core was integrated.

Commit (Struct Dis-/Enable), Commit (fix Struct Access), Commit (fix Struct initialize), Commit (Add Struct Tests), Commit (fix return value)

Compile flags

Till now the CFLAGS for mruby were always set to “-g -O3″. With this we had the benefit of having debug support build into every built. But most of the user out there might never use the gdb on mruby. So I decided to add the following three compile options to the Makefiles:

# compile with "-g -O3"
COMPILE_MODE=debug make

# compile with "-O3"
COMPILE_MODE=release make

# compile with "-Os"
COMPILE_MODE=small make

Commit

New Methods

Symbol got the spaceship method (<=>) and Module got also a lot (define_method, attr, attr_reader, attr_writer, attr_accessor). Lambda got initialize_copy and is now duplicable.

Commit (Symbo#<=>), Commit (Method#define_method), Commit (Module#{attr,attr_reader,attr_writer,attr_accessor}), Commit (Lambda#initialize_copy)

printf

One method I was wondering about is printf. This one was also added this week. printf is working like print but calls sprintf before its execution. Due to the reason that sprintf is an optional feature of mruby-core, printf should be optional too. But it appears that printf is implemented in pure Ruby and has no compiler switch by now. Lets see what happens with this method.

Update: I made a change to printf. Now it is only available if sprintf is also enabled. I used respond_to? to check if sprintf is available. I’m curious if this is the best way. This code will now also be compiled into the core, even if sprintf was deactivated. It won’t be executed but at least during initialization it will be called one-time. I guess it is ok for now but in case this kind of stuff is growing there might be another solution necessary.

Commit, Commit (printf optional)

Optional Tests

Lately I played around with the customization of mruby. While I removed some features I notice that the test cases are failing (good indicator that they are working). Nevertheless I don’t want to see failing tests if I decided to not use specific features of mruby. So I decided to patch this behavior away. My first approach was to define a new constant which defines the configuration of the mruby-core. Matz actually suggested to check if the related class is defined. In the end this solution is more implementation-independent. All tests which are testing optional mruby features are from now on not executed if the feature is disabled.

Commit

strlen replacement by sizeof

Masaki Muranaka suggested to reduce the use of strlen due to the reason that on small systems it is to blown. I think it is a good idea to look at optimization of the code but I’m not completely sure if now is already the right time to optimize parts of mruby. sizeof instead of strlen might not be such a dramatic optimization. But I’m afraid that we try to early to optimize the core and make the code in this way harder to read.

Commit (codegen), Commit (Reduce mrb_str_new2), Commit (Remove strlen in array)


available also via rss