From e0edcccd4cdb6925e8d96fee9a6762aae8a2b25c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Sat, 4 May 2013 03:50:19 +0100 Subject: [PATCH] Define custom symbol object in prelude instead of plain objects --- src/compiler.lisp | 15 ++++++--------- src/prelude.js | 6 ++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/compiler.lisp b/src/compiler.lisp index c61e931..7d92b9e 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -574,13 +574,13 @@ #+common-lisp (let ((package (symbol-package symbol))) (if (eq package (find-package "KEYWORD")) - (code "{name: " (dump-string (symbol-name symbol)) - ", 'package': " (dump-string (package-name package)) "}") - (code "{name: " (dump-string (symbol-name symbol)) "}"))) + (code "(new Symbol(" (dump-string (symbol-name symbol)) ", " + (dump-string (package-name package)) "))") + (code "(new Symbol(" (dump-string (symbol-name symbol)) "))"))) #+jscl (let ((package (symbol-package symbol))) (if (null package) - (code "{name: " (dump-symbol (symbol-name symbol)) "}") + (code "(new Symbol(" (dump-symbol (symbol-name symbol)) "))") (ls-compile `(intern ,(symbol-name symbol) ,(package-name package)))))) (defun dump-cons (cons) @@ -1415,13 +1415,10 @@ (code "(x.cdr = " new ", x)"))) (define-builtin symbolp (x) - (js!bool - (js!selfcall - "var tmp = " x ";" *newline* - "return (typeof tmp == 'object' && 'name' in tmp);" *newline*))) + (js!bool (code "(" x " instanceof Symbol)"))) (define-builtin make-symbol (name) - (code "({name: " name "})")) + (code "(new Symbol(" name "))")) (define-builtin symbol-name (x) (code "(" x ").name")) diff --git a/src/prelude.js b/src/prelude.js index e49b781..6f5feea 100644 --- a/src/prelude.js +++ b/src/prelude.js @@ -62,6 +62,12 @@ function make_lisp_string (string){ function xstring(x){ return x.join(''); } +function Symbol(name, package_name){ + this.name = name; + if (package_name) + this['package'] = package_name; +} + function lisp_to_js (x) { if (typeof x == 'object' && 'length' in x && x.type == 'character') return xstring(x); -- 1.7.10.4