Commit 489bc337

489bc3376691Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified

Description

Add built-in Array support, compile bm_so_lists.rb

New sp_IntArray runtime with deque-style O(1) shift:

  • from_range, dup, push, shift, pop, empty?, reverse!, length, [], !=
  • start-offset design avoids O(n) memmove on shift

Also adds: SPINEL_TYPE_ARRAY, not/! operator, p builtin, implicit return propagation through if/else branches, re-inference pass for function return type propagation.

Performance (NUM=300, SIZE=10000): CRuby: 0.44s mruby interpreter: 2.01s Spinel AOT: 0.02s (22x faster than CRuby)

All three benchmarks pass: mandelbrot: 0.02s (57x vs CRuby) ao_render: 0.06s (59x vs CRuby) so_lists: 0.02s (22x vs CRuby)

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

Details

Commit
489bc3376691
Parent
be870dcfa82e

bm_so_lists.rbaddedView file

1+#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
2+
3+NUM = 300
4+SIZE = 10000
5+
6+def test_lists()
7+ # create a list of integers (Li1) from 1 to SIZE
8+ li1 = (1..SIZE).to_a
9+ # copy the list to li2 (not by individual items)
10+ li2 = li1.dup
11+ # remove each individual item from left side of li2 and
12+ # append to right side of li3 (preserving order)
13+ li3 = Array.new
14+ while (not li2.empty?)
15+ li3.push(li2.shift)
16+ end
17+ # li2 must now be empty
18+ # remove each individual item from right side of li3 and
19+ # append to right side of li2 (reversing list)
20+ while (not li3.empty?)
21+ li2.push(li3.pop)
22+ end
23+ # li3 must now be empty
24+ # reverse li1 in place
25+ li1.reverse!
26+ # check that first item is now SIZE
27+ if li1[0] != SIZE then
28+ p "not SIZE"
29+ 0
30+ else
31+ # compare li1 and li2 for equality
32+ if li1 != li2 then
33+ return(0)
34+ else
35+ # return the length of the list
36+ li1.length
37+ end
38+ end
39+end
40+
41+i = 0
42+while i<NUM
43+ i += 1
44+ result = test_lists()
45+end
46+
47+result