(define-compilation eq (x y)
(concat "(" (ls-compile x env fenv) " === " (ls-compile y env fenv) ")"))
+(define-compilation equal (x y)
+ (concat "(" (ls-compile x env fenv) " == " (ls-compile y env fenv) ")"))
+
(define-compilation string (x)
(concat "String.fromCharCode(" (ls-compile x env fenv) ")"))
(define-compilation string-upcase (x)
(concat "(" (ls-compile x env fenv) ").toUpperCase()"))
+(define-compilation string-length (x)
+ (concat "(" (ls-compile x env fenv) ").length"))
+
(define-compilation char (string index)
(concat "("
(ls-compile string env fenv)
(defun ls-compile-file (filename output)
(setq *env* nil *fenv* nil)
+ (setq *compilation-unit-checks* nil)
(with-open-file (out output :direction :output :if-exists :supersede)
(let* ((source (read-whole-file filename))
(in (make-string-stream source)))
when (plusp (length compilation))
do (write-line (concat compilation "; ") out))
(dolist (check *compilation-unit-checks*)
- (funcall check)))))
+ (funcall check))
+ (setq *compilation-unit-checks* nil))))
(defun bootstrap ()
(ls-compile-file "lispstrack.lisp" "lispstrack.js")))
(defun cdar (x) (cdr (car x)))
(defun cddr (x) (cdr (cdr x)))
+(defun list (&rest args)
+ args)
+
(defun append (list1 list2)
(if (null list1)
list2
(defun char= (x y) (= x y))
+(defun digit-char-p (x)
+ (if (and (< #\0 x) (< x #\9))
+ (- x #\0)
+ nil))
+
+(defun parse-integer (string)
+ (let ((value 0)
+ (index 0)
+ (size (string-length string)))
+ (while (< index size)
+ (setq value (+ (* value 10) (digit-char-p (char string index))))
+ (incf index))))
+
+(defun every (function seq)
+ ;; string
+ (let ((ret t)
+ (index 0)
+ (size (string-length seq)))
+ (while (and ret (< index size))
+ (unless (funcall function (char seq index))
+ (setq ret nil)))))
+
+(defun eql (x y)
+ (eq x y))
+
+(defun string= (s1 s2)
+ (equal s1 s2))
+
;;;; Reader
;;; It is a basic Lisp reader. It does not use advanced stuff