Commit b28557ec

b28557ec9504Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

docs: update README with current features and benchmarks

  • Update benchmark table with all categories (computation, data structures, real-world programs)
  • Add new features: global variables, Fiber, Bigint, nullable types, each_with_index, for..in array, String#tr/ljust/rjust, char comparison optimization
  • Update architecture section with sp_runtime.h and libspinel_rt.a
  • Update file counts and line counts
  • Document require_relative support
  • Update limitations (Fiber is now supported)

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
b28557ec9504
Parent
224db21e47fb

README.mdmodifiedView file

@@ -2,7 +2,7 @@
22
33 Spinel compiles Ruby source code into standalone native executables.
44 It performs whole-program type inference and generates optimized C code,
5-achieving 9x-4,000x speedup over CRuby.
5+achieving significant speedups over CRuby.
66
77 Spinel is **self-hosting**: the compiler backend is written in Ruby and
88 compiles itself into a native binary.
@@ -25,7 +25,7 @@
2525 C source (.c)
2626 |
2727 v
28-cc -O2 -lm Standard C compiler
28+cc -O2 -Ilib -lm Standard C compiler + runtime header
2929 |
3030 v
3131 Native binary Standalone, no runtime dependencies
@@ -78,77 +78,108 @@
7878
7979 ## Benchmarks
8080
81-39/39 benchmarks pass. 59/60 tests pass.
81+52/53 benchmarks pass. 65 tests pass.
8282
83-| Benchmark | Spinel | CRuby 3.x | Speedup |
84-|-----------|--------|-----------|---------|
85-| attr_accessor_bench | 0.4 ms | 1,690 ms | **4,225x** |
86-| life (Game of Life) | 0.4 ms | 1,500 ms | **3,750x** |
87-| inline | 0.4 ms | 1,560 ms | **3,900x** |
88-| send_cfunc_block | 0.4 ms | 1,400 ms | **3,500x** |
89-| send_bmethod | 0.5 ms | 600 ms | **1,200x** |
90-| nested_loop | 0.4 ms | 330 ms | **825x** |
91-| keyword_args | 0.4 ms | 290 ms | **725x** |
92-| str_concat | 0.5 ms | 60 ms | **120x** |
93-| ruby_xor | 10 ms | 1,490 ms | **149x** |
94-| ackermann | 4.4 ms | 380 ms | **86x** |
95-| mandelbrot | 20 ms | 1,160 ms | **58x** |
96-| fib(34) | 10 ms | 560 ms | **56x** |
97-| spectralnorm | 20 ms | 1,010 ms | **50x** |
98-| nqueens | 800 ms | 25,050 ms | **31x** |
99-| sudoku | 4.9 ms | 150 ms | **31x** |
100-| so_lists | 20 ms | 530 ms | **26x** |
101-| splay | 10 ms | 240 ms | **24x** |
102-| fizzbuzz (lambda) | 1,630 ms | 32,180 ms | **20x** |
103-| gcbench | 480 ms | 4,320 ms | **9x** |
83+### Computation
10484
85+| Benchmark | Spinel | CRuby | Speedup |
86+|-----------|--------|-------|---------|
87+| life (Game of Life) | 2 ms | 1,487 ms | **743x** |
88+| ackermann | 6 ms | 397 ms | **66x** |
89+| mandelbrot | 24 ms | 1,179 ms | **49x** |
90+| matmul | 8 ms | 319 ms | **39x** |
91+| nqueens | 770 ms | 25,600 ms | **33x** |
92+| tarai | 16 ms | 433 ms | **27x** |
93+| tak | 22 ms | 506 ms | **23x** |
94+| sudoku | 7 ms | 148 ms | **21x** |
95+| sieve | 20 ms | 410 ms | **20x** |
96+| partial_sums | 82 ms | 1,282 ms | **15x** |
97+
98+### Data Structures & GC
99+
100+| Benchmark | Spinel | CRuby | Speedup |
101+|-----------|--------|-------|---------|
102+| rbtree (red-black tree) | 18 ms | 579 ms | **32x** |
103+| splay tree | 10 ms | 210 ms | **21x** |
104+| so_lists | 29 ms | 520 ms | **17x** |
105+| gcbench | 486 ms | 4,425 ms | **9x** |
106+| linked_list | 63 ms | 484 ms | **7.7x** |
107+| binary_trees | 5 ms | 80 ms | **16x** |
108+
109+### Real-World Programs
110+
111+| Benchmark | Spinel | CRuby | Speedup |
112+|-----------|--------|-------|---------|
113+| fasta (DNA seq gen) | 1,260 ms | 7,700 ms | **6.1x** |
114+| io_wordcount | 29 ms | 151 ms | **5.2x** |
115+| json_parse | 104 ms | 453 ms | **4.4x** |
116+| template engine | 227 ms | 983 ms | **4.3x** |
117+| csv_process | 273 ms | 952 ms | **3.5x** |
118+| pidigits (bigint) | 6,300 ms | 11,600 ms | **1.8x** |
119+
105120 ## Supported Ruby Features
106121
107122 **Core**: Classes, inheritance, `super`, `include` (mixin), `attr_accessor`,
108123 `Struct.new`, `alias`, module constants, open classes for built-in types.
109124
110125 **Control Flow**: `if`/`elsif`/`else`, `unless`, `case`/`when`,
111-`case`/`in` (pattern matching), `while`, `until`, `loop`, `for..in`,
112-`break`, `next`, `return`, `catch`/`throw`, `&.` (safe navigation).
126+`case`/`in` (pattern matching), `while`, `until`, `loop`, `for..in`
127+(range and array), `break`, `next`, `return`, `catch`/`throw`,
128+`&.` (safe navigation).
113129
114130 **Blocks**: `yield`, `block_given?`, `&block`, `proc {}`, `Proc.new`,
115-lambda `-> x { }`, `method(:name)`. Block methods: `each`, `map`,
116-`select`, `reject`, `reduce`, `sort_by`, `any?`, `all?`, `none?`.
131+lambda `-> x { }`, `method(:name)`. Block methods: `each`,
132+`each_with_index`, `map`, `select`, `reject`, `reduce`, `sort_by`,
133+`any?`, `all?`, `none?`, `times`, `upto`, `downto`.
117134
118135 **Exceptions**: `begin`/`rescue`/`ensure`/`retry`, `raise`,
119136 custom exception classes.
120137
121138 **Types**: Integer, Float, String (immutable + mutable), Array, Hash,
122-Range, Time, StringIO, File, Regexp. Polymorphic values via tagged unions.
139+Range, Time, StringIO, File, Regexp, Bigint (auto-promoted), Fiber.
140+Polymorphic values via tagged unions. Nullable object types (`T?`)
141+for self-referential data structures (linked lists, trees).
142+
143+**Global Variables**: `$name` compiled to static C variables with
144+type-mismatch detection at compile time.
123145
124146 **Strings**: `<<` automatically promotes to mutable strings (`sp_String`)
125-for O(n) in-place append. `+`, interpolation, and methods work on both.
147+for O(n) in-place append. `+`, interpolation, `tr`, `ljust`/`rjust`/`center`,
148+and all standard methods work on both. Character comparisons like
149+`s[i] == "c"` are optimized to direct char array access (zero allocation).
126150
127151 **Regexp**: Built-in NFA regexp engine (no external dependency).
128152 `=~`, `$1`-`$9`, `match?`, `gsub(/re/, str)`, `sub(/re/, str)`,
129153 `scan(/re/)`, `split(/re/)`.
130154
131-**Memory**: Mark-and-sweep GC with explicit roots and adaptive threshold.
132-Small classes (<=4 fields, no inheritance, no mutation through parameters)
133-are automatically stack-allocated as **value types** -- no GC allocation,
134-no rooting overhead. Programs using only value types emit no GC runtime
135-at all. Arrays track GC-managed memory for accurate collection.
155+**Bigint**: Arbitrary precision integers via mruby-bigint. Auto-promoted
156+from loop multiplication patterns (e.g. `q = q * k`). Linked as static
157+library -- only included when used.
158+
159+**Fiber**: Cooperative concurrency via `ucontext_t`. `Fiber.new`,
160+`Fiber#resume`, `Fiber.yield` with value passing. Captures free
161+variables via heap-promoted cells.
136162
163+**Memory**: Mark-and-sweep GC with size-segregated free lists, non-recursive
164+marking, and sticky mark bits. Small classes (<=4 fields, no inheritance,
165+no mutation through parameters) are automatically stack-allocated as
166+**value types**. Programs using only value types emit no GC runtime at all.
167+
137168 **I/O**: `puts`, `print`, `printf`, `p`, `gets`, `ARGV`, `ENV[]`,
138-`File.read/write/open`, `system()`, backtick.
169+`File.read/write/open` (with blocks), `system()`, backtick.
139170
140171 ## Architecture
141172
142173 ```
143-spinel One-command wrapper script (POSIX shell)
144-spinel_parse.rb CRuby frontend: Prism AST → text format (715 lines)
145-spinel_parse.c C frontend: libprism → text format (915 lines)
146-spinel_codegen.rb Compiler backend: AST → C code (15,126 lines)
147-lib/regexp/ Built-in regexp engine (1,759 lines)
148-lib/ Stub libraries (stringio, strscan, optparse, etc.)
149-test/ 60 test programs
150-benchmark/ 39 benchmark programs
151-Makefile Build automation
174+spinel One-command wrapper script (POSIX shell)
175+spinel_parse.c C frontend: libprism → text AST (1,061 lines)
176+spinel_codegen.rb Compiler backend: AST → C code (17,162 lines)
177+lib/sp_runtime.h Runtime library header (455 lines)
178+lib/sp_bigint.c Arbitrary precision integers (5,406 lines)
179+lib/regexp/ Built-in regexp engine (1,759 lines)
180+test/ 65 feature tests
181+benchmark/ 53 benchmarks
182+Makefile Build automation
152183 ```
153184
154185 The compiler backend (`spinel_codegen.rb`) is written in a Ruby subset
@@ -158,19 +189,26 @@
158189
159190 No metaprogramming, no `eval`, no `require` in the backend.
160191
192+The runtime (`lib/sp_runtime.h`) contains GC, array/hash/string
193+implementations, and all runtime support as a single header file.
194+Generated C includes this header, and the linker pulls only the
195+needed parts from `libspinel_rt.a` (bigint + regexp engine).
196+
161197 The parser has two implementations:
162198 - **spinel_parse.c** links libprism directly (no CRuby needed)
163199 - **spinel_parse.rb** uses the Prism gem (CRuby fallback)
164200
165201 Both produce identical AST output. The `spinel` wrapper prefers the
166-C binary if available.
202+C binary if available. `require_relative` is resolved at parse time
203+by inlining the referenced file.
167204
168205 ## Building
169206
170207 ```bash
171208 make # build parser + regexp library + bootstrap compiler
172-make test # run 60 tests
173-make bench # run 39 benchmarks
209+make test # run 65 feature tests (requires bootstrap)
210+make bench # run 53 benchmarks (requires bootstrap)
211+make bootstrap # rebuild compiler from source
174212 sudo make install # install to /usr/local (spinel in PATH)
175213 make clean # remove build artifacts
176214 ```
@@ -187,8 +225,9 @@
187225
188226 - **No eval**: `eval`, `instance_eval`, `class_eval`
189227 - **No metaprogramming**: `send`, `method_missing`, `define_method` (dynamic)
190-- **No threads**: `Thread`, `Fiber`, `Mutex`
228+- **No threads**: `Thread`, `Mutex` (Fiber is supported)
191229 - **No encoding**: assumes UTF-8/ASCII
230+- **No general lambda calculus**: deeply nested `-> x { }` with `[]` calls
192231
193232 ## Dependencies
194233
@@ -196,6 +235,7 @@
196235 CRuby (bootstrap only)
197236 - **Run time**: None. Generated binaries need only libc + libm.
198237 - **Regexp**: Built-in engine, no external library needed.
238+- **Bigint**: Built-in (from mruby-bigint), linked only when used.
199239
200240 ## History
201241