(defn emit-arguments-to-array
"Emit code that copies function arguments into an array starting at an index.
Returns name of var holding the array."
[startslice]
(assert (and (>= startslice 0) (integer? startslice)))
(let [mname (munge (gensym))
i (str mname "__i")
a (str mname "__a")]
(emitln "var " i " = 0, "
a " = new Array(arguments.length - " startslice ");")
(emitln "while (" i " < " a ".length) {"
a "[" i "] = arguments[" i " + " startslice "]; ++" i ";}")
a))