-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathliterals.lisp
72 lines (62 loc) · 2.84 KB
/
literals.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(defpackage clclojure.literals
(:use :common-lisp
:clclojure.eval
:clclojure.pvector
:clclojure.cowmap))
(in-package :clclojure.literals)
;;Data Literal Eval Semantics
(EVAL-WHEN (:compile-toplevel :load-toplevel :execute)
(clclojure.eval:enable-custom-eval)
;;(eval [x y z]) => (vector (eval x) (eval y) (eval z))
;;this is somewhat inefficient since we're not exploiting
;;chunks, but good enough for proof of concept. We do
;;have chunks, fyi.
(defmethod clclojure.eval::literal? ((obj pvec)) t)
(defmethod custom-eval ((obj pvec) &optional env)
(vector-map (lambda (x) (clclojure.eval:custom-eval-in-lexenv x env)) obj))
(defmethod let-expr ((obj pvec))
;; `(clclojure.eval:literal
;; (clclojure.pvector:persistent-vector ,@(clclojure.pvector:vector-to-list obj)))
(list 'clclojure.reader::literal
(list* 'clclojure.reader::data-literal
(list 'function 'persistent-vector)
`((list ,@(vector-to-list obj)))))
)
;; (defmethod let-expr ((obj pvec))
;; obj)
(defmethod clclojure.eval::literal? ((obj subvector)) t)
(defmethod custom-eval ((obj subvector) &optional env)
(vector-map (lambda (x) (clclojure.eval:custom-eval-in-lexenv x env)) obj))
(defmethod let-expr ((obj subvector))
;; `(clclojure.eval:literal
;; (clclojure.pvector:persistent-vector ,@(clclojure.pvector:vector-to-list obj)))
(list 'clclojure.reader::literal
(list* 'clclojure.reader::data-literal
(list 'function 'persistent-vector)
`((list ,@(vector-to-list obj)))))
)
(defmethod clclojure.eval::literal? ((obj cowmap)) t)
;;(map {x y j k} => (persistent-map
;;(clclojure.eval:custom-eval-in-lexenv x)
;;(clclojure.eval:custom-eval-in-lexenv y)
;;(clclojure.eval:custom-eval-in-lexenv j)
;;(clclojure.eval:custom-eval-in-lexenv k))
(defmethod custom-eval ((obj cowmap) &optional env)
(reduce (lambda (acc kv)
(destructuring-bind (k v) kv
(map-assoc acc (clclojure.eval:custom-eval-in-lexenv k env)
(clclojure.eval:custom-eval-in-lexenv v env))))
(map-seq obj) :initial-value (empty-map)))
(defmethod let-expr ((obj cowmap))
;; `(clclojure.eval:literal
;; (clclojure.cowmap:persistent-map
;; ,@(reduce (lambda (acc kv)
;; (cons (first kv) (cons (second kv) acc)))
;; (clclojure.cowmap:map-seq obj) :initial-value '())))
(list 'clclojure.reader::literal
(list* 'clclojure.reader::data-literal
(list 'function 'persistent-map)
`((list ,@(reduce (lambda (acc kv)
(cons (first kv) (cons (second kv) acc)))
(clclojure.cowmap:map-seq obj) :initial-value '()))))))
)