guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 86/99: Keywords cannot be both keyword and optional


From: Christopher Allan Webber
Subject: [Guile-commits] 86/99: Keywords cannot be both keyword and optional
Date: Sun, 10 Oct 2021 21:51:12 -0400 (EDT)

cwebber pushed a commit to branch compile-to-js-merge
in repository guile.

commit 062e413cda68b7c8fdb7112c189e3e95ec7bd2b5
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Sun Aug 27 22:23:39 2017 +0100

    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.
---
 module/language/js-il/compile-javascript.scm | 48 ++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/module/language/js-il/compile-javascript.scm 
b/module/language/js-il/compile-javascript.scm
index 5967fb4..6fff2d2 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]