-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSpadNodeFactory.spad
92 lines (82 loc) · 2.85 KB
/
SpadNodeFactory.spad
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
)abbrev package SNFAC SpadNodeFactory
SpadNodeFactory() : Exports == Implementation where
)include SpadTypeDefs.inc
mt ==> nodeMappingType
Exports ==> with
booleanType : () -> N
floatType : () -> N
integerType : () -> N
nonNegativeIntegerType : () -> N
positiveIntegerType : () -> N
outputFormType : () -> N
stringType : () -> N
symbolType : () -> N
voidType : () -> N
categoryType : () -> N
baseType : () -> N
undefinedType : () -> N
setCategoryType : () -> N
orderedSetType : () -> N
typeVar : () -> N
typeVar : PI -> N
typeVar : (PI, PI) -> N
nodeRef : (PI, PI) -> N
makeRecordFunList : N -> List(TD)
makeUnionFunList : N -> List(TD)
Implementation ==> add
booleanType () == nodeApp(['Boolean], [])
floatType () == nodeApp(['DoubleFloat], [])
integerType () == nodeApp(['Integer], [])
nonNegativeIntegerType () == nodeApp(['NonNegativeInteger], [])
positiveIntegerType () == nodeApp(['PositiveInteger], [])
outputFormType () == nodeApp(['OutputForm], [])
stringType () == nodeApp(['String], [])
symbolType () == nodeApp(['Symbol], [])
voidType () == nodeApp(['Void], [])
categoryType () == nodeApp(['Category], [])
baseType () == nodeApp(['Type], [])
setCategoryType () == nodeApp(['SetCategory], [])
orderedSetType () == nodeApp(['OrderedSet], [])
undefinedType() == [["%undef"]$MR]
typeVar() == [[0, 0]$TV]
typeVar(j) == [[0, j]$TV]
typeVar(i, j) == [[i, j]$TV]
nodeRef(i, j) == [[i, j]$NR]
makeRecordFunList n ==
r := n :: RT
funs : List(TD) :=
([[['=], mt([n, n], booleanType())],
[['~=], mt([n, n], booleanType())],
[['copy], mt([n], n)],
[['coerce], mt([n], outputFormType())],
[['construct], mt([f.type for f in fields r], n)]
])
for f in fields r repeat
s : N := [string(f.expr :: Symbol)]
r : N := f.type
funs := ([[f.expr, s],
[['elt], mt([n, s], r)],
[['setelt!], mt([n, s, r], r)], :funs])
funs
makeUnionFunList n ==
u := n :: UT
funs : List(TD) :=
([[['=], mt([n, n], booleanType())],
[['~=], mt([n, n], booleanType())],
[['coerce], mt([n], outputFormType())]
])
vs := variants u
if typeDecl? vs.1 then
for v in vs repeat
td := v :: TD
s : N := [string(td.expr :: Symbol)]
-- PARSER BUG: split into three lines and the parser will fail
funs := [[['construct], mt([td.type], n)], [td.expr, s],
[['elt], mt([n, s], td.type)], :funs]
else
for v in vs repeat
funs := [[['construct], mt([v], n)],
[['coerce], mt([n], v)], :funs]
if string? v then
funs := [[[v :: String :: Symbol], v], :funs]
funs