better primitives support for bit operations
authorAndy Wingo <wingo@pobox.com>
Sun, 15 Apr 2012 20:39:56 +0000 (13:39 -0700)
committerAndy Wingo <wingo@pobox.com>
Mon, 23 Apr 2012 19:52:24 +0000 (21:52 +0200)
* module/language/tree-il/primitives.scm
  (*interesting-primitive-names*): Add lognot.
  (*effect-free-primitives*): Add ash, logand, logior, logxor, and
  lognot.
  (logior, logand): Define associative expanders.

module/language/tree-il/primitives.scm

index 704f7c2..dba31bd 100644 (file)
@@ -46,7 +46,7 @@
     memq memv
     = < > <= >= zero?
     + * - / 1- 1+ quotient remainder modulo
-    ash logand logior logxor
+    ash logand logior logxor lognot
     not
     pair? null? list? symbol? vector? string? struct? number? char?
 
   `(values
     eq? eqv? equal?
     = < > <= >= zero?
+    ash logand logior logxor lognot
     + * - / 1- 1+ quotient remainder modulo
     not
     pair? null? list? symbol? vector? struct? string? number? char?
   (x) (/ 1 x)
   (x y z . rest) (/ x (* y z . rest)))
   
+(define-primitive-expander logior
+  () 0
+  (x) (logior x 0)
+  (x y) (logior x y)
+  (x y z . rest) (logior x (logior y z . rest)))
+
+(define-primitive-expander logand
+  () -1
+  (x) (logand x -1)
+  (x y) (logand x y)
+  (x y z . rest) (logand x (logand y z . rest)))
+
 (define-primitive-expander caar (x) (car (car x)))
 (define-primitive-expander cadr (x) (car (cdr x)))
 (define-primitive-expander cdar (x) (cdr (car x)))