- (code
- ;; Declare variables
- (mapconcat (lambda (arg)
- (let ((var (second (car arg))))
- (code "var " (translate-variable var) "; " *newline*
- (when (third arg)
- (code "var " (translate-variable (third arg))
- " = " (ls-compile nil)
- ";" *newline*)))))
- keyword-arguments)
- ;; Parse keywords
- (flet ((parse-keyword (keyarg)
- ;; ((keyword-name var) init-form)
- (code "for (i=" (+ n-required-arguments n-optional-arguments)
- "; i<nargs; i+=2){" *newline*
- (code
- "if (arguments[i+2] === " (ls-compile (caar keyarg)) "){" *newline*
- (code (translate-variable (cadr (car keyarg)))
- " = arguments[i+3];"
- *newline*
- (let ((svar (third keyarg)))
- (when svar
- (code (translate-variable svar) " = " (ls-compile t) ";" *newline*)))
- "break;" *newline*)
- "}" *newline*)
- "}" *newline*
- ;; Default value
- "if (i == nargs){" *newline*
- (code (translate-variable (cadr (car keyarg))) " = " (ls-compile (cadr keyarg)) ";" *newline*)
- "}" *newline*)))
- (when keyword-arguments
- (code "var i;" *newline*
- (mapconcat #'parse-keyword keyword-arguments))))
- ;; Check for unknown keywords
- (when keyword-arguments
- (code "var start = " (+ n-required-arguments n-optional-arguments) ";" *newline*
- "if ((nargs - start) % 2 == 1){" *newline*
- (code "throw 'Odd number of keyword arguments';" *newline*)
- "}" *newline*
- "for (i = start; i<nargs; i+=2){" *newline*
- (code "if ("
- (join (mapcar (lambda (x)
- (concat "arguments[i+2] !== " (ls-compile (caar x))))
- keyword-arguments)
- " && ")
- ")" *newline*
- (code
- "throw 'Unknown keyword argument ' + xstring(arguments[i+2].name);" *newline*))
- "}" *newline*)))))
+ `(code
+ ;; Declare variables
+ ,@(mapcar (lambda (arg)
+ (let ((var (second (car arg))))
+ `(code "var " ,(translate-variable var) "; "
+ ,(when (third arg)
+ `(code "var " ,(translate-variable (third arg))
+ " = " ,(ls-compile nil)
+ ";" )))))
+ keyword-arguments)
+ ;; Parse keywords
+ ,(flet ((parse-keyword (keyarg)
+ ;; ((keyword-name var) init-form)
+ `(code "for (i=" ,(+ n-required-arguments n-optional-arguments)
+ "; i<nargs; i+=2){"
+ (code
+ "if (arguments[i+2] === " ,(ls-compile (caar keyarg)) "){"
+ (code ,(translate-variable (cadr (car keyarg)))
+ " = arguments[i+3];"
+
+ ,(let ((svar (third keyarg)))
+ (when svar
+ `(code ,(translate-variable svar) " = " ,(ls-compile t) ";" )))
+ "break;" )
+ "}" )
+ "}"
+ ;; Default value
+ "if (i == nargs){"
+ (code ,(translate-variable (cadr (car keyarg)))
+ " = "
+ ,(ls-compile (cadr keyarg))
+ ";" )
+ "}" )))
+ (when keyword-arguments
+ `(code "var i;"
+ ,@(mapcar #'parse-keyword keyword-arguments))))
+ ;; Check for unknown keywords
+ ,(when keyword-arguments
+ `(code "var start = " ,(+ n-required-arguments n-optional-arguments) ";"
+ "if ((nargs - start) % 2 == 1){"
+ (code "throw 'Odd number of keyword arguments';" )
+ "}"
+ "for (i = start; i<nargs; i+=2){"
+ (code "if ("
+ ,(interleave (mapcar (lambda (x)
+ `(code "arguments[i+2] !== " ,(ls-compile (caar x))))
+ keyword-arguments)
+ " && ")
+ ")"
+ (code
+ "throw 'Unknown keyword argument ' + xstring(arguments[i+2].name);" ))
+ "}" )))))