forked from dumbs/2010-m1s1-compilation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisp2li.lisp
565 lines (486 loc) · 20.2 KB
/
lisp2li.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
(require 'util "util.lisp")
(require 'match "match.lisp")
;; `
(defvar my-quasiquote nil);(car '`(,a)))
;; ,
(defvar my-unquote nil);(caaadr '`(,a)))
;; ,@
(defvar my-unquote-unsplice nil);(caaadr '`(,@a)))
(declaim (ftype function lisp2li)) ;; Double récursion map-lisp2li / lisp2li.
(defun map-lisp2li (expr env)
(mapcar (lambda (x) (lisp2li x env)) expr))
(declaim (ftype function make-stat-env1)) ;; Double récursion make-stat-env1 / make-stat-env-optional
(defun make-stat-env-optional (params env position num-env)
(cond ((endp params)
env)
((consp (car params))
`((,(caar params) ,num-env ,position)
(,(intern (format nil "~a-P" (caar params))) ,num-env ,(+ 1 position))
. ,(make-stat-env-optional (cdr params) env (+ 2 position) num-env)))
((eq '&rest (car params))
(make-stat-env1 (cdr params) env position num-env))
(T
`((,(car params) ,num-env ,position)
. ,(make-stat-env-optional (cdr params) env (+ 1 position) num-env)))))
(defun env-depth (env)
(or (cadar (last env)) 0))
(defun recalculation (env)
(cond ((endp env)
env)
(T
`((,(caar env) ,(+ 1 (cadar env)) ,(caddar env))
. ,(recalculation (cdr env))))))
(defun make-stat-env1 (params &optional env (position 1) num-env)
(cond ((endp params)
env)
((eq '&optional (car params))
(make-stat-env-optional (cdr params) env position num-env))
((eq '&rest (car params))
(make-stat-env1 (cdr params) env position num-env))
(T
`((,(car params) 0 ,position)
. ,(make-stat-env1 (cdr params) env (+ 1 position) num-env)))))
(defun make-stat-env (params &optional env (position 1))
(make-stat-env1 params (recalculation env) position 0))
(defun transform-quasiquote (expr)
(cond
;; a
((atom expr)
`',expr)
;; (a)
((atom (car expr))
`(cons ',(car expr)
,(transform-quasiquote (cdr expr))))
;; (,a)
((eq my-unquote (caar expr))
`(cons ,(cadar expr)
,(transform-quasiquote (cdr expr))))
;; (,@a)
((eq my-unquote-unsplice (caar expr))
(if (endp (cdr expr))
(cadar expr)
`(append ,(cadar expr)
,(transform-quasiquote (cdr expr)))))
;; ((a ...) ...)
(T
`(cons ,(transform-quasiquote (car expr))
,(transform-quasiquote (cdr expr))))))
(defun get-nb-params-t (params r)
(cond ((endp params)
r)
((or (eq '&optional (car params))
(eq '&rest (car params)))
(get-nb-params-t (cdr params) r))
(T
(get-nb-params-t (cdr params) (+ 1 r)))))
(defun get-nb-params (params)
"Renvoie le nombre exact de paramètres sans les &optional et &rest"
(get-nb-params-t params 0))
(defun implicit-progn (expr)
(if (n-consp 2 expr)
(cons 'progn expr)
(car expr)))
(defun simplify (li) ;; TODO : a finir
(cond-match li
((:nil :progn :expr _)
(simplify expr))
((:nil :progn :body0 _* (:nil :progn :body1 _*)+ :body2 _*)
(simplify `(:progn ,@body0 ,@(car body1) ,@body2)))
((:nil :progn :body0 _* (:nil :let :size (? integerp) :body1 _*)+ :body2 _*)
(simplify `(:let ,@size ,@body0 ,@(car body1) ,@body2)))
((:nil :let :size1 (? integerp) :body1 _*
(:nil :let :size2 (? integerp)
(:nil :set-var (:depth-set (? integerp) :index-set (? integerp)) @.)+
:var1 (:nil :cvar :depth1 (? integerp) :index1 (? integerp))*
:body2 _* :var2 (:nil :cvar :depth2 (? integerp) :index2 (? integerp))*)
:body3 _*)
(simplify `(:let ,(+ size1 size2)
,@body1
,@(mapcar
(lambda (depth index)
`(:cvar ,(- depth 1) ,(+ index size1))) depth1 index1)
,@body2
,@(if (and depth2 index2)
(mapcar
(lambda (depth index)
`(:cvar ,(- depth 1) ,(+ index size1))) depth2 index2))
,@body3)))
((:nil :let :body0 _* (:nil :progn :body1 _*)+ :body2 _*)
(simplify `(:let ,@body0 ,@(car body1) ,@body2)))
((:nil :let :size1 (? integerp) :body0 _* (:nil :let :size2 (? integerp) :body1 _*)+ :body2 _*)
(simplify `(:let ,(+ size1 (car size2)) ,@body0 ,@(car body1) ,@body2)))
((:nil :if (:nil :const :cond . _) :then @. :else @.)
(simplify (if cond then else)))
(@. li)))
(defun lisp2li (expr &optional env)
"Convertit le code LISP en un code intermédiaire reconnu
par le compilateur et par l’interpréteur"
(cond
;; literaux
((and (atom expr) (constantp expr))
(cons :const expr))
;; symboles
((symbolp expr)
(let ((cell (assoc expr env)))
(if cell
`(:cvar ,(cadr cell) ,(caddr cell))
(error "Variable ~S unknown" expr))))
;; lambda solitaire ex: (lambda (x) x)
((eq 'lambda (car expr)) ;; TODO : ameliorer le cas du lambda
(if (member '&rest (second expr))
`(:lclosure . (,(get-nb-params (second expr))
,(+ 1 (mposition '&rest (second expr)))
,@(lisp2li (implicit-progn (cddr expr))
(make-stat-env (second expr) env))))
`(:lclosure . ,(cons (get-nb-params (second expr))
(lisp2li (implicit-progn (cddr expr))
(make-stat-env (second expr) env))))))
;; lambda ex: ((lambda (x) x) 1)
((and (consp (car expr))
(eq 'lambda (caar expr)))
`(:mcall ,(lisp2li (car expr) env)
,@(mapcar (lambda (param)
(lisp2li param env))
(cdr expr))))
;; (not-symbol ...)
((not (symbolp (car expr)))
(warn "~S isn't a symbol" (car expr)))
;; fonction meta-definie
((get (car expr) :defun)
`(:mcall ,(car expr)
,@(mapcar (lambda (x) (lisp2li x env)) (cdr expr))))
;; macro meta-definie
((get (car expr) :defmacro)
`(:mcall ,(car expr)
,@(mapcar (lambda (x) `(:const . ,x)) (cdr expr))))
;; fonction inconnue
((and (not (fboundp (car expr)))
(not (get (car expr) :defun))
(not (get (car expr) :defmacro)))
`(:unknown ,expr ,env))
;; if
((eq 'if (car expr))
(list :if
(lisp2li (second expr) env)
(lisp2li (third expr) env)
(lisp2li (fourth expr) env)))
;; quote
((eq 'quote (car expr))
(cons :const (second expr)))
;; quasiquote `
((eq my-quasiquote (car expr))
(lisp2li (transform-quasiquote (cadr expr)) env))
;; #'fn (FUNCTION fn)
((eq 'function (car expr))
`(:sclosure ,(cadr expr)))
;; let
((eq 'let (car expr))
(match (let :bindings ((:names $ :values _)*) :body _*) expr
(let ((new-env (make-stat-env names env)))
`(:let ,(length bindings)
,@(mapcar
(lambda (name value)
(let ((cell (assoc name new-env)))
`(:set-var (,(second cell) ,(third cell))
,(lisp2li value new-env))))
names values)
,(lisp2li (implicit-progn body) new-env)))))
((eq 'let* (car expr))
(cond-match expr
(((? (eq x 'let*)) :bindings () :body _*)
(lisp2li (implicit-progn body) env))
(((? (eq x 'let*)) :bindings ((:name $ :value _) :rest ($ _)*) :body _*)
(lisp2li `(let ((,name ,value))
(let* ,rest
,@body)) env))))
;; defun
((eq 'defun (car expr))
`(:mcall set-defun (:const . ,(second expr))
,(lisp2li `(lambda ,(third expr) ,@(cdddr expr)) env)))
;; defmacro
((eq 'defmacro (car expr))
`(:mcall set-defmacro (:const . ,(second expr))
,(lisp2li `(lambda ,(third expr) ,@(cdddr expr)) env)))
;; apply
((eq 'apply (car expr))
`(:sapply ,(second expr) ,@(cddr expr)))
;; setf
((eq 'setf (car expr))
(cond ((symbolp (cadr expr))
(let ((cell (assoc (cadr expr) env)))
`(:set-var (,(second cell) ,(third cell))
,(lisp2li (third expr) env))))
((symbolp (cdadr expr))
(let ((cell (assoc (cdadr expr) env)))
`(:set-var (,(second cell) ,(third cell))
,(third expr))))
(T
`(:set-fun ,(caadr expr) ,@(last expr) ,@(cdadr expr)))))
;; setq
((eq 'setq (car expr))
(lisp2li `(setf ,@(cdr expr)) env))
;; defvar
((eq 'defvar (car expr))
(let ((var `(,(cadr expr)
,(if (eq nil env) 0 (cadar (last env)))
,(if (eq nil env) 1 (+ (caddar (last env)) 1)))))
(setf env (append env `(,var)))
(print env)
`(:set-var (,(second var) ,(third var))
,(third expr))))
;; progn
((eq 'progn (car expr))
(cons :progn (map-lisp2li (cdr expr) env)))
;; declaim
((eq 'declaim (car expr))
(cons :const nil))
;; the
((eq 'the (car expr))
(lisp2li (third expr)))
;; macros
((macro-function (car expr))
(lisp2li (macroexpand-1 expr) env))
;; foctions normales
((not (special-operator-p (car expr)))
`(:call ,(first expr) ,@(map-lisp2li (cdr expr) env)))
(T
(error "special form not yet implemented ~S" (car expr)))))
;; TODO : demander au prof comment corriger (or (= n 0) (= n 1)) qui rend nil car il fait 2 macroexpand 1: (COND ((= N 0)) (T (= N 1))) 2: (LET (#1=#:RESULT-7048) (IF (SETQ #1# (= N 0)) #1# (= N 1))) et 2 vaux nil car n != 0
;; Test unitaire
(require 'test-unitaire "test-unitaire")
(erase-tests lisp2li)
(deftest (lisp2li make-stat-env)
(make-stat-env '(x y z))
'((x 0 1) (y 0 2) (z 0 3)))
(deftest (lisp2li make-stat-env)
(make-stat-env '(a b c d))
'((a 0 1) (b 0 2) (c 0 3) (d 0 4)))
(deftest (lisp2li make-stat-env)
(make-stat-env '(a b) '((x 0 1) (y 0 2)))
'((a 0 1) (b 0 2) (x 1 1) (y 1 2)))
(deftest (lisp2li make-stat-env)
(make-stat-env '(a b &optional c &rest d))
'((a 0 1) (b 0 2) (c 0 3) (d 0 4)))
(deftest (lisp2li make-stat-env)
(make-stat-env '(x y &optional (z t)))
'((x 0 1) (y 0 2) (z 0 3) (z-p 0 4)))
;; (deftest (lisp2li simplify :progn)
;; (simplify '(:progn (:const . 3)))
;; '(:const . 3))
;; (deftest (lisp2li simplify :progn)
;; (simplify '(:progn (:call list (:const . 1) (:const . 2))))
;; '(:call list (:const . 1) (:const . 2)))
;; (deftest (lisp2li simplify :progn)
;; (simplify '(:progn (:progn (:const . 3) (:const . 4))))
;; '(:progn (:const . 3) (:const . 4)))
;; (deftest (lisp2li simplify :progn)
;; (simplify '(:progn (:const . 3) (:const . 4) (:progn (:const . 5) (:const . 6))))
;; '(:progn (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :progn)
;; (simplify '(:progn (:const . 1) (:const . 2) (:progn (:const . 3) (:const . 4)) (:const . 5) (:const . 6)))
;; '(:progn (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :progn)
;; (simplify '(:progn (:const . 1) (:const . 2) (:progn (:const . 3) (:const . 4)) (:const . 5) (:progn (:const . 6) (:const . 7))))
;; '(:progn (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6) (:const . 7)))
;; (deftest (lisp2li simplify :let-progn)
;; (simplify '(:let (:progn (:const . 3) (:const . 4))))
;; '(:let (:const . 3) (:const . 4)))
;; (deftest (lisp2li simplify :let-progn)
;; (simplify '(:let (:const . 3) (:const . 4) (:progn (:const . 5) (:const . 6))))
;; '(:let (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :let-progn)
;; (simplify '(:let (:const . 1) (:const . 2) (:progn (:const . 3) (:const . 4)) (:const . 5) (:const . 6)))
;; '(:let (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :let-progn)
;; (simplify '(:let (:const . 1) (:const . 2) (:progn (:const . 3) (:const . 4)) (:const . 5) (:progn (:const . 6) (:const . 7))))
;; '(:let (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6) (:const . 7)))
;; (deftest (lisp2li simplify :progn-let)
;; (simplify '(:progn (:let 0 (:const . 3) (:const . 4))))
;; '(:let 0 (:const . 3) (:const . 4)))
;; (deftest (lisp2li simplify :progn-let)
;; (simplify '(:progn (:let 2 (:const . 3) (:const . 4) (:progn (:const . 5) (:const . 6)))))
;; '(:let 2 (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :progn-let)
;; (simplify '(:progn (:const . 1) (:const . 2) (:let 1 (:const . 3) (:const . 4)) (:const . 5) (:const . 6)))
;; '(:let 1 (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :progn-let)
;; (simplify '(:progn (:const . 1) (:const . 2) (:let 5 (:const . 3) (:const . 4)) (:const . 5) (:progn (:const . 6) (:const . 7))))
;; '(:let 5 (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6) (:const . 7)))
;; (deftest (lisp2li simplify :let-let)
;; (simplify '(:let 1 (:let 1 (:const . 3) (:const . 4))))
;; '(:let 2 (:const . 3) (:const . 4)))
;; (deftest (lisp2li simplify :let-let)
;; (simplify '(:let 3 (:let 2 (:const . 3) (:const . 4) (:progn (:const . 5) (:const . 6)))))
;; '(:let 5 (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :let-let)
;; (simplify '(:let 2 (:const . 1) (:const . 2) (:let 1 (:const . 3) (:const . 4)) (:const . 5) (:const . 6)))
;; '(:let 3 (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6)))
;; (deftest (lisp2li simplify :let-let)
;; (simplify '(:let 5 (:const . 1) (:const . 2) (:let 5 (:const . 3) (:const . 4)) (:const . 5) (:let 2 (:const . 6) (:const . 7))))
;; '(:let 12 (:const . 1) (:const . 2) (:const . 3) (:const . 4) (:const . 5) (:const . 6) (:const . 7)))
;; (deftest (lisp2li simplify :if)
;; (simplify '(:if (:const . nil) (:call list 1 2 3) (:const . T)))
;; '(:const . T))
;; (deftest (lisp2li simplify :if)
;; (simplify '(:if (:const . nil) (:progn (:let 2 (:const . 1)) (:const . 2)) (:call list (:const 1 2 3))))
;; '(:call list (:const 1 2 3)))
;; (deftest (lisp2li simplify :if)
;; (simplify '(:if (:const . nil) (:const . nil) (:progn (:let 2 (:const . 1)) (:const . 2)) ))
;; '(:let 2 (:const . 1) (:const . 2)))
;; (deftest (lisp2li simplify :if)
;; (simplify '(:if (:const . 2) (:const . nil) (:const . T)))
;; '(:const . nil))
;; (deftest (lisp2li simplify :if)
;; (simplify '(:if (:const . T) (:const . 3) (:const . 4)))
;; '(:const . 3))
;; (deftest (lisp2li simplify :if)
;; (simplify '(:if (:const 1 2 3) (:progn (:let 3 (:const . 3)) (:let 4 (:const . 4))) (:const . 4)))
;; '(:let 7 (:const . 3) (:const . 4)))
;; (deftest (lisp2li simplify :let-cvar)
;; (simplify '(:let 3 (:const . T) (:let 4 (:cvar 1 1) (:const . 4))))
;; '(:let 7 (:const . T) (:cvar 0 4) (:const . 4)))
;; (deftest (lisp2li simplify :let-cvar)
;; (simplify '(:progn (:cvar 0 1)
;; (:LET 1 (:CONST . T)
;; (:LET 2 (:CVAR 0 1) (:cvar 1 1) (:cvar 2 1) (:CONST . 4)))))
;; '(:let 3 (:cvar 0 1) (:const . T) (:cvar 0 1) (:cvar 0 2) (:cvar 1 2) (:const . 4)))
(deftest (lisp2li constante)
(lisp2li '3 ())
'(:const . 3))
(deftest (lisp2li constante)
(lisp2li ''x ())
'(:const . x))
(deftest (lisp2li constante)
(lisp2li ''(1 2 3) ())
'(:const 1 2 3))
(deftest (lisp2li variables)
(lisp2li 'x '((x 0 1) (y 0 2)))
'(:cvar 0 1))
(deftest (lisp2li fonctions-normales)
(lisp2li '(+ 3 4) ())
'(:call + (:const . 3) (:const . 4)))
(deftest (lisp2li fonctions-normales)
(lisp2li '(list 3 4 (* 6 7)) ())
'(:call list (:const . 3) (:const . 4)
(:call * (:const . 6) (:const . 7))))
(deftest (lisp2li if)
(lisp2li '(if T T nil) ())
'(:if (:const . T) (:const . T) (:const . nil)))
(deftest (lisp2li defun)
(lisp2li '(defun bar (x) x) ())
'(:mcall set-defun (:const . bar) (:lclosure 1 :cvar 0 1)))
(deftest (lisp2li defun)
(lisp2li '(defun foo (x y z) (list x y z)) ())
'(:mcall set-defun (:const . foo)
(:lclosure 3 :call list
(:cvar 0 1)
(:cvar 0 2)
(:cvar 0 3))))
(deftest (lisp2li setf)
(lisp2li '(setf y 42) '((x 0 1) (y 0 2)))
'(:set-var (0 2) (:const . 42)))
(deftest (lisp2li setf)
(lisp2li '(setf (cdr '(1 2 3)) 42) ())
'(:set-fun cdr 42 '(1 2 3)))
(deftest (lisp2li lambda)
(lisp2li '(mapcar (lambda (x y z) (list x y z)) '(1 2 3)) ())
'(:call mapcar (:lclosure 3 :call list
(:cvar 0 1)
(:cvar 0 2)
(:cvar 0 3))
(:const 1 2 3)))
(deftest (lisp2li lambda)
(lisp2li '((lambda (x y z) (list x y z)) 1 2 3) ())
'(:mcall (:lclosure 3 :call list
(:cvar 0 1)
(:cvar 0 2)
(:cvar 0 3))
(:const . 1) (:const . 2) (:const . 3)))
(deftest (lisp2li lambda)
(lisp2li `(lambda (x y z) (list x y z)) ())
'(:lclosure 3 :call list
(:cvar 0 1)
(:cvar 0 2)
(:cvar 0 3)))
(deftest (lisp2li lambda)
(lisp2li `(lambda (x y z) (list x y z) (+ x y)) ())
'(:lclosure 3 :progn (:call list
(:cvar 0 1)
(:cvar 0 2)
(:cvar 0 3))
(:call +
(:cvar 0 1)
(:cvar 0 2))))
(deftest (lisp2li rest)
(lisp2li `(lambda (x &rest y) (cons x y)) ())
'(:lclosure 2 2 :call cons
(:cvar 0 1)
(:cvar 0 2)))
(deftest (lisp2li unknown)
(lisp2li '(bar 3) ())
'(:unknown (bar 3) ()))
(deftest (lisp2li function)
(lisp2li '#'car ())
'(:sclosure car))
(deftest (lisp2li apply)
(lisp2li '(apply 'list '(1 2 3)) ())
'(:sapply 'list '(1 2 3)))
(deftest (lisp2li apply)
(lisp2li '(apply #'list '(1 2 3)) ())
'(:sapply #'list '(1 2 3)))
(deftest (lisp2li progn)
(lisp2li '(progn (list 1 2 3) (+ 3 4)) ())
'(:progn (:call list
(:const . 1)
(:const . 2)
(:const . 3))
(:call +
(:const . 3)
(:const . 4))))
;; TODO : on ne peut pas faire de tests sur des macros qu'on n'a pas implémentées nous-mêmes,
;; car sinon le résultat dépend de l'implémentation.
;; (deftest (lisp2li macro)
;; (lisp2li '(cond ((eq (car '(1 2 3)) 1) T)
;; ((eq (car '(1 2 3)) 2) 2)
;; (T nil))
;; ())
;; '(:if (:call eq (:call car (:const 1 2 3)) (:const . 1))
;; (:const . T)
;; (:if (:call eq (:call car (:const 1 2 3)) (:const . 2))
;; (:const . 2)
;; (:const . nil))))
;; (deftest (lisp2li macro)
;; (lisp2li '(and (eq (car '(1 2)) 1)
;; T)
;; ())
;; '(:if (:call not
;; (:call eq (:call car (:const 1 2)) (:const . 1)))
;; (:const . nil)
;; (:const . T)))
(deftest (lisp2li let)
(lisp2li '(let ((x 1) (y 2))
(cons x y)) ())
'(:let 2 (:set-var (0 1) (:const . 1))
(:set-var (0 2) (:const . 2))
(:call cons (:cvar 0 1) (:cvar 0 2))))
(deftest (lisp2li let)
(lisp2li '(let ((x 1) (y 2))
(cons x y)
(list x y)) ())
'(:let 2 (:set-var (0 1) (:const . 1))
(:set-var (0 2) (:const . 2))
(:progn
(:call cons (:cvar 0 1) (:cvar 0 2))
(:call list (:cvar 0 1) (:cvar 0 2)))))
(deftest (lisp2li let)
(lisp2li '(let ((x z) (y 2))
(cons x y)) '((z 0 1)))
'(:let 2 (:set-var (0 1) (:cvar 1 1))
(:set-var (0 2) (:const . 2))
(:call cons (:cvar 0 1) (:cvar 0 2))))
(deftest (lisp2li let)
(lisp2li '(let ((x 2))
(cons x z)) '((z 0 1)))
'(:let 1 (:set-var (0 1) (:const . 2))
(:call cons (:cvar 0 1) (:cvar 1 1))))
(provide 'lisp2li)