Mar
25th
Wed
25th
With the infrastructure to generate machine code comes the possibility of compiling Python into a much more efficient implementation. For example, take the snippet
for i in range(3):
foo(i)
This currently desugars to something like
$x = range(3)
while True:
try:
i = $x.next()
except StopIteration:
break
foo(i)
Once we have a mechanism to know that range() means the range() builtin function, we can turn this into something more akin to
for (i = 0; i
in C, possibly using unboxed types for the math. We can then unroll the loop to yield
foo(0)
foo(1)
foo(2)
