From: David Vazquez Date: Thu, 20 Dec 2012 17:49:38 +0000 (+0000) Subject: More progresses to bootstrap X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=907f87f5558d1690f565a520a48abdb3612e974e;p=jscl.git More progresses to bootstrap --- diff --git a/lispstrack.lisp b/lispstrack.lisp index d71f675..90b723f 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -493,12 +493,18 @@ (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) @@ -598,6 +604,7 @@ (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))) @@ -608,7 +615,8 @@ 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"))) diff --git a/test.lisp b/test.lisp index 50bc756..950841d 100644 --- a/test.lisp +++ b/test.lisp @@ -47,6 +47,9 @@ (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 @@ -202,6 +205,34 @@ (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