Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mtg@gnu.org>2017-12-12 00:46:18 -0500
committerMike Gerwitz <mtg@gnu.org>2017-12-12 00:46:18 -0500
commit462d99fb991aca1ae471bd4ed2d9013e6ed63a89 (patch)
tree1ec619a4f56ce0aa98eea803b4a74d7c530390c8
parent1d6756a7098e66d2c05020aaf4996215994a5fb7 (diff)
downloadulambda-462d99fb991aca1ae471bd4ed2d9013e6ed63a89.tar.gz
ulambda-462d99fb991aca1ae471bd4ed2d9013e6ed63a89.tar.bz2
ulambda-462d99fb991aca1ae471bd4ed2d9013e6ed63a89.zip
rebirth: Add define/define-macro rest support
That is: `(define (foo bar . rest))'. * build-aux/bootstrap/rebirth.scm (params->es): Add rest support.
-rw-r--r--build-aux/bootstrap/rebirth.scm28
1 files changed, 23 insertions, 5 deletions
diff --git a/build-aux/bootstrap/rebirth.scm b/build-aux/bootstrap/rebirth.scm
index bb93057..b0c2839 100644
--- a/build-aux/bootstrap/rebirth.scm
+++ b/build-aux/bootstrap/rebirth.scm
@@ -718,12 +718,30 @@
;; Compile parameter list.
;;
-;; This simply takes the value of the symbol and outputs it (formatted),
-;; delimited by commas.
+;; This takes the value of the symbol and outputs it (formatted), delimited
+;; by commas.
+;;
+;; Since we do not support actual pairs (yet), the "." syntax that normally
+;; denotes the cdr is retained and presents itself here. The form "(arg1,
+;; arg2 . rest)" creates a list `rest' containing all remaining arguments
+;; after that point. Conveniently, ECMAScript Harmony supports this
+;; natively with the "..." syntax.
(define (params->es params)
- (join ", " (map (lambda (t)
- (tname->id (token-value t)))
- params)))
+ (define (%param-conv params)
+ (let* ((param (car params))
+ (name (token-value param))
+ (id (tname->id name))
+ (rest (cdr params)))
+ (if (string=? name ".")
+ (list (string-append
+ "..." (car (%param-conv rest))))
+ (if (pair? rest)
+ (cons id (%param-conv rest))
+ (list id)))))
+
+ (if (pair? params)
+ (join "," (%param-conv params))
+ ""))
;; Compile body s-expressions into ECMAScript