Commit a4c5957f
a4c5957fa94fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #152 from ryanseys/rs-hash-transform-values-block
feat(codegen): Hash#transform_values block form for int_str_hash
Details
- Commit
- a4c5957fa94f
- Parent
- e139e3a8b94c
- Merge parent
- 216aa5542143
spinel_codegen.rbmodifiedView file
@@ -18003,6 +18003,34 @@
1800318003
return "sp_IntStrHash_get(" + rc + ", " + key + ")"1800418004
end1800518005
end18006+
# transform_values block form. Mirrors str_int_hash's arm: walk18007+
# self, run the block on each value, build a new hash with the18008+
# same keys and the block's returns. Result type matches the18009+
# input hash type.18010+
if mname == "transform_values"18011+
if @nd_block[nid] >= 018012+
blk = @nd_block[nid]18013+
bp = get_block_param(nid, 0)18014+
tmp = new_temp18015+
emit(" sp_IntStrHash *" + tmp + " = sp_IntStrHash_new();")18016+
emit(" for (mrb_int _i = 0; _i < " + rc + "->len; _i++) {")18017+
emit(" const char *lv_" + bp + " = sp_IntStrHash_get(" + rc + ", " + rc + "->order[_i]);")18018+
push_scope18019+
declare_var(bp, "string")18020+
bbody = @nd_body[blk]18021+
bexpr = "0"18022+
if bbody >= 018023+
bs = get_stmts(bbody)18024+
if bs.length > 018025+
bexpr = compile_expr(bs.last)18026+
end18027+
end18028+
emit(" sp_IntStrHash_set(" + tmp + ", " + rc + "->order[_i], " + bexpr + ");")18029+
pop_scope18030+
emit(" }")18031+
return tmp18032+
end18033+
end1800618034
end1800718035
if recv_type == "str_str_hash"1800818036
if mname == "[]"test/hash_transform_values_int_str.rbaddedView file
Loading diff…