New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of keyword arguments. #3629
Conversation
Great works! I fount some incompatibility with CRuby.
|
@ksss @miura1729 |
@take-cheeze I found another bugs may about GC. $ ruby -e 'p ->(a:, **k) { [a, k] }.call(a: 1, b: 2, c: 3)'
[1, {:b=>2, :c=>3}]
$ mruby -e 'p ->(a:, **k) { [a, k] }.call(a: 1, b: 2, c: 3)'
[1, {:b=>2}] And interpretation for argument. $ ruby -e 'p ->(a = nil, **k) { [a, k] }.call({a: 1}, {})'
[{:a=>1}, {}]
$ mruby -e 'p ->(a = nil, **k) { [a, k] }.call({a: 1}, {})'
trace:
[0] -e:1
-e:1: 'call': wrong number of arguments (2 for 0) (ArgumentError) mruby: e7bab50 build_config.rb MRuby::Build.new do |conf|
toolchain :gcc
enable_debug
conf.gembox 'default'
conf.cc.defines << %w(MRB_GC_STRESS)
end |
@ksss Should be fixed with updates. |
@take-cheeze Great! $ cat t.rb
p ["-> (a:, b:) { }.arity", -> (a:, b:) { }.arity]
p ["-> (a, b, c:, d: 1) { }.arity", -> (a, b, c:, d: 1) { }.arity]
p ["-> (a, b=1, *c, d:, e:, f: 2, **k, &l) { }.arity", -> (a, b=1, *c, d:, e:, f: 2, **k, &l) { }.arity]
$ ruby t.rb
["-> (a:, b:) { }.arity", 1]
["-> (a, b, c:, d: 1) { }.arity", 3]
["-> (a, b=1, *c, d:, e:, f: 2, **k, &l) { }.arity", -3]
$ mruby t.rb
["-> (a:, b:) { }.arity", 2]
["-> (a, b, c:, d: 1) { }.arity", -4]
["-> (a, b=1, *c, d:, e:, f: 2, **k, &l) { }.arity", -4] See also |
@ksss I should read description of |
@take-cheeze Thank you for responding. |
@ksss That's nice! |
Add `&`, `*`, `**` for unnamed register.
Got some tweet from JIT implementer: https://twitter.com/miura1729/status/855888165755691008 `acc` can be reduced to 16-bit since it's value always fit in 9bit.
Rebased and fixed a GC issue in C function. |
@matz @take-cheeze What's the status about keyword arguments? It was announced that they will arrive with 1.4.0 and 1.4.1 is out already but without them. |
@katzer I don't know the detailed progress but this can't be applied without an incompatible changes to VM instructions so I'm waiting for the new VM instruction sets to come. |
We are going to make big changes in the next release and name it mruby 2.0! |
Whats the big picture for mruby 2.0? |
The current plan is:
|
The implementation of keyword arguments is heavily rely on the prototype made by @take-cheeze in #3629.
That sounds all great, however what about better threading support? |
@katzer Unfortunately there's no plan for the better threading support. Some platforms mruby supports do not provide threading functionality (e.g. small devices without OS). That means mruby cannot support threading by the core, which is needed for the better treading support, in my opinion. |
Since the keyword argument is merged in the |
The implementation of keyword arguments is heavily rely on the prototype made by @take-cheeze in mruby#3629.
Thank @keizo042 and @ksss for sending me
Ruby Under a Microscope
via amazon.co.jp. The book helped a lot to start implementing this.This PR isn't squashed since its modification is too big and may need more changes.
parse.y
. Thanks to CRuby developers.Optimize keyword arguments.
, I've implemented handling keyword arguments only withHash
.OP_SENDK
, it usesArray
to handle passed keyword arguments instead. Though the old way is still used to handle arguments withOP_SEND
orOP_SENDB
opcode.struct mrb_callinfo
size is increased for optimization.I've re-reduced size of
mrb_callinfo
by reducing size ofacc
field since it's always 9-bit integer(GETARG_A
). Thanks to @miura1729 for some advice.And
kwds
is removed since it's value is from kdict.codedump.c
improvements is added to know what is on the stack.&
,*
,**
when there is no specific variable name.OP_KARG
andOP_KDICT
's behavior is changed from the previous documentation to make keyword arguments handling easier. See updated documents for detail.OP_SENDK
is added to call method with optimized keyword arguments passing.nil
object.OP_KARG
keyword is linear searched instead ofmrb_hash_get
.OP_ENTER
's arguments specifier's layout has changed. And now maybe it's got a big VM instruction.4
bit(max: 31 -> 15).3
bit (max: 7) each.OP_ENTERK
may make VM compatible.Hash#fetch
(implemented inmruby-hash-ext
),Hash#delete
,Hash#key?
isn't used to handle keyword arguments. SoHash
methods overwriting example inRuby Under a Microscope
can't be reproduced in this implementation.mrb_get_args
can only handle keyword arguments with last hash argument.OP_KARG
andOP_KDICT
?.