     return    @compile_array(o) unless o.index
     idx:      del o, 'index'
     step:     del o, 'step'
-    vars:     "$idx = $@from_var"
+    vars:     "$idx = ${@from_var.compile(o)}"
     step:     if step then step.compile(o) else '1'
     equals:   if @exclusive then '' else '='
-    intro:    "($@from_var <= $@to_var ? $idx"
-    compare:  "$intro <$equals $@to_var : $idx >$equals $@to_var)"
-    incr:     "$intro += $step : $idx -= $step)"
-    "$vars; $compare; $incr"
-
-  # When used as a value, expand the range into the equivalent array. In the
-  # future, the code this generates should probably be cleaned up by handwriting
-  # it instead of wrapping nodes.
+    op:       if starts(step, '-') then ">$equals" else "<$equals"
+    "$vars; ${idx} $op ${@to_var.compile(o)}; $idx += $step"
+
+  # When used as a value, expand the range into the equivalent array.
   compile_array: (o) ->
-    name: o.scope.free_variable()
-    body: Expressions.wrap([literal(name)])
-    arr:  Expressions.wrap([new ForNode(body, {source: (new ValueNode(this))}, literal(name))])
-    (new ParentheticalNode(new CallNode(new CodeNode([], arr.make_return())))).compile(o)
+    idt:    @idt 1
+    vars:   @compile_variables(merge(o, {indent: idt}))
+    equals: if @exclusive then '' else '='
+    from:   @from_var.compile o
+    to:     @to_var.compile o
+    clause: "$from <= $to ?"
+    pre:    "\n${idt}a = [];${vars}"
+    body:   "var i = $from; ($clause i <$equals $to : i >$equals $to); ($clause i += 1 : i -= 1)"
+    post:   "a.push(i);\n${idt}return a;\n$o.indent"
+    "(function(){${pre}for ($body) $post}).call(this)"
 
 #### SliceNode
 

  # If the code generation wishes to use the result of a complex expression
  # in multiple places, ensure that the expression is only ever evaluated once,
  # by assigning it to a temporary variable.
  compile_reference: (o) ->
    reference: literal o.scope.free_variable()
    compiled:  new AssignNode reference, this
    [compiled, reference]

  # because other nodes like to check the existence of their variables as well.
  # Be careful not to double-evaluate anything.
  @compile_test: (o, variable) ->
    [first, second]: variable.compile_reference o, true
    "(typeof ${first.compile(o)} !== \"undefined\" && ${second.compile(o)} !== null)"

#### ParentheticalNode

