Commit 5f40630d
5f40630dc111Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add Struct.new support
Struct.new(:x, :y) detected in class analysis → synthetic class:
- Fields from symbol arguments → ivars with getter/setter
- Synthetic initialize assigns params to fields
- Works with all existing features (method calls, puts, etc.)
Test: examples/bm_struct.rb — Point and Color structs. Output matches Ruby.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 5f40630dc111
- Parent
- 41023eb2c21a
examples/bm_struct.rbaddedView file
1+
# Test Struct2+
3+
Point = Struct.new(:x, :y)4+
5+
p1 = Point.new(3, 4)6+
puts p1.x # 37+
puts p1.y # 48+
9+
p1.x = 1010+
puts p1.x # 1011+
12+
# Struct with methods13+
Color = Struct.new(:r, :g, :b)14+
15+
c = Color.new(255, 128, 0)16+
puts c.r # 25517+
puts c.g # 12818+
puts c.b # 0src/codegen.cmodifiedView file
Loading diff…