From: David Vázquez Date: Sat, 4 May 2013 02:50:19 +0000 (+0100) Subject: Define custom symbol object in prelude instead of plain objects X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=e0edcccd4cdb6925e8d96fee9a6762aae8a2b25c;p=jscl.git Define custom symbol object in prelude instead of plain objects --- 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);