shithub: sl

Download patch

ref: 8e5d5789171e00a9208fea587c81e7322281bbc0
parent: 9db91979e51a69f53edca7b46f84f73ae95454f9
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Dec 31 20:20:29 EST 2024

fix broken >= and <=

References: https://todo.sr.ht/~ft/femtolisp/32

--- a/compiler.lsp
+++ b/compiler.lsp
@@ -486,7 +486,7 @@
 
 ;; lambda, main compilation loop
 
-(define (fits-i8 x) (and (fixnum? x) (>= x -128) (<= x 127)))
+(define (fits-i8 x) (and (fixnum? x) (>= 127 x -128)))
 
 (define (compile-in g env tail? x (outl #f))
   (cond ((symbol? x) (compile-sym g env x #t))
--- a/flisp.boot
+++ b/flisp.boot
@@ -48,11 +48,13 @@
 	    1+ #fn("6000n10KM:" #() 1+) 1-
 	    #fn("6000n10K~:" #() 1-) 1arg-lambda? #fn("7000n10B;3E04700<51;3:04710TK62:" #(is-lambda?
   length=) 1arg-lambda?)
-	    <= #fn("9000z0700f2;I:047172052S:" #(> every nan?) <=) >
-	    #fn("<000z1\x8d\x8a620862186>1_51486<0162:" #(#0#
-							  #fn("7000n21V;IE041<0L2;3;04A<1<1=62:" #() f)) >)
-	    >= #fn("9000z0700f2;I:047172052S:" #(< every nan?) >=) Instructions
-	    #table(call.l 81  trycatch 75  largc 79  loadg.l 68  aref2 23  box 90  cadr 36  argc 62  setg 71  load0 21  vector? 45  fixnum? 41  loadc0 17  loada0 0  div0 59  keyargs 89  call 5  loada.l 69  brt.l 50  sub2 78  add2 29  loadc.l 70  loadc 9  builtin? 43  set-car! 47  brt 25  ret 10  loadi8 66  tapply 77  loadvoid 93  loada1 1  shift 46  boolean? 39  atom? 24  cdr 13  brne.l 83  / 58  loadf 31  equal? 52  apply 54  dup 11  loadt 20  jmp.l 48  null? 38  not 35  = 60  set-cdr! 30  eq? 33  * 57  load1 27  bound? 42  brf 3  function? 44  box.l 91  < 28  brnn.l 84  jmp 16  loadv 2  for 76  lvargc 80  dummy_eof 94  + 55  brne 19  compare 61  neg 37  loadv.l 67  number? 40  vargc 74  brn 85  brbound 88  vector 63  loadc1 22  setg.l 72  cons? 18  brf.l 49  aref 92  symbol? 34  aset! 64  car 12  cons 32  tcall.l 82  - 56  brn.l 86  optargs 87  closure 14  pop 4  eqv? 51  list 53  seta 15  seta.l 73  brnn 26  loadnil 65  loadg 7  loada 8  tcall 6)
+	    <= #fn("<000z1\x8d\x8a620862186>1_51486<0152S:" #(#0#
+							      #fn("7000n21J40O:1<0L2;IE0470051;I;04A<1<1=62:" #(nan?) f)) <=)
+	    > #fn("<000z1\x8d\x8a620862186>1_51486<0162:" #(#0#
+							    #fn("7000n21V;IE041<0L2;3;04A<1<1=62:" #() f)) >)
+	    >= #fn("<000z1\x8d\x8a620862186>1_51486<0152S:" #(#0#
+							      #fn("7000n21J40O:01<L2;IE0470051;I;04A<1<1=62:" #(nan?) f)) >=)
+	    Instructions #table(call.l 81  trycatch 75  largc 79  loadg.l 68  aref2 23  box 90  cadr 36  argc 62  setg 71  load0 21  vector? 45  fixnum? 41  loadc0 17  loada0 0  div0 59  keyargs 89  call 5  loada.l 69  brt.l 50  sub2 78  add2 29  loadc.l 70  loadc 9  builtin? 43  set-car! 47  brt 25  ret 10  loadi8 66  tapply 77  loadvoid 93  loada1 1  shift 46  boolean? 39  atom? 24  cdr 13  brne.l 83  / 58  loadf 31  equal? 52  apply 54  dup 11  loadt 20  jmp.l 48  null? 38  not 35  = 60  set-cdr! 30  eq? 33  * 57  load1 27  bound? 42  brf 3  function? 44  box.l 91  < 28  brnn.l 84  jmp 16  loadv 2  for 76  lvargc 80  dummy_eof 94  + 55  brne 19  compare 61  neg 37  loadv.l 67  number? 40  vargc 74  brn 85  brbound 88  vector 63  loadc1 22  setg.l 72  cons? 18  brf.l 49  aref 92  symbol? 34  aset! 64  car 12  cons 32  tcall.l 82  - 56  brn.l 86  optargs 87  closure 14  pop 4  eqv? 51  list 53  seta 15  seta.l 73  brnn 26  loadnil 65  loadg 7  loada 8  tcall 6)
 	    __init_globals #fn("5000n020w1422w3424w5476w7478w947:w;:" #(#fn("6000n0702161:" #(princ
   "#;> ")) *prompt* "/" *directory-separator* "\n" *linefeed* *stdout* *output-stream* *stdin*
 									*input-stream* *stderr*
@@ -243,7 +245,7 @@
 	    extend-env #fn("8000n370182E530P:" #(vars-to-env) extend-env) filter
 	    #fn("9000n2\x8d20210>1?65148601qe163:" #(#0#
 						     #fn("8000n382\x8d1B3Q04A1<513?0821<qPN=?2@30O41=?1@\x0e/4=:" #() filter-)) filter)
-	    fits-i8 #fn("7000n10Y;3F04700r\xb052;3:04710r\xaf62:" #(>= <=) fits-i8) foldl
+	    fits-i8 #fn("8000n10Y;3<0470r\xaf0r\xb063:" #(>=) fits-i8) foldl
 	    #fn("9000n382J401:700082<15282=63:" #(foldl) foldl) foldr #fn(":000n382J401:082<700182=5362:" #(foldr) foldr)
 	    get-defined-vars #fn("7000n170A<05161:" #(delete-duplicates) #(#2=(#fn("8000n10H340q:0<20Cj00=B3d00TR;37040Te1;IS040TB;3E0471051R;3:0471051e1;I404q:0<22C?07324A<0=52}2:q:" #(define
   caadr begin nconc #fn(map)) #(#2#)))))
binary files a/flisp.boot.builtin b/flisp.boot.builtin differ
--- a/system.lsp
+++ b/system.lsp
@@ -184,13 +184,21 @@
 (define-macro (> a . rest)
   `(< ,@(reverse! rest) ,a))
 
-(define (<= . rest)
-  (not (or (apply > rest)
-           (every nan? rest))))
+(define (<= a . rest)
+  (define (f a rest)
+    (unless (null? rest)
+      (or (< (car rest) a)
+          (nan? a)
+          (f (car rest) (cdr rest)))))
+  (not (f a rest)))
 
-(define (>= . rest)
-  (not (or (apply < rest)
-           (every nan? rest))))
+(define (>= a . rest)
+  (define (f a rest)
+    (unless (null? rest)
+      (or (< a (car rest))
+          (nan? a)
+          (f (car rest) (cdr rest)))))
+  (not (f a rest)))
 
 (define (negative? x) (< x 0))
 (define (zero? x)     (= x 0))
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -148,6 +148,12 @@
 (assert (>= "ab" "aa"))
 (assert (>= "ab" "aa" "aa"))
 
+; one or more than two arguments
+(assert (and (> 0) (< 0) (>= 0) (<= 0)))
+(assert (and (> 2 1 0) (< 0 1 2) (>= 2 1 0) (<= 0 1 2)))
+(assert (and (>= 2 1 1) (<= 1 1 2)))
+(assert (not (and (>= 2 1 2) (<= 2 1 2))))
+
 ; comparing numbers and runes
 (assert (< 9 #\newline))
 (assert (not (< 10 #\newline)))
--