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:
putcbuiltin (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_valwidens 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=953+
iterations=04+
cr = (c_r * 100).to_i5+
ci = (c_i * 100).to_i6+
zr = zi = 07+
# Avoid sqrt by squaring the threshold: sqrt(x) < 1000 => x < 10000008+
while iterations<limit9+
zr2 = zr*zr10+
zi2 = zi*zi11+
break if zr2+zi2 >= 100000012+
zr, zi = (zr2-zi2)/100+cr, (zr*zi*2)/100+ci13+
iterations+=114+
end15+
return iterations16+
end17+
18+
def mandel_calc(min_r, min_i, max_r, max_i, res)19+
cur_i = min_i20+
while cur_i > max_i21+
putc "|"22+
cur_r = min_r23+
while cur_r < max_r24+
ch = 127 - mandelbrot(cur_r, cur_i)25+
putc ch # Use putc with integer - no string allocation!26+
cur_r += res27+
end28+
putc "|"29+
putc "\n"30+
cur_i -= res31+
end32+
end33+
34+
mandel_calc(-2, 1, 1, -1, 0.04)src/codegen.cmodifiedView file
Loading diff…