[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 13/99: Mangle js identifiers
From: |
Christopher Allan Webber |
Subject: |
[Guile-commits] 13/99: Mangle js identifiers |
Date: |
Sun, 10 Oct 2021 21:50:43 -0400 (EDT) |
cwebber pushed a commit to branch compile-to-js-merge
in repository guile.
commit 41023d5b4cd322d51319ba8e9bbd1a7f3cfb7091
Author: Ian Price <ianprice90@googlemail.com>
AuthorDate: Mon Jun 8 00:17:22 2015 +0100
Mangle js identifiers
---
module/language/js-il/compile-javascript.scm | 37 ++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/module/language/js-il/compile-javascript.scm
b/module/language/js-il/compile-javascript.scm
index 3d50bcc..19e8eb7 100644
--- a/module/language/js-il/compile-javascript.scm
+++ b/module/language/js-il/compile-javascript.scm
@@ -14,8 +14,41 @@
(define (name->id name)
(make-id (rename name)))
-(define (rename name)
- (format #f "kont_~a" name))
+(define (rename id)
+ (cond ((and (integer? id) (>= id 0))
+ (format #f "k_~a " id))
+ ((symbol? id)
+ (js-id (symbol->string id)))
+ ((string? id)
+ (js-id id))
+ (else
+ (throw 'bad-id id))))
+
+(define (js-id name)
+ (call-with-output-string
+ (lambda (port)
+ (display "k_" port)
+ (string-for-each
+ (lambda (c)
+ (if (or (and (char<=? #\a c) (char<=? c #\z))
+ (and (char<=? #\A c) (char<=? c #\Z))
+ (and (char<=? #\0 c) (char<=? c #\9)))
+ (display c port)
+ (case c
+ ((#\-) (display "_h" port))
+ ((#\_) (display "_u" port))
+ ((#\?) (display "_p" port))
+ ((#\!) (display "_x" port))
+ ((#\<) (display "_l" port))
+ ((#\>) (display "_g" port))
+ ((#\=) (display "_e" port))
+ ((#\*) (display "_s" port))
+ ((#\+) (display "_a" port))
+ ((#\\) (display "_b" port))
+ ((#\/) (display "_f" port))
+ (else
+ (throw 'bad-id-char c)))))
+ name))))
(define (bind-rest-args rest num-drop)
(define (ref i l)
- [Guile-commits] 04/99: fix makefile, (continued)
- [Guile-commits] 04/99: fix makefile, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 05/99: separate js-il functions into actual functions and those for continuations, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 06/99: Get rid of comments and dead branches, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 07/99: Simple inlining of immediate calls, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 08/99: conditional->branch, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 10/99: fix makefile, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 11/99: Compile rest args, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 16/99: Remove superfluous space, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 20/99: Implement keyword argument parsing, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 12/99: Compile string constants, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 13/99: Mangle js identifiers,
Christopher Allan Webber <=
- [Guile-commits] 15/99: Handle case-lambda via a jump table, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 19/99: Simplify output Javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 21/99: Primitives should return Scheme Booleans, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 23/99: Compile cps $prompt form to javascript, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 26/99: abort-to-prompt takes multiple arguments, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 34/99: Change function type representation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 33/99: Change program type representation, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 31/99: Different types for Continuation and Variable identifiers, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 29/99: Use scheme.frame.Prompt objects for prompts on dynstack, Christopher Allan Webber, 2021/10/10
- [Guile-commits] 30/99: Implement fluid primitives, Christopher Allan Webber, 2021/10/10