ref: 9139fb180c76413d036311a8e2b02178a72e557f
parent: bda4940a4be038f85887cb93c2fdc60db6b4d41a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Dec 26 14:18:43 EST 2024
compiler: drop useless load followed by a pop
--- a/compiler.lsp
+++ b/compiler.lsp
@@ -21,12 +21,17 @@
(aset! b 2 (+ nconst 1)))))))
(define (emit e inst . args)
+ (define (load? i)
+ (member i '(load0 load1 loadt loadf loadnil loadvoid))) ; FIXME no load immediate here yet
(let ((bc (aref e 0)))
(if (null? args)
(if (and (eq? inst 'car)
(eq? (car bc) 'cdr))
(set-car! bc 'cadr)
- (aset! e 0 (cons inst bc)))
+ (cond ((and (eq? inst 'pop) (load? (car bc)))
+ (aset! e 0 (cdr bc)))
+ (else
+ (aset! e 0 (cons inst bc)))))
(begin
(if (memq inst '(loadv loadg setg))
(set! args (list (bcode:indexfor e (car args)))))
--- a/flisp.boot
+++ b/flisp.boot
@@ -193,8 +193,9 @@
(optargs keyargs) keyargs " " brbound (jmp brf brt brne brnn brn) "@" hex5 ref-int16-LE (jmp.l
brf.l brt.l brne.l brnn.l brn.l)) disassemble)
div #fn("7000n201k0EL;3C041EL;3404K;I504r/;I404EM:" #() div) emit
- #fn("O000z20EG82JR0120CB087<21C:08722_@900E187Pp@\x9e123124523A075082<52e1?2@30O42612752883F07882<29523:088T?1@30O^142612:52883F07882<29523:088T?1@30O^1412;C\\0822<d3=02=?14q?2@F0822>d3=02??14q?2@30O@30O412@C\\0822<d3=02A?14q?2@F0822>d3=02B?14q?2@30O@30O487<12CQ;3\x9b04882DCM087T2ECE00E82<2F7G8751PPp@x0882DCB00E82<2H87=PPp@a0882ICB00E82<2J87=PPp@J0882ECB00E82<2K87=PPp@30O;I]0412HCI0882ECB00E82<2F87=PPp@?00E7L182P8752p^140:" #(car
- cdr cadr #fn(memq) (loadv loadg setg) bcode:indexfor #fn(assq)
+ #fn("Q000z2\x8d2021?75140EG82Jk0122CB088<23C:08824_@R0125CE08788<513;00E88=p@900E188Pp@\x9e126127523A078082<52e1?2@30O42912:52893F07;82<2<523:089T?1@30O^142912=52893F07;82<2<523:089T?1@30O^1412>C\\0822?d3=02@?14q?2@F0822Ad3=02B?14q?2@30O@30O412CC\\0822?d3=02D?14q?2@F0822Ad3=02E?14q?2@30O@30O488<12FQ;3\x9b04892GCM088T2HCE00E82<2I7J8851PPp@x0892GCB00E82<2K88=PPp@a0892LCB00E82<2M88=PPp@J0892HCB00E82<2N88=PPp@30O;I]0412KCI0892HCB00E82<2I88=PPp@?00E7O182P8852p^140:" #(#0#
+ #fn("7000n17002162:" #(member (load0 load1 loadt loadf loadnil loadvoid)) load?) car cdr cadr pop
+ #fn(memq) (loadv loadg setg) bcode:indexfor #fn(assq)
((loadv loadv.l) (loadg loadg.l) (setg setg.l) (loada loada.l) (seta seta.l) (box box.l)) > 255
((loadc loadc.l)) loada (0) loada0 (1) loada1 loadc loadc0 loadc1 brf not null? brn cddr brt eq?
brne brnn nreconc) emit)