Commit 108a3fc8
108a3fc8dc97Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
Add sp_String — mutable, GC-managed string type for << operator
Variables that use << get promoted from const char * (STRING) to sp_String * (SP_STRING) during type inference. Existing STRING programs are unaffected.
Runtime: sp_String_new, sp_String_append, sp_String_length, sp_String_upcase, sp_String_reverse, sp_String_include, sp_String_cstr. Only emitted when needs_sp_string is true.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 108a3fc8dc97
- Parent
- f684a406e399
examples/bm_mutable_str.rbaddedView file
1+
# Test mutable strings (sp_String)2+
3+
# String << (true mutation, not reassignment)4+
s = "hello"5+
s << " world"6+
s << "!"7+
puts s # hello world!8+
puts s.length # 129+
10+
# Build string incrementally11+
buf = ""12+
5.times do |i|13+
buf << i.to_s14+
buf << ","15+
end16+
puts buf # 0,1,2,3,4,17+
18+
# String methods on mutable string19+
s2 = "Hello World"20+
puts s2.upcase # HELLO WORLD21+
puts s2.reverse # dlroW olleH22+
puts s2.include?("World") # true23+
24+
puts "done"src/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…