summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Price <ianprice90@googlemail.com>2017-08-27 22:23:39 +0100
committerIan Price <ianprice90@googlemail.com>2017-08-27 22:23:39 +0100
commit062e413cda68b7c8fdb7112c189e3e95ec7bd2b5 (patch)
tree2a49bdb02ea8974f34ea6c8dfdb0d81495b15a2a
parent4ef95dd74cc98d5accc3359cf22e0cae0037e367 (diff)
downloadguile-062e413cda68b7c8fdb7112c189e3e95ec7bd2b5.tar.gz
Keywords cannot be both keyword and optional
* module/language/js-il/compile-javascript.scm (compile-jump-table, bind-opt-kw-args): Keywords should not be parsed as optional arguments when both are present.
-rw-r--r--module/language/js-il/compile-javascript.scm48
1 files changed, 46 insertions, 2 deletions
diff --git a/module/language/js-il/compile-javascript.scm b/module/language/js-il/compile-javascript.scm
index 5967fb41c..6fff2d280 100644
--- a/module/language/js-il/compile-javascript.scm
+++ b/module/language/js-il/compile-javascript.scm
@@ -131,6 +131,51 @@
kws
ids))
+(define (bind-opt-kw-args opts kws ids num-drop)
+ ;; FIXME: what we really need is a rewrite of all the complex argument
+ ;; handling , not another special case.
+ ;; NB: our generated IDs will not clash since they are not prefixed
+ ;; with k_ or v_
+ (define skip? (make-id "skip"))
+ (define skip-idx (make-id "skip_idx"))
+ (define (bind-opt-args opts num-drop)
+ (map (lambda (opt idx)
+ (make-var (rename-id opt)
+ (let ((arg (make-refine (make-id "arguments")
+ (make-const (+ num-drop idx)))))
+ (make-ternary (make-binop 'or
+ skip?
+ (make-binop '===
+ (make-prefix 'typeof arg)
+ (make-id "undefined")))
+ (make-refine *scheme* (make-const "UNDEFINED"))
+ (make-ternary (make-binop 'instanceof
+ arg
+ (make-refine *scheme* (make-const "Keyword")))
+ (make-binop 'begin
+ (make-assign "skip" (compile-const #t))
+ (make-refine *scheme* (make-const "UNDEFINED")))
+ (make-binop 'begin
+ (make-assign "skip_idx" (make-binop '+ skip-idx (make-const 1)))
+ arg))))))
+ opts
+ (iota (length opts))))
+ (define (bind-kw-args kws ids)
+ (define lookup (make-refine *utils* (make-const "keyword_ref")))
+ (map (lambda (kw id)
+ (make-var (rename-id id)
+ (make-call lookup
+ (list (compile-const kw)
+ (make-id "arguments")
+ skip-idx
+ (make-refine *scheme* (make-const "UNDEFINED"))))))
+ kws
+ ids))
+ (append (list (make-var "skip" (compile-const #f))
+ (make-var "skip_idx" (compile-const num-drop)))
+ (bind-opt-args opts num-drop)
+ (bind-kw-args kws ids)))
+
(define (compile-exp exp)
;; TODO: handle ids for js
@@ -284,8 +329,7 @@
(map compile-id opts)))))))
(($ il:params self req opts #f ((kws names ids) ...) _)
(append
- (bind-opt-args opts (+ offset (length req)))
- (bind-kw-args kws names (+ offset (length req)))
+ (bind-opt-kw-args opts kws names (+ offset (length req)))
(list
(make-return
(make-call (compile-id k)