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 end
1800518005 end
18006+ # transform_values block form. Mirrors str_int_hash's arm: walk
18007+ # self, run the block on each value, build a new hash with the
18008+ # same keys and the block's returns. Result type matches the
18009+ # input hash type.
18010+ if mname == "transform_values"
18011+ if @nd_block[nid] >= 0
18012+ blk = @nd_block[nid]
18013+ bp = get_block_param(nid, 0)
18014+ tmp = new_temp
18015+ 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_scope
18019+ declare_var(bp, "string")
18020+ bbody = @nd_body[blk]
18021+ bexpr = "0"
18022+ if bbody >= 0
18023+ bs = get_stmts(bbody)
18024+ if bs.length > 0
18025+ bexpr = compile_expr(bs.last)
18026+ end
18027+ end
18028+ emit(" sp_IntStrHash_set(" + tmp + ", " + rc + "->order[_i], " + bexpr + ");")
18029+ pop_scope
18030+ emit(" }")
18031+ return tmp
18032+ end
18033+ end
1800618034 end
1800718035 if recv_type == "str_str_hash"
1800818036 if mname == "[]"