From 54de4d4abbeb7f99e5f5702ad93e815cae7a0b3b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Thu, 25 Apr 2013 18:59:44 +0100 Subject: [PATCH] Rename project to JSCL --- README.org | 20 +++++----- ecmalisp.html | 110 ----------------------------------------------------- ecmalisp.lisp | 76 ------------------------------------ jscl.html | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++ jscl.lisp | 76 ++++++++++++++++++++++++++++++++++++ src/boot.lisp | 10 ++--- src/compiler.lisp | 12 +++--- src/prelude.js | 4 +- src/read.lisp | 4 +- src/utils.lisp | 6 +-- 10 files changed, 213 insertions(+), 215 deletions(-) delete mode 100644 ecmalisp.html delete mode 100644 ecmalisp.lisp create mode 100644 jscl.html create mode 100644 jscl.lisp diff --git a/README.org b/README.org index 25a519b..d6b5ebd 100644 --- a/README.org +++ b/README.org @@ -1,26 +1,26 @@ -* Ecmalisp +* JSCL - Ecmalisp is a Common Lisp to Javascript compiler, which is - bootstrapped from Common Lisp and executed from the browser. + JSCL is a Common Lisp to Javascript compiler, which is bootstrapped + from Common Lisp and executed from the browser. ** Getting started -You can try a demo [[http://davazp.net/ecmalisp/ecmalisp.html][here]]. But if you want to hack ecmalisp, you will -have to download the repository +You can try a demo [[http://davazp.net/jscl/jscl.html][here]]. But if you want to hack JSCL, you will have +to download the repository -=git clone git@github.com:davazp/ecmalisp.git= +=git clone git@github.com:davazp/jscl.git= -/load/ ecmalisp.lisp in your Lisp, and call the bootstrap function to +/load/ jscl.lisp in your Lisp, and call the bootstrap function to compile the implementation itself: =(bootstrap)= -It will generate a ecmalisp.js file in the top of the source tree. Now -you can open ecmalisp.html in your browser and use it. +It will generate a jscl.js file in the top of the source tree. Now you +can open JSCL.html in your browser and use it. ** Status -Ecmalisp is and will be a subset of Common Lisp. Of course it is far +JSCL is and will be a subset of Common Lisp. Of course it is far from complete, but it supports partially most common special operators, functions and macros. In particular: diff --git a/ecmalisp.html b/ecmalisp.html deleted file mode 100644 index ee15a2a..0000000 --- a/ecmalisp.html +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - -
- - - - - - diff --git a/ecmalisp.lisp b/ecmalisp.lisp deleted file mode 100644 index 855d813..0000000 --- a/ecmalisp.lisp +++ /dev/null @@ -1,76 +0,0 @@ -;;; ecmalisp.lisp --- - -;; Copyright (C) 2012, 2013 David Vazquez -;; Copyright (C) 2012 Raimon Grau - -;; This program is free software: you can redistribute it and/or -;; modify it under the terms of the GNU General Public License as -;; published by the Free Software Foundation, either version 3 of the -;; License, or (at your option) any later version. -;; -;; This program is distributed in the hope that it will be useful, but -;; WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;; General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -(defvar *source* - '(("boot" :target) - ("compat" :host) - ("utils" :both) - ("print" :target) - ("read" :both) - ("compiler" :both) - ("toplevel" :target))) - -(defun source-pathname - (filename &key (directory '(:relative "src")) (type nil) (defaults filename)) - (if type - (make-pathname :type type :directory directory :defaults defaults) - (make-pathname :directory directory :defaults defaults))) - -;;; Compile ecmalisp into the host -(with-compilation-unit () - (dolist (input *source*) - (when (member (cadr input) '(:host :both)) - (compile-file (source-pathname (car input)))))) - -;;; Load ecmalisp into the host -(dolist (input *source*) - (when (member (cadr input) '(:host :both)) - (load (source-pathname (car input))))) - -(defun read-whole-file (filename) - (with-open-file (in filename) - (let ((seq (make-array (file-length in) :element-type 'character))) - (read-sequence seq in) - seq))) - -(defun ls-compile-file (filename out &key print) - (let ((*compiling-file* t) - (*compile-print-toplevels* print)) - (let* ((source (read-whole-file filename)) - (in (make-string-stream source))) - (format t "Compiling ~a...~%" filename) - (loop - with eof-mark = (gensym) - for x = (ls-read in nil eof-mark) - until (eq x eof-mark) - for compilation = (ls-compile-toplevel x) - when (plusp (length compilation)) - do (write-string compilation out))))) - -(defun bootstrap () - (setq *environment* (make-lexenv)) - (setq *literal-symbols* nil) - (setq *variable-counter* 0 - *gensym-counter* 0 - *literal-counter* 0 - *block-counter* 0) - (with-open-file (out "ecmalisp.js" :direction :output :if-exists :supersede) - (write-string (read-whole-file (source-pathname "prelude.js")) out) - (dolist (input *source*) - (when (member (cadr input) '(:target :both)) - (ls-compile-file (source-pathname (car input) :type "lisp") out))))) diff --git a/jscl.html b/jscl.html new file mode 100644 index 0000000..656af67 --- /dev/null +++ b/jscl.html @@ -0,0 +1,110 @@ + + + + + + + +
+ + + + + + diff --git a/jscl.lisp b/jscl.lisp new file mode 100644 index 0000000..5f1aec2 --- /dev/null +++ b/jscl.lisp @@ -0,0 +1,76 @@ +;;; jscl.lisp --- + +;; Copyright (C) 2012, 2013 David Vazquez +;; Copyright (C) 2012 Raimon Grau + +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +(defvar *source* + '(("boot" :target) + ("compat" :host) + ("utils" :both) + ("print" :target) + ("read" :both) + ("compiler" :both) + ("toplevel" :target))) + +(defun source-pathname + (filename &key (directory '(:relative "src")) (type nil) (defaults filename)) + (if type + (make-pathname :type type :directory directory :defaults defaults) + (make-pathname :directory directory :defaults defaults))) + +;;; Compile jscl into the host +(with-compilation-unit () + (dolist (input *source*) + (when (member (cadr input) '(:host :both)) + (compile-file (source-pathname (car input)))))) + +;;; Load jscl into the host +(dolist (input *source*) + (when (member (cadr input) '(:host :both)) + (load (source-pathname (car input))))) + +(defun read-whole-file (filename) + (with-open-file (in filename) + (let ((seq (make-array (file-length in) :element-type 'character))) + (read-sequence seq in) + seq))) + +(defun ls-compile-file (filename out &key print) + (let ((*compiling-file* t) + (*compile-print-toplevels* print)) + (let* ((source (read-whole-file filename)) + (in (make-string-stream source))) + (format t "Compiling ~a...~%" filename) + (loop + with eof-mark = (gensym) + for x = (ls-read in nil eof-mark) + until (eq x eof-mark) + for compilation = (ls-compile-toplevel x) + when (plusp (length compilation)) + do (write-string compilation out))))) + +(defun bootstrap () + (setq *environment* (make-lexenv)) + (setq *literal-symbols* nil) + (setq *variable-counter* 0 + *gensym-counter* 0 + *literal-counter* 0 + *block-counter* 0) + (with-open-file (out "jscl.js" :direction :output :if-exists :supersede) + (write-string (read-whole-file (source-pathname "prelude.js")) out) + (dolist (input *source*) + (when (member (cadr input) '(:target :both)) + (ls-compile-file (source-pathname (car input) :type "lisp") out))))) diff --git a/src/boot.lisp b/src/boot.lisp index 2dca3a8..d57fa0b 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -16,11 +16,11 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . -;;; This code is executed when ecmalisp compiles this file -;;; itself. The compiler provides compilation of some special forms, -;;; as well as funcalls and macroexpansion, but no functions. So, we -;;; define the Lisp world from scratch. This code has to define enough -;;; language to the compiler to be able to run. +;;; This code is executed when JSCL compiles this file itself. The +;;; compiler provides compilation of some special forms, as well as +;;; funcalls and macroexpansion, but no functions. So, we define the +;;; Lisp world from scratch. This code has to define enough language +;;; to the compiler to be able to run. (eval-when-compile (%compile-defmacro 'defmacro diff --git a/src/compiler.lisp b/src/compiler.lisp index 5cabe76..171e0c8 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -50,7 +50,7 @@ ;;; of this function are available, because the Ecmalisp version is ;;; very slow and bootstraping was annoying. -#+ecmalisp +#+jscl (defun indent (&rest string) (let ((input (apply #'code string))) (let ((output "") @@ -238,7 +238,7 @@ (let ((b (global-binding name 'variable 'variable))) (push 'constant (binding-declarations b))))))) -#+ecmalisp +#+jscl (fset 'proclaim #'!proclaim) (defun %define-symbol-macro (name expansion) @@ -246,7 +246,7 @@ (push-to-lexenv b *environment* 'variable) name)) -#+ecmalisp +#+jscl (defmacro define-symbol-macro (name expansion) `(%define-symbol-macro ',name ',expansion)) @@ -547,7 +547,7 @@ (code "{name: \"" (escape-string (symbol-name sexp)) "\", 'package': '" (package-name package) "'}") (code "{name: \"" (escape-string (symbol-name sexp)) "\"}"))) - #+ecmalisp + #+jscl (let ((package (symbol-package sexp))) (if (null package) (code "{name: \"" (escape-string (symbol-name sexp)) "\"}") @@ -1590,7 +1590,7 @@ ;; us replace the list representation version of the ;; function with the compiled one. ;; - #+ecmalisp (setf (binding-value macro-binding) compiled) + #+jscl (setf (binding-value macro-binding) compiled) #+common-lisp (setf (gethash macro-binding *macroexpander-cache*) compiled) (setq expander compiled)))) (values (apply expander (cdr form)) t)) @@ -1609,7 +1609,7 @@ ((translate-function function) (concat (translate-function function) arglist)) ((and (symbolp function) - #+ecmalisp (eq (symbol-package function) (find-package "COMMON-LISP")) + #+jscl (eq (symbol-package function) (find-package "COMMON-LISP")) #+common-lisp t) (code (ls-compile `',function) ".fvalue" arglist)) (t diff --git a/src/prelude.js b/src/prelude.js index 38a13d7..9a8d363 100644 --- a/src/prelude.js +++ b/src/prelude.js @@ -1,5 +1,5 @@ -// This file is prepended to the result of compile ecmalisp.lisp, and -// contain runtime code that ecmalisp assumes to exist. +// This file is prepended to the result of compile jscl.lisp, and +// contain runtime code that jscl assumes to exist. var window = this; var nil; diff --git a/src/read.lisp b/src/read.lisp index d642be0..d513ef3 100644 --- a/src/read.lisp +++ b/src/read.lisp @@ -119,7 +119,7 @@ ((string= feature "common-lisp") (ls-read-1 stream) ;ignore (ls-read-1 stream)) - ((string= feature "ecmalisp") + ((string= feature "jscl") (ls-read-1 stream)) (t (error "Unknown reader form."))))))) @@ -270,7 +270,7 @@ (values (* sign value) index) (values nil index))))) -#+ecmalisp +#+jscl (defun parse-integer (string &key junk-allowed) (multiple-value-bind (num index) (!parse-integer string junk-allowed) diff --git a/src/utils.lisp b/src/utils.lisp index d73a15d..3cf0103 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -87,7 +87,5 @@ digits))))) (defun float-to-string (x) - #+ecmalisp - (float-to-string x) - #+common-lisp - (format nil "~f" x)) + #+jscl (float-to-string x) + #+common-lisp (format nil "~f" x)) -- 1.7.10.4