-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMachineSize.hs
29 lines (23 loc) · 1.03 KB
/
MachineSize.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- @author: Joanna Biega
-- machine size measuring module
module MachineSize where
import Prelude hiding (lex)
import AST
msize :: Character -> Integer
msize character = sum (map (msizeTerm.snd) character)
msizeTerm :: Term -> Integer
msizeTerm (TmIf cond tt elifs tf) = let msize_elifs = sum (map (\(x,y) -> (msizeCondition x) + (msizeTerm y)) elifs)
in (msizeCondition cond) + (msizeTerm tt) + (msize_elifs) + (msizeTerm tf)
msizeTerm (TmDecision TmCurrent _) = 3
msizeTerm (TmDecision _ _) = 4
msizeTerm (TmCase _ arms def) = let msize_arms = sum (map (\(_,y) -> (msizeTerm y)) arms)
in 10 + msize_arms + (mspan arms) + (msizeTerm def)
mspan :: [(ValueSet, Term)] -> Integer
mspan arms = let all_labels = concat (map fst arms) in
maximum all_labels - minimum all_labels + 1
msizeCondition :: Condition -> Integer
msizeCondition (TmEquals _ _ _) = 6
msizeCondition (TmAnd tests _) = sum (map msizeCondition tests)
msizeCondition (TmOr tests _) = sum (map msizeCondition tests)
msizeCondition TmFalse = 0
msizeCondition TmTrue = 0