X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fcompiler.lisp;h=22b318f2533f41774938caee3735a206522c1bc1;hb=00ba710e3c68fd667499a602bcead98400f1ac55;hp=39234c1019206d8c54ebdabf5a7d63d90787c46a;hpb=ba609c48b83ab6191a8572f7d0a5bb5122d51731;p=jscl.git diff --git a/src/compiler.lisp b/src/compiler.lisp index 39234c1..22b318f 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -368,8 +368,11 @@ (mapconcat #'parse-keyword keyword-arguments)))) ;; Check for unknown keywords (when keyword-arguments - (code "for (i=" (+ n-required-arguments n-optional-arguments) - "; i "foo's" -;;; "foo" => '"foo"' -;;; which avoids having to escape quotes where possible -(defun js-escape-string (string) - (let ((index 0) - (size (length string)) - (seen-single-quote nil) - (seen-double-quote nil)) - (flet ((%js-escape-string (string escape-single-quote-p) - (let ((output "") - (index 0)) - (while (< index size) - (let ((ch (char string index))) - (when (char= ch #\\) - (setq output (concat output "\\"))) - (when (and escape-single-quote-p (char= ch #\')) - (setq output (concat output "\\"))) - (when (char= ch #\newline) - (setq output (concat output "\\")) - (setq ch #\n)) - (setq output (concat output (string ch)))) - (incf index)) - output))) - ;; First, scan the string for single/double quotes - (while (< index size) - (let ((ch (char string index))) - (when (char= ch #\') - (setq seen-single-quote t)) - (when (char= ch #\") - (setq seen-double-quote t))) - (incf index)) - ;; Then pick the appropriate way to escape the quotes - (cond - ((not seen-single-quote) - (concat "'" (%js-escape-string string nil) "'")) - ((not seen-double-quote) - (concat "\"" (%js-escape-string string nil) "\"")) - (t (concat "'" (%js-escape-string string t) "'")))))) - -(defun lisp-escape-string (string) - (let ((output "") - (index 0) - (size (length string))) - (while (< index size) - (let ((ch (char string index))) - (when (or (char= ch #\") (char= ch #\\)) - (setq output (concat output "\\"))) - (when (or (char= ch #\newline)) - (setq output (concat output "\\")) - (setq ch #\n)) - (setq output (concat output (string ch)))) - (incf index)) - (concat "\"" output "\""))) - ;;; BOOTSTRAP MAGIC: We record the macro definitions as lists during ;;; the bootstrap. Once everything is compiled, we want to dump the ;;; whole global environment to the output file to reproduce it in the @@ -728,6 +670,19 @@ ",") ")"))) +(define-compilation macrolet (definitions &rest body) + (let ((*environment* (copy-lexenv *environment*))) + (dolist (def definitions) + (destructuring-bind (name lambda-list &body body) def + (let ((binding (make-binding :name name :type 'macro :value + (let ((g!form (gensym))) + `(lambda (,g!form) + (destructuring-bind ,lambda-list ,g!form + ,@body)))))) + (push-to-lexenv binding *environment* 'function)))) + (ls-compile `(progn ,@body) *multiple-value-p*))) + + (defun special-variable-p (x) (and (claimp x 'variable 'special) t))