1 (in-package #:avm2-compiler
)
3 ;;; implement lower level functions from conses dictionary
5 ;;; not all match CL semantics very closely yet...
7 ;;; conses dictionary (14.2)
9 ;;; not sure what best internal rep for conses is,
10 ;;; could use anonymous object
12 ;;; instances of named class
15 ;;; named class is probably easiest to recognize for type checking
16 ;;; so trying that first
17 ;;; anon object with car and cdr properties might also be nice, and
18 ;;; just allow any object with those to be used as a 'cons', but
19 ;;; wouldn't match CL sematics very well
20 (let ((*symbol-table
* *cl-symbol-table
*))
21 ;; todo: probably should figure out how to make this final/sealed/etc.
22 (def-swf-class cons-type
"cons" object
(%car %cdr
)
24 (%set-property this %car a
)
25 (%set-property this %cdr b
)))
27 (swf-defmemfun cons
(a b
)
28 (%asm
(:find-property-strict cons-type
)
31 (:construct-prop cons-type
2)))
33 #||
(def-swf-class cons-type
"cons" object
(%car %cdr
)
37 (swf-defmemfun cons
(a b
)
38 (%asm
(:find-property-strict cons-type
)
39 (:construct-prop cons-type
0)
48 (swf-defmemfun consp
(a)
51 (swf-defun atom (object)
54 (swf-defun %type-error
(fun arg
)
55 (%error
(+ "type-error: unknown type in " fun
":" (%type-of arg
))))
57 #+nil
(swf-defmemfun car
(a)
63 (%type-error
"CAR" a
))))
65 #+nil
(swf-defmemfun cdr
(a)
71 (%type-error
"CDR" a
))))
74 (swf-defmemfun car
(a)
78 (:get-property %car
))))
80 (swf-defmemfun cdr
(a)
84 (:get-property %cdr
))))
87 (swf-defmacro rplaca
(cons object
)
88 (let ((temp (gensym "RPLACA-TEMP-")))
91 (unless (consp ,temp
) (%type-error
"RPLACA" ,temp
))
92 (%set-property
,temp %car
,object
)
95 (swf-defmacro rplacd
(cons object
)
96 (let ((temp (gensym "REPLACD-TEMP-")))
99 (unless (consp ,temp
) (%type-error
"RPLACD" ,temp
))
100 (%set-property
,temp %cdr
,object
)
104 (swf-defun caar (x) (car (car x
)))
105 (swf-defun cadr (x) (car (cdr x
)))
106 (swf-defun cdar (x) (cdr (car x
)))
107 (swf-defun cddr (x) (cdr (cdr x
)))
108 (swf-defun caaar (x) (car (car (car x
))))
109 (swf-defun caadr (x) (car (car (cdr x
))))
110 (swf-defun cadar (x) (car (cdr (car x
))))
111 (swf-defun caddr (x) (car (cdr (cdr x
))))
112 (swf-defun cdaar (x) (cdr (car (car x
))))
113 (swf-defun cdadr (x) (cdr (car (cdr x
))))
114 (swf-defun cddar (x) (cdr (cdr (car x
))))
115 (swf-defun cdddr (x) (cdr (cdr (cdr x
))))
116 (swf-defun caaaar (x) (car (car (car (car x
)))))
117 (swf-defun caaadr (x) (car (car (car (cdr x
)))))
118 (swf-defun caadar (x) (car (car (cdr (car x
)))))
119 (swf-defun caaddr (x) (car (car (cdr (cdr x
)))))
120 (swf-defun cadaar (x) (car (cdr (car (car x
)))))
121 (swf-defun cadadr (x) (car (cdr (car (cdr x
)))))
122 (swf-defun caddar (x) (car (cdr (cdr (car x
)))))
123 (swf-defun cadddr (x) (car (cdr (cdr (cdr x
)))))
124 (swf-defun cdaaar (x) (cdr (car (car (car x
)))))
125 (swf-defun cdaadr (x) (cdr (car (car (cdr x
)))))
126 (swf-defun cdadar (x) (cdr (car (cdr (car x
)))))
127 (swf-defun cdaddr (x) (cdr (car (cdr (cdr x
)))))
128 (swf-defun cddaar (x) (cdr (cdr (car (car x
)))))
129 (swf-defun cddadr (x) (cdr (cdr (car (cdr x
)))))
130 (swf-defun cdddar (x) (cdr (cdr (cdr (car x
)))))
131 (swf-defun cddddr (x) (cdr (cdr (cdr (cdr x
)))))
134 (swf-defun copy-tree (tree)
136 (cons (copy-tree (car tree
)) (copy-tree (cdr tree
)))
139 (swf-defmemfun listp
(a)
140 (or (%typep a cons-type
) (eq a nil
)))
142 (swf-defmemfun endp
(a)
147 (%type-error
"ENDP" a
))))
149 ;; fixme: implement pop according to spec
150 (swf-defmacro pop
(a)
151 (let ((temp (gensym "POP-TEMP-")))
153 (%asm
(:comment
"pop") (:push-null
))
157 (%set-local
,a
(cdr ,temp
)))))))
159 ;; fixme: implement PUSH according to spec
160 (swf-defmacro push
(item place
)
161 (let ((temp (gensym "PUSH-TEMP-")))
163 (let ((,temp
,place
))
164 (%set-local
,place
(cons ,item
,temp
))))))
167 (swf-defun first (list) (car list
))
168 (swf-defun second (list) (car (cdr list
)))
169 (swf-defun third (list) (car (cddr list
)))
170 (swf-defun fourth (list) (car (cdddr list
)))
171 (swf-defun fifth (list) (car (cddddr list
)))
172 (swf-defun sixth (list) (car (cdr (cddddr list
))))
173 (swf-defun seventh (list) (car (cddr (cddddr list
))))
174 (swf-defun eighth (list) (car (cdddr (cddddr list
))))
175 (swf-defun ninth (list) (car (cddddr (cddddr list
))))
176 (swf-defun tenth (list) (car (cdr (cddddr (cddddr list
)))))