1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 02:45:44 +03:00

Remove unnecessary boxing/unboxing

This commit is contained in:
Vasilij Schneidermann 2016-03-02 00:10:29 +01:00
parent 5dc4e25706
commit 4e1479b290
5 changed files with 13 additions and 16 deletions

View File

@ -5,11 +5,10 @@
mal-false)))
(defun mal-listify (mal-object)
;; FIXME: avoid boxing
(let ((type (mal-type mal-object)))
(if (eq type 'vector)
(mal-list (append (mal-value mal-object) nil))
mal-object)))
(append (mal-value mal-object) nil)
(mal-value mal-object))))
(defun mal-= (a b)
(let ((a-type (mal-type a))
@ -37,9 +36,7 @@
(defun mal-seq-= (a b)
(when (= (length (mal-value a))
(length (mal-value b)))
(when (everyp 'mal-=
(mal-value (mal-listify a))
(mal-value (mal-listify b)))
(when (everyp 'mal-= (mal-listify a) (mal-listify b))
t)))
(defun everyp (predicate list-a list-b)
@ -117,24 +114,24 @@
(value (apply (mal-value fn*) args*)))
(setf (aref atom 1) value)))))
(cons . ,(mal-fn (lambda (arg list) (mal-list (cons arg (mal-value (mal-listify list)))))))
(cons . ,(mal-fn (lambda (arg list) (mal-list (cons arg (mal-listify list))))))
(concat . ,(mal-fn (lambda (&rest lists)
(let ((lists* (mapcar (lambda (item) (mal-value (mal-listify item))) lists)))
(let ((lists* (mapcar (lambda (item) (mal-listify item)) lists)))
(mal-list (apply 'append lists*))))))
(nth . ,(mal-fn (lambda (seq index)
(let ((i (mal-value index))
(list (mal-value (mal-listify seq))))
(list (mal-listify seq)))
(or (nth i list)
;; FIXME
(signal 'args-out-of-range (list (pr-str seq) i)))))))
(first . ,(mal-fn (lambda (seq)
(if (mal-nil-p seq)
mal-nil
(let* ((list (mal-value (mal-listify seq)))
(let* ((list (mal-listify seq))
(value (car list)))
(or value mal-nil))))))
(rest . ,(mal-fn (lambda (seq) (mal-list (cdr (mal-value (mal-listify seq)))))))
(rest . ,(mal-fn (lambda (seq) (mal-list (cdr (mal-listify seq))))))
(throw . ,(mal-fn (lambda (mal-object) (signal 'mal-custom (list mal-object)))))
@ -142,7 +139,7 @@
(let* ((butlast (butlast args))
(last (mal-listify (car (last args))))
(fn* (if (mal-func-p fn) (mal-func-fn fn) fn))
(args* (append butlast (mal-value last))))
(args* (append butlast last)))
(apply (mal-value fn*) args*)))))
(map . ,(mal-fn (lambda (fn seq)
(let ((fn* (if (mal-func-p fn) (mal-func-fn fn) fn)))

View File

@ -30,7 +30,7 @@
(defun quasiquote (ast)
(if (not (mal-pair-p ast))
(mal-list (list (mal-symbol 'quote) ast))
(let* ((a (mal-value (mal-listify ast)))
(let* ((a (mal-listify ast))
(a0 (car a))
(a0... (cdr a))
(a1 (cadr a)))

View File

@ -30,7 +30,7 @@
(defun quasiquote (ast)
(if (not (mal-pair-p ast))
(mal-list (list (mal-symbol 'quote) ast))
(let* ((a (mal-value (mal-listify ast)))
(let* ((a (mal-listify ast))
(a0 (car a))
(a0... (cdr a))
(a1 (cadr a)))

View File

@ -30,7 +30,7 @@
(defun quasiquote (ast)
(if (not (mal-pair-p ast))
(mal-list (list (mal-symbol 'quote) ast))
(let* ((a (mal-value (mal-listify ast)))
(let* ((a (mal-listify ast))
(a0 (car a))
(a0... (cdr a))
(a1 (cadr a)))

View File

@ -30,7 +30,7 @@
(defun quasiquote (ast)
(if (not (mal-pair-p ast))
(mal-list (list (mal-symbol 'quote) ast))
(let* ((a (mal-value (mal-listify ast)))
(let* ((a (mal-listify ast))
(a0 (car a))
(a0... (cdr a))
(a1 (cadr a)))