Skip to content

Commit

Permalink
Change to split namespace by package
Browse files Browse the repository at this point in the history
Previously, Common Lisp pacage is used only for grouping variables and
functions. Then, when they are output as JavaScript code, the
namespace is not split.

This commit introduces namespace also in JavaScript code by using
closure. But some (dirty) hacks were required.

First, to refer un-exported symbols, each package has a "_internal"
member, then internal symbols can be referred as
"<package>._internal.<symbol>". In addition, to identify un-imported
symbol, ps:symbol-to-js-string is overwritten.

Second, to send type-specifier to other package, quote is removed if
it is attached to a type-specifier symbol. In Common Lisp,
type-specifier can be specified using symbol, but it is converted to
just a string by Parenscript. In other words, the information of
package is lost. So in other package, we can no longer extract the
type. To achieve this, "quote" in Parenscript is overwritten.

Note: Variable, function and type-specfier are in a same namespace in
a package unlike Common Lisp namespace.

Note: Parenscript has a namespace system. It splits namespaces by
adding prefix to all symbols in the package. But I wanted to achieve
more Common Lisp like one that has symbol importing and exporting.
  • Loading branch information
eshamster committed Dec 11, 2017
1 parent 5351dfd commit b714695
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 80 deletions.
15 changes: 14 additions & 1 deletion src/base.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
:defmacro.ps
:defmacro.ps+
:enable-ps-experiment-syntax
;; The following used only in ps-experiment.package
:*original-package*
:--))
(in-package :ps-experiment.base)

Expand Down Expand Up @@ -57,8 +59,19 @@
(rest (replace-dot-sep rest)))))
(rec tree)))

;; In ps:ps, the *package* will be binded to "COMMON-LISP-USER" package
;; (to be exact, ps::parenscript-print that called from ps:ps uses
;; with-standard-io-syntax).
;; So *original-package* saves an original package before that. Then
;; it will be used in the ps-experiment.package package.
;;
;; Note: Maybe some refactoring is required to place ps. and fucntions
;; related to this in a same package
(defvar *original-package* nil)

(defmacro ps. (&body body)
`(ps ,@(replace-dot-in-tree body)))
`(let ((*original-package* ,*package*))
(macroexpand '(ps ,@(replace-dot-in-tree body)))))

(defmacro defmacro.ps (name args &body body)
"Note: 2015/12/12
Expand Down
7 changes: 3 additions & 4 deletions src/defines.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
(:export :defvar.ps
:defvar.ps+
:defun.ps
:defun.ps-only
:defun.ps+
:defstruct.ps
:defstruct.ps+)
Expand All @@ -24,6 +23,8 @@
:make-ps-definer
:def-ps-definer
:def-top-level-form.ps
:defun.ps-only
:register-ps-type
:add-unintern-all-ps-symbol-hook))
(in-package :ps-experiment.defines)

Expand All @@ -44,9 +45,6 @@
(mapcan #'make-a-list
(list required optional rest keys aux)))))

(def-ps-definer defun.ps-only (name args &body body) ()
`(defun ,name ,args ,@body))

(def-ps-definer defun.ps (name args &body body)
(:before `(defun ,name ,args
(declare ,(cons 'ignore
Expand Down Expand Up @@ -184,6 +182,7 @@ value = ({(slot-name slot-init-form}*)")
`(setf (@ this ,(car slot)) ,(cadr slot)))
slots)
this)
(register-ps-type ',name)
(defun-wrapper ,ps-only-p ,(symbolicate 'make- name) (&key ,@slots)
(let ((result (new (,name))))
,@(mapcar (lambda (elem)
Expand Down

0 comments on commit b714695

Please sign in to comment.