classpool: staticfields calculation: bugfix
authorBernhard Urban <lewurm@gmail.com>
Sun, 20 May 2012 19:49:22 +0000 (21:49 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sun, 20 May 2012 19:49:22 +0000 (21:49 +0200)
span doesn't do what I believed it does (it aborts on first predicate match)

Mate/ClassPool.hs
tests/Generics1.java

index 816c73b98ef4b7b5e1e9922838dae4776d3e915f..8b3e8a961fdb71af97418061fe2f23f8ceeb3041 100644 (file)
@@ -197,7 +197,14 @@ calculateFields :: Class Direct -> Maybe ClassInfo -> IO (FieldMap, FieldMap)
 calculateFields cf superclass = do
     -- TODO(bernhard): correct sizes. int only atm
 
-    let (sfields, ifields) = span (S.member ACC_STATIC . fieldAccessFlags) (classFields cf)
+    -- TODO(bernhard): nicer replacement for `myspan'
+    let (sfields, ifields) = myspan (S.member ACC_STATIC . fieldAccessFlags) (classFields cf)
+        myspan :: (a -> Bool) -> [a] -> ([a], [a])
+        myspan _ [] = ([],[])
+        myspan p (x:xs)
+          | p x = (x:ns, ni)
+          | otherwise = (ns, x:ni)
+          where (ns,ni) = myspan p xs
 
     staticbase <- mallocClassData $ fromIntegral (length sfields) * 4
     let i_sb = fromIntegral $ ptrToIntPtr staticbase
index 4e3d2620d8b15eb6611e2443e1a2c145847f5792..fa093ca2611da4f32ec1042de1cb9067e2663ee0 100644 (file)
@@ -7,6 +7,7 @@ public class Generics1 implements Cmp<Integer> {
        }
 
        public static Cmp<Integer> sb = new Generics1();
+       public static int lalelu = 0;
 
        public static void main(String []args) {
                Generics1 foo = new Generics1();