Commit 02fd208f
02fd208f31ceMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #147 from ryanseys/rs-symbol-case
feat(codegen): Symbol#upcase and Symbol#downcase
Details
- Commit
- 02fd208f31ce
- Parent
- b09cac74596f
- Merge parent
- e383ca609379
spinel_codegen.rbmodifiedView file
@@ -2174,10 +2174,10 @@
21742174
if mname == "round"21752175
return "int"21762176
end2177-
if mname == "upcase"2178-
return "string"2179-
end2180-
if mname == "downcase"2177+
if mname == "upcase" || mname == "downcase"2178+
if recv >= 0 && infer_type(recv) == "symbol"2179+
return "symbol"2180+
end21812181
return "string"21822182
end21832183
if mname == "swapcase"@@ -8511,6 +8511,16 @@
85118511
end85128512
end85138513
end8514+
# `:foo.upcase` / `:foo.downcase` lower to sp_str_upcase /8515+
# sp_str_downcase on the symbol's name string and re-intern via8516+
# sp_sym_intern. Mark the dynamic-pool path so it gets emitted.8517+
if mname == "upcase" || mname == "downcase"8518+
if @nd_receiver[nid] >= 08519+
if infer_type(@nd_receiver[nid]) == "symbol"8520+
@needs_sym_intern = 18521+
end8522+
end8523+
end85148524
# Methods that need string helpers only when receiver is string85158525
if mname == "+" || mname == "*" || mname == "reverse"85168526
if @nd_receiver[nid] >= 0@@ -16673,6 +16683,12 @@
1667316683
if mname == "to_sym" || mname == "intern"1667416684
return rc1667516685
end16686+
# Symbol#upcase / Symbol#downcase: lower-case via the str case helper16687+
# then re-intern. Naming convention `sp_str_<mname>` lets one branch16688+
# handle both — and slots in cleanly for capitalize/swapcase later.16689+
if mname == "upcase" || mname == "downcase"16690+
return "sp_sym_intern(sp_str_" + mname + "(sp_sym_to_s(" + rc + ")))"16691+
end1667616692
if mname == "inspect"1667716693
return "sp_str_concat(\":\", sp_sym_to_s(" + rc + "))"1667816694
endtest/symbol_upcase_downcase.rbaddedView file
Loading diff…