3 ;; Copyright (C) 2012, 2013 David Vazquez
4 ;; Copyright (C) 2012 Raimon Grau
6 ;; This program is free software: you can redistribute it and/or
7 ;; modify it under the terms of the GNU General Public License as
8 ;; published by the Free Software Foundation, either version 3 of the
9 ;; License, or (at your option) any later version.
11 ;; This program is distributed in the hope that it will be useful, but
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;; General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 (js-eval (ls-compile-toplevel x t)))
34 (defun eval-interactive (x)
36 (let ((results (multiple-value-list (eval x))))
48 (export '(&body &key &optional &rest * ** *** *gensym-counter* *package* + ++
49 +++ - / // /// 1+ 1- < <= = = > >= and append apply aref
50 arrayp assoc atom block boundp butlast caar cadddr caddr
51 cadr car car case catch cdar cdddr cddr cdr cdr char
52 char-code char= code-char cond cons consp constantly
53 copy-list decf declaim defconstant define-setf-expander
54 define-symbol-macro defmacro defparameter defun defvar
55 digit-char digit-char-p disassemble do do* documentation
56 dolist dotimes ecase eq eql equal error eval every export expt
57 fdefinition find-package find-symbol first flet fourth fset
58 funcall function functionp gensym get-setf-expansion
59 get-universal-time go identity if in-package incf integerp
60 intern keywordp labels lambda last length let let* list
61 list* list-all-packages listp loop make-array make-package
62 make-symbol mapcar member minusp mod multiple-value-bind
63 multiple-value-call multiple-value-list multiple-value-prog1
64 nconc nil not nreconc nth nthcdr null numberp or
65 package-name package-use-list packagep parse-integer plusp
66 prin1-to-string print proclaim prog1 prog2 progn psetq push
67 quote remove remove-if remove-if-not return return-from
68 revappend reverse rplaca rplacd second set setf setq some
69 string string-upcase string= stringp subseq symbol-function
70 symbol-name symbol-package symbol-plist symbol-value symbolp
71 t tagbody third throw truncate unless unwind-protect values
72 values-list variable warn when write-line write-string zerop))
74 (setq *package* *user-package*)
77 (%js-vset "lisp" (new))
78 (%js-vset "lisp.read" #'ls-read-from-string)
79 (%js-vset "lisp.print" #'prin1-to-string)
80 (%js-vset "lisp.eval" #'eval)
81 (%js-vset "lisp.compile" (lambda (s) (ls-compile-toplevel s t)))
82 (%js-vset "lisp.evalString" (lambda (str) (eval (ls-read-from-string str))))
83 (%js-vset "lisp.evalInput" (lambda (str) (eval-interactive (ls-read-from-string str))))
84 (%js-vset "lisp.compileString" (lambda (str) (ls-compile-toplevel (ls-read-from-string str) t)))
86 ;; Set the initial global environment to be equal to the host global
87 ;; environment at this point of the compilation.
90 (ls-compile `(setq *environment* ',*environment*))))
96 ,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(cdr s))))
98 (setq *literal-symbols* ',*literal-symbols*)
99 (setq *variable-counter* ,*variable-counter*)
100 (setq *gensym-counter* ,*gensym-counter*)
101 (setq *block-counter* ,*block-counter*)))))
104 (toplevel-compilation
106 `(setq *literal-counter* ,*literal-counter*))))