open-goal / jak-project

Reviving the language that brought us the Jak & Daxter Series
https://opengoal.dev
ISC License
2.74k stars 165 forks source link

[goal] Support loop unrolling with :unroll factor #3449

Open Brent-Hickey opened 3 months ago

Brent-Hickey commented 3 months ago

Not sure if this will actually be useful but thought it'd be cool to support

Supports optional loop unrolling with :unroll factor Supports (_ x) syntax to unroll without binding and incrementing a variable when fully unrolled. Otherwise uses gensym var to iterate.

Could add to countdown as well

Examples:

 (dotimes (_ 4) :unroll 4
    (print "hi")
  )

(begin (print "hi") (print "hi") (print "hi") (print "hi"))

(unchanged)

(dotimes (i 4)
    (format #t "i: ~D~%" i)
  )

((lambda :immediate #t (i) (while (< i 4)
                             :label #f
                             (block continue (format #t "i: ~D~%" i) (1+! i))
                             )
         )
 0
 )
(dotimes (_ 4) :unroll 2
    (print "hi")
  )

((lambda :immediate
   #t
   (gensym20077)
   (while (< gensym20077 4)
     :label #f
     (block continue (print "hi") (1+! gensym20077) (print "hi") (1+! gensym20077))
     )
   )
 0
 )
(dotimes (i 4) :unroll 4
    (format #t "i: ~D~%" i)
  )

((lambda :immediate
   #t
   (i)
   (format #t "i: ~D~%" i)
   (1+! i)
   (format #t "i: ~D~%" i)
   (1+! i)
   (format #t "i: ~D~%" i)
   (1+! i)
   (format #t "i: ~D~%" i)
   (1+! i)
   )
 0
 )