I want to introduce the patching rule by mrbgems to mruby core.
First, I want to make mruby-JIT mrbgems. https://github.com/miura1729/mruby
So I have to patch to mruby because JIT is too low level.
I introduce how to patch.
See: https://github.com/wanabe/mruby-jit
If you wish to include some source files in mruby core, push files into core/src directory.
core/src/.{c,cc,cpp,m,asm,S} is required by libmruby and libmruby_core as same as src/.{c,cc,cpp,m,asm,S}, original mruby source files.
You can patch to mruby core to use MRuby::Build#patch in rakefile. Like this:
patch "path/from/mruby/root", "path/to/patch"
or
patch "path/from/mruby/root", __FILE__ do ... end
Patched files is pushed to build/(build-target)/original/path. In example, patched vm.c for host, is in build/host/src/vm.c.
1st argument is patch target.
2nd argument is patch file. This file is required by patched file. So if you update this file, rakefile update patched file automatically.
When MRuby::Build#patch receive a block, patch file isn't read content but use time stamp to update. block is evaluated as patching rule.
patched c-sources come into use in place of original ones. Because rule of making object files is overwritten by MRuby::Build#patch.
patched headers is same. Because build/(build-target)/include add to top of include_paths of cc and cxx.
You can write patches in Ruby DSL.
Patching state has @line, @match, and @mark.
@line is index of current line.
most methods , like MRuby::PatchTarget#search, can change @line.
@match is last MatchData.
@mark is index of marked line and updated by MRuby::PatchTarget#mark or MRuby::PatchTarget#search.
Patching range is represented by @mark..@line.
- insert(String)
- insert string to current line.
- mark
- mark current line.
- delete
- delete lines
@mark..@lineand set@line = @mark.
- delete lines
- change(String)
- same as
delete.insert(str).
- same as
- each do ... end | each(pattern) do ... end
- enumerate each line between
@mark..@line. If pattern is given, enumerate line onlypattern === line.
- enumerate each line between
- rest
- set
@mark = @lineand @line to last line. If block given, eval block and reset line last value.
- set
- seek(*patterns)
- down @line from current line by pattern, following:
- pattern is
Integer-- treat as offset. eval@line += pattern. - pattern is
:mark-- set mark. same asseek(*patterns_before_mark).mark.seek(*patterns_after_mark) - other -- seek the line what
pattern === line.
- pattern is
- down @line from current line by pattern, following:
patch(1), Unix command, is useful. But in this case patch(1) is not fit unfortunately, I guess.
mruby core get change day by day. So someday, patch write once may be too old. Of course DSL doesn't keep patch available on eternity. But DSL can extend the life cycle than patch(1), I guess.
patch(1) needs some lines to identify target line. For example, A gem and B gem want to extend same struct, patching will be failed.