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 | 12 | ;;; Symbol obfuscation |
0c542be0 | 13 | (defvar *obfuscation-table* (make-hash-table)) |
06babcf5 | 14 | |
0c542be0 VS |
15 | (defun obfuscate-package (package-designator) |
16 | (setf (gethash (find-package package-designator) *obfuscation-table*) (make-hash-table))) | |
06babcf5 | 17 | |
0c542be0 VS |
18 | (defun unobfuscate-package (package-designator) |
19 | (remhash (find-package package-designator) *obfuscation-table*)) | |
06babcf5 | 20 | |
0c542be0 VS |
21 | (defun maybe-obfuscate-symbol (symbol) |
22 | (let ((obfuscated-symbol-table (gethash (symbol-package symbol) *obfuscation-table*))) | |
23 | (if obfuscated-symbol-table | |
24 | (or (gethash symbol obfuscated-symbol-table) | |
25 | (setf (gethash symbol obfuscated-symbol-table) (ps-gensym "G"))) | |
26 | symbol))) | |
06babcf5 | 27 | |
0c542be0 | 28 | ;;; Interface for printing identifiers |
06babcf5 | 29 | |
4a987e2b VS |
30 | (defvar *package-prefix-table* (make-hash-table)) |
31 | ||
32 | (defmacro ps-package-prefix (package) | |
33 | "Place for storing a string to be prefixed to any symbols in the | |
34 | designated package when translating ParenScript code." | |
35 | `(gethash (find-package ,package) *package-prefix-table*)) | |
06babcf5 | 36 | |
4a987e2b | 37 | (defun js-translate-symbol (symbol) |
0c542be0 VS |
38 | (let ((possibly-obfuscated-symbol (maybe-obfuscate-symbol symbol))) |
39 | (if (ps-package-prefix (symbol-package symbol)) | |
40 | (format nil "~A~A" (ps-package-prefix (symbol-package symbol)) (symbol-to-js possibly-obfuscated-symbol)) | |
41 | (symbol-to-js possibly-obfuscated-symbol)))) |