Skip to content

Commit

Permalink
Eval relational operators in eval-parsed-c-expression
Browse files Browse the repository at this point in the history
This case arose when trying to deal with the following C macro

#define CTRL(x) ((x) >= 'a' && (x) <= 'z' ? \
        ((x) - 'a' + 1) : (((x) - 'A' + 1) & 0x7f))

as found in FreeBSD's <sys/ttydefaults.h>
  • Loading branch information
xrme committed Aug 10, 2024
1 parent f9466ed commit f9650bc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions library/parse-ffi.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
constant-alist))
(else (eval-parsed-c-expression (third operands)
constant-alist)))
(if (= test 1) then else)))
(if (not (eql test 0)) then else)))
(t
(if (typep operator 'foreign-type)
operator
Expand Down Expand Up @@ -330,7 +330,14 @@
(progn
(%int-to-ptr (logand b #xffffffff)))))))
(c::== (if (= a b) 1 0))
(t
(c::!= (if (/= a b) 1 0))
(c::> (if (> a b) 1 0))
(c::< (if (< a b) 1 0))
(c::>= (if (>= a b) 1 0))
(c::<= (if (<= a b) 1 0))
(c::&& (if (or (eql a 0) (eql b 0)) 0 1))
(c::\|\| (if (and (eql a 0) (eql b 0)) 0 1))
(t
;;(break "binary op = ~s ~s ~s" operator a b)
nil))))
(t
Expand Down

0 comments on commit f9650bc

Please sign in to comment.