Commit | Line | Data |
---|---|---|
06babcf5 | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
4a987e2b | 2 | ;;; ParenScript namespace system |
06babcf5 VS |
3 | |
4 | (in-package :parenscript) | |
5 | ||
4a987e2b VS |
6 | (defun lisp-symbol-to-ps-identifier (symbol context) |
7 | (case context | |
8 | (:special-form (symbol-name symbol)) | |
9 | (:macro symbol) | |
10 | (otherwise (symbol-name symbol)))) | |
06babcf5 | 11 | |
4a987e2b VS |
12 | ;;; Symbol obfuscation |
13 | (defvar *obfuscate-identifiers* nil) | |
06babcf5 VS |
14 | |
15 | (defparameter *obfuscation-table* (make-hash-table)) | |
16 | ||
17 | (defun obfuscated-symbol (symbol) | |
18 | (or (gethash symbol *obfuscation-table*) | |
19 | (setf (gethash symbol *obfuscation-table*) (string (gensym))))) | |
20 | ||
21 | ;;; Interface for printing identifiers | |
22 | ||
23 | (defvar *package-prefix-style* :prefix | |
24 | "Determines how package symbols are serialized to JavaScript identifiers. NIL for | |
25 | no prefixes. :prefix to prefix variables with something like packagename_identifier.") | |
26 | ||
4a987e2b VS |
27 | (defvar *package-prefix-table* (make-hash-table)) |
28 | ||
29 | (defmacro ps-package-prefix (package) | |
30 | "Place for storing a string to be prefixed to any symbols in the | |
31 | designated package when translating ParenScript code." | |
32 | `(gethash (find-package ,package) *package-prefix-table*)) | |
06babcf5 | 33 | |
4a987e2b VS |
34 | (defun js-translate-symbol (symbol) |
35 | (cond (*obfuscate-identifiers* (obfuscated-symbol symbol)) | |
36 | ((and (eql *package-prefix-style* :prefix) (ps-package-prefix (symbol-package symbol))) | |
37 | (format nil "~A~A" (ps-package-prefix (symbol-package symbol)) (symbol-to-js symbol))) | |
38 | (t (symbol-to-js symbol)))) | |
06babcf5 | 39 |