Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/FLINT/opt/optutils.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/FLINT/opt/optutils.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 202 - (view) (download)

1 : monnier 163 (* copyright 1998 YALE FLINT PROJECT *)
2 :     (* monnier@cs.yale.edu *)
3 :    
4 :     signature OPT_UTILS =
5 :     sig
6 :    
7 : monnier 184 datatype ('a,'b) either = A of 'a | B of 'b
8 :    
9 : monnier 163 (* takes the fk of a function and returns the fk of the wrapper
10 :     * along with the new fk of the actual body *)
11 :     val fk_wrap : FLINT.fkind * FLINT.lty list option ->
12 :     (FLINT.fkind * FLINT.fkind)
13 :    
14 :     (* this is a known APL function, but I don't know its real name *)
15 :     val filter : bool list * 'a list -> 'a list
16 : monnier 199
17 :     (* A less brain-dead version of ListPair.all: returns false if
18 :     * length l1 <> length l2 *)
19 :     val ListPair_all : ('a * 'b -> bool) -> 'a list * 'b list -> bool
20 : monnier 202
21 :     (* This is not a proper transposition in that the order is reversed
22 :     * in the following way: transpose x = map rev (proper_trans x) *)
23 :     exception Unbalanced
24 :     val transpose : 'a list list -> 'a list list
25 :     val foldl3 : ('a * 'b * 'c * 'd -> 'd) -> 'd -> 'a list * 'b list * 'c list -> 'd
26 : monnier 163 end
27 :    
28 :     structure OptUtils :> OPT_UTILS =
29 :     struct
30 :     local structure F = FLINT
31 :     structure LK = LtyKernel
32 :     in
33 : monnier 184 datatype ('a,'b) either = A of 'a | B of 'b
34 :    
35 : monnier 163 fun bug msg = ErrorMsg.impossible ("OptUtils: "^msg)
36 :    
37 : monnier 184 fun fk_wrap ({inline,known,isrec,cconv},rtys') =
38 :     let val cconv' =
39 :     case cconv
40 :     of F.CC_FUN(LK.FF_VAR(f1,f2)) => F.CC_FUN(LK.FF_VAR(true, f2))
41 :     | (F.CC_FCT | F.CC_FUN(LK.FF_FIXED)) => cconv
42 :     val isrec' = Option.map (fn ltys => (ltys, F.LK_UNKNOWN)) rtys'
43 :     in ({isrec=isrec, known=known, cconv=cconv, inline=F.IH_ALWAYS},
44 :     {isrec=isrec', known=true, cconv=cconv', inline=inline})
45 : monnier 163 end
46 :    
47 :     fun filter ([],[]) = []
48 :     | filter (true::fs,x::xs) = x::(filter(fs, xs))
49 :     | filter (false::fs,x::xs) = (filter(fs, xs))
50 :     | filter _ = bug "unmatched list length in filter"
51 :    
52 : monnier 199 fun ListPair_all pred =
53 :     let fun allp (a::r1, b::r2) = pred(a, b) andalso allp (r1, r2)
54 :     | allp ([],[]) = true
55 :     | allp _ = false
56 :     in allp
57 :     end
58 :    
59 : monnier 202 exception Unbalanced
60 :     fun transpose [] = []
61 :     | transpose (xs::xss) =
62 :     let fun tr [] accs = accs
63 :     | tr (xs::xss) accs =
64 :     let fun f [] [] = []
65 :     | f (x::xs) (acc::accs) = (x::acc)::(f xs accs)
66 :     | f _ _ = raise Unbalanced
67 :     in tr xss (f xs accs)
68 :     end
69 :     in tr xss (map (fn x => [x]) xs)
70 :     end
71 :    
72 :     fun foldl3 f =
73 :     let fun l s ([],[],[]) = s
74 :     | l s (x1::x1s,x2::x2s,x3::x3s) = l (f(x1,x2,x3,s)) (x1s,x2s,x3s)
75 :     | l _ _ = raise Unbalanced
76 :     in l
77 :     end
78 :    
79 : monnier 163 end
80 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0