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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
module AST.Ident where
import AST.Span (Span, virtualSpan)
data Ident = Ident
{ idSpan :: Span
, idName :: String
, idUnique :: Int
}
data QualIdent = QualIdent
{ qidModule :: Maybe ModuleIdent
, qidIdent :: Ident
}
data ModuleIdent = ModuleIdent
{ midSpan :: Span
, midQualifiers :: [String]
}
data SymIdent = SymIdent (Maybe Span) Ident (Maybe Span)
data SymQualIdent = SymQualIdent (Maybe Span) QualIdent (Maybe Span)
globalScope :: Int
globalScope = 0
mkIdent :: String -> Ident
mkIdent x = Ident virtualSpan x globalScope
mkSQIdent :: QualIdent -> SymQualIdent
mkSQIdent qi = SymQualIdent Nothing qi Nothing
qualify :: Ident -> QualIdent
qualify = QualIdent Nothing
qualifyWith :: ModuleIdent -> Ident -> QualIdent
qualifyWith = QualIdent . Just
tupleId :: Int -> Ident
tupleId n
| n > 1 = mkIdent $ '(' : replicate (n - 1) ',' ++ ")"
| otherwise = error $ "ExtendAbstractCurry.tupleId: wrong arity " ++ show n
nilId :: Ident
nilId = mkIdent "[]"
consId :: Ident
consId = mkIdent ":"
unitId :: Ident
unitId = mkIdent "()"
listId :: Ident
listId = mkIdent "[]"
qUnitId :: QualIdent
qUnitId = qualify unitId
qListId :: QualIdent
qListId = qualify listId
qTupleId :: Int -> QualIdent
qTupleId = qualify . tupleId
qNilId :: QualIdent
qNilId = qualify nilId
qConsId :: QualIdent
qConsId = qualify consId
qEnumFromId :: QualIdent
qEnumFromId = qualifyWith preludeMIdent (mkIdent "enumFrom")
qEnumFromThenId :: QualIdent
qEnumFromThenId = qualifyWith preludeMIdent (mkIdent "enumFromThen")
qEnumFromToId :: QualIdent
qEnumFromToId = qualifyWith preludeMIdent (mkIdent "enumFromTo")
qEnumFromThenToId :: QualIdent
qEnumFromThenToId = qualifyWith preludeMIdent (mkIdent "enumFromThenTo")
qNegateId :: QualIdent
qNegateId = qualifyWith preludeMIdent (mkIdent "negate")
qFlip :: QualIdent
qFlip = qualifyWith preludeMIdent (mkIdent "flip")
qIfThenElseId :: QualIdent
qIfThenElseId = qualifyWith preludeMIdent (mkIdent "if_then_else")
preludeMIdent :: ModuleIdent
preludeMIdent = ModuleIdent virtualSpan ["Prelude"]
|