Commit ed999ebf

ed999ebfda5dMerged

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

Description

Compile bm_mandel_term.rb — putc, chained assignment, cross-function type inference

New features:

  • putc builtin (integer → putchar, string → first char)
  • Chained assignment: zr = zi = 0 (PM_LOCAL_VARIABLE_WRITE_NODE as expr)
  • PM_RETURN_NODE in infer_type (enables return type inference)
  • Operator-write type widening: cur_r += float_val widens int to float
  • Cross-function param inference from call sites in function bodies
  • Function body param→local→return type inference (infer_pass + infer_type)
  • Heuristic: (param * N).to_i pattern → param is Float
  • mrb_value fallback → mrb_int for standalone mode (no mruby dependency)

Note: slight rendering differences from CRuby due to float→int truncation in iterative calculations (known fp precision issue).

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

Details

Commit
ed999ebfda5d
Parent
40ba71269e5a

bm_mandel_term.rbaddedView file

1+def mandelbrot(c_r, c_i)
2+ limit=95
3+ iterations=0
4+ cr = (c_r * 100).to_i
5+ ci = (c_i * 100).to_i
6+ zr = zi = 0
7+ # Avoid sqrt by squaring the threshold: sqrt(x) < 1000 => x < 1000000
8+ while iterations<limit
9+ zr2 = zr*zr
10+ zi2 = zi*zi
11+ break if zr2+zi2 >= 1000000
12+ zr, zi = (zr2-zi2)/100+cr, (zr*zi*2)/100+ci
13+ iterations+=1
14+ end
15+ return iterations
16+end
17+
18+def mandel_calc(min_r, min_i, max_r, max_i, res)
19+ cur_i = min_i
20+ while cur_i > max_i
21+ putc "|"
22+ cur_r = min_r
23+ while cur_r < max_r
24+ ch = 127 - mandelbrot(cur_r, cur_i)
25+ putc ch # Use putc with integer - no string allocation!
26+ cur_r += res
27+ end
28+ putc "|"
29+ putc "\n"
30+ cur_i -= res
31+ end
32+end
33+
34+mandel_calc(-2, 1, 1, -1, 0.04)