*newline*
(if rest-argument
(let ((js!rest (lookup-variable-translation rest-argument new-env)))
- (concat "var " js!rest ";" *newline*
+ (concat "var " js!rest "= false;" *newline*
"for (var i = arguments.length-1; i>="
(integer-to-string (length required-arguments))
"; i--)" *newline*
(setq *toplevel-compilations* nil)
(let ((code (ls-compile sexp)))
(prog1
- (concat (join (mapcar (lambda (x) (concat x ";" *newline*))
+ (concat "/* " (princ-to-string sexp) " */"
+ (join (mapcar (lambda (x) (concat x ";" *newline*))
*toplevel-compilations*)
- "")
+ "")
code)
(setq *toplevel-compilations* nil))))
(defun atom (x)
(not (consp x)))
-(defun listp (x)
- (or (consp x) (null x)))
-
(defun ensure-list (x)
(if (listp x)
x
(defmacro decf (x)
`(setq ,x (1- ,x)))
-(defun length (list)
+(defun list-length (list)
(let ((l 0))
(while (not (null list))
(incf l)
(setq list (cdr list)))
l))
+(defun length (seq)
+ (if (stringp seq)
+ (string-length seq)
+ (list-length seq)))
+
(defun mapcar (func list)
(if (null list)
'()
(defun char= (x y) (= x y))
+(defun <= (x y) (or (< x y) (= x y)))
+(defun >= (x y) (not (< x y)))
+
+(defun listp (x)
+ (or (consp x) (null x)))
+
(defun integerp (x)
(and (numberp x) (= (floor x) x)))
-
(defun last (x)
(if (null (cdr x))
x
((eql x (car list))
(remove x (cdr list)))
(t
- (cons (car x) (remove x (cdr list))))))
+ (cons (car list) (remove x (cdr list))))))
(defun digit-char-p (x)
- (if (and (< #\0 x) (< x #\9))
+ (if (and (<= #\0 x) (<= x #\9))
(- x #\0)
nil))
(defun parse-integer (string)
(let ((value 0)
(index 0)
- (size (string-length string)))
+ (size (length string)))
(while (< index size)
(setq value (+ (* value 10) (digit-char-p (char string index))))
- (incf index))))
+ (incf index))
+ value))
(defun every (function seq)
;; string
(let ((ret t)
(index 0)
- (size (string-length seq)))
+ (size (length seq)))
(while (and ret (< index size))
(unless (funcall function (char seq index))
- (setq ret nil)))))
+ (setq ret nil))
+ (incf index))
+ ret))
(defun eql (x y)
(eq x y))
(defun terminalp (ch)
(or (null ch) (whitespacep ch) (char= #\) ch) (char= #\( ch)))
-
(defun read-until (stream func)
(let ((string "")
(ch))
(parse-integer string)
(intern (string-upcase string))))))))
-
(defun ls-read-from-string (string)
(ls-read (make-string-stream string)))
-
;;;; Compiler
(defvar *compilation-unit-checks* '())
*newline*
(if rest-argument
(let ((js!rest (lookup-variable-translation rest-argument new-env)))
- (concat "var " js!rest ";" *newline*
+ (concat "var " js!rest "= false;" *newline*
"for (var i = arguments.length-1; i>="
(integer-to-string (length required-arguments))
"; i--)" *newline*
(defun macrop (x)
(and (symbolp x) (eq (binding-type (lookup-function x *fenv*)) 'macro)))
-(defun ls-macroexpand-1 (form &optional env fenv)
+(defun ls-macroexpand-1 (form env fenv)
(when (macrop (car form))
(let ((binding (lookup-function (car form) *env*)))
(if (eq (binding-type binding) 'macro)
(t
(error (concat "Invalid function designator " (symbol-name function))))))
-(defun ls-compile (sexp &optional env fenv)
+(defun ls-compile (sexp env fenv)
(cond
((symbolp sexp) (lookup-variable-translation sexp env))
((integerp sexp) (integer-to-string sexp))
(defun ls-compile-toplevel (sexp)
(setq *toplevel-compilations* nil)
- (let ((code (ls-compile sexp)))
+ (let ((code (ls-compile sexp nil nil)))
(prog1
(concat (join (mapcar (lambda (x) (concat x ";" *newline*))
*toplevel-compilations*)