[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)
- [Guile-commits] 71/99: modules should be passed current continuation, (continued)
- [Guile-commits] 71/99: modules should be passed current continuation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 79/99: Implement list builtins, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 80/99: *features* is an empty list, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 84/99: Add assignment js-type to (language javascript), Christopher Allan Webber, 2021/10/10
- [Guile-commits] 87/99: Create stub module forms for dependecies, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 97/99: Switch use of $closure to $const-fun, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 22/99: Add more Scheme Primitives to runtime.js, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 32/99: Rewrite js-il inliner, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 82/99: pop-fluid uses field of frame not fluid, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 85/99: Handle more JavaScript binary operators, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 86/99: Keywords cannot be both keyword and optional,
Christopher Allan Webber <=
- [Guile-commits] 91/99: Update Copyright Headers, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 94/99: Add compiler-chooser for CPS spec, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 96/99: Fix cps's choose-compiler to be able to compile javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 98/99: Merge branch 'main' into compile-to-js-merge, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 78/99: Implement Hook Builtins, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 81/99: Argument to make-fluid is optional, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 83/99: Implement variable-bound? builtin, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 88/99: read argument to --depends switch, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 89/99: extra-dependencies go before boot-dependencies, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 90/99: Mention all arguments to guild jslink in --help, Christopher Allan Webber, 2021/10/10