Commit 254c9902
254c9902f8e1Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · ~1 modified
Description
Update README with yield, case/when, inheritance, benchmarks
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 254c9902f8e1
- Parent
- fb0285220b43
README.mdmodifiedView file
@@ -75,42 +75,80 @@
7575
7676
| Feature | Example |7777
|---------|---------|78+
| **Classes & OOP** | |7879
| Classes with instance variables | `class Vec; def initialize(x,y,z); @x=x; end; end` |80+
| Inheritance | `class Dog < Animal` |81+
| `super` | `super(name)` in child initialize/methods |7982
| Method definitions | `def vadd(b); Vec.new(@x+b.x, ...); end` |8083
| Getters/setters (inlined) | `def x; @x; end` / `def x=(v); @x=v; end` |8184
| Object construction | `Vec.new(1.0, 2.0, 3.0)` |8285
| Method calls on typed objects | `ray.org.vsub(@center)` |8386
| Modules with state | `module Rand; @x = 123; def self.rand; ...; end; end` |84-
| Local variables, constants | `size = 600`, `ITER = 49` |85-
| `while` loops | `while x <= count_size` |87+
| **Blocks & Closures** | |88+
| `yield` | `def my_iter(n); yield i; end` |89+
| Blocks at call sites | `my_iter(10) do \|i\| total += i end` |90+
| `Array#each/map/select` | `arr.each { \|x\| puts x }` (inlined) |8691
| `Integer#times` with block | `n.times do \|i\| ... end` |92+
| Lambda/closures | `-> x { x + 1 }` with capture analysis |93+
| **Control Flow** | |8794
| `if` / `elsif` / `else` | conditional branching |95+
| `case` / `when` / `else` | pattern matching with values, ranges |96+
| `unless` | `unless x > 20` |97+
| `while`, `until` | loops |8898
| Ternary operator | `escape ? 0 : 1` |89-
| `and` / `or` | `t > 0.0 and t < isect.t` |99+
| `and` / `or` / `not` | boolean operators |100+
| `break`, `next`, `return` | loop/method exit, continue |101+
| **Types & Literals** | |102+
| Integer, Float, Boolean, String, nil | unboxed C types |103+
| Integer arrays | push/pop/shift/dup/reverse!/each/map/select |104+
| Default parameter values | `def greet(name, greeting = "Hello")` |105+
| **Arithmetic & Operators** | |90106
| Arithmetic, comparison, bitwise | `+`, `-`, `*`, `/`, `%`, `<`, `>`, `==`, `<<`, `\|`, `^` |91107
| Unary minus | `-b`, `-(expr)` |92108
| `Math.sqrt`, `Math.cos`, `Math.sin` | C math functions |109+
| **I/O** | |110+
| `puts`, `print`, `printf`, `putc`, `p` | stdio calls |93111
| String interpolation | `"P4\n#{size} #{size}"` → printf |94-
| `puts`, `print`, `printf` | stdio calls |95112
| `Integer#chr` | `print byte_acc.chr` → putchar |96-
| `break`, `return` | loop/method exit |97-
| Parallel assignment | `zr, zi = tr, ti` |113+
| **Other** | |114+
| Parallel/chained assignment | `zr, zi = tr, ti` / `a = b = 0` |115+
| Local variables, constants | `size = 600`, `ITER = 49` |98116
| Array indexing | `basis[0].x`, `@spheres[1].intersect(...)` |117+
| Mark-and-sweep GC | automatic for heap-allocated objects |118+
119+
## Benchmarks120+
121+
| Benchmark | CRuby 3.2 | mruby | **Spinel AOT** | Speedup |122+
|-----------|-----------|-------|----------------|---------|123+
| mandelbrot (600x600 PBM) | 1.14s | 3.18s | **0.02s** | **57x** |124+
| ao_render (64x64 AO raytracer) | 3.55s | 13.69s | **0.07s** | **51x** |125+
| so_lists (300x10K arrays) | 0.44s | 2.01s | **0.02s** | **22x** |126+
| fib(34) recursive | 0.55s | 2.78s | **0.01s** | **55x** |127+
| lc_fizzbuzz (Church encoding) | 28.96s | — | **1.55s** | **19x** |128+
| mandel_term (terminal art) | 0.05s | 0.05s | **~0s** | **50x+** |99129
100130
## Project Structure101131
102132
```103133
spinel/104134
├── src/105-
│ ├── main.c # CLI, file reading, Prism parsing106-
│ ├── codegen.h # Type system, class/method/module info structs107-
│ └── codegen.c # Multi-pass code generator (~2000 lines)135+
│ ├── main.c # CLI, file reading, Prism parsing136+
│ ├── codegen.h # Type system, class/method/module info structs137+
│ └── codegen.c # Multi-pass code generator (~5000 lines)138+
├── examples/139+
│ ├── bm_so_mandelbrot.rb # Mandelbrot set (while loops, bitwise)140+
│ ├── bm_ao_render.rb # AO raytracer (6 classes, modules)141+
│ ├── bm_so_lists.rb # Array operations (push/pop/shift)142+
│ ├── bm_fib.rb # Recursive fibonacci143+
│ ├── bm_app_lc_fizzbuzz.rb # Lambda calculus FizzBuzz (1201 closures)144+
│ ├── bm_mandel_term.rb # Terminal Mandelbrot (cross-function calls)145+
│ ├── bm_yield.rb # yield/blocks (iterators, each/map/select)146+
│ ├── bm_case.rb # case/when, unless, next, default args147+
│ └── bm_inherit.rb # Inheritance, super108148
├── prototype/109-
│ └── tools/ # Step 0 prototype (RBS extraction, LumiTrace, etc.)110-
├── bm_so_mandelbrot.rb # Benchmark: Mandelbrot set renderer111-
├── bm_ao_render.rb # Benchmark: Ambient occlusion raytracer149+
│ └── tools/ # Step 0 prototype (RBS extraction, LumiTrace, etc.)112150
├── Makefile113-
├── PLAN.md # Implementation roadmap151+
├── PLAN.md # Implementation roadmap114152
└── ruby_aot_compiler_design.md # Detailed design document115153
```116154