-
Notifications
You must be signed in to change notification settings - Fork 0
/
STypeUtils.ulam
78 lines (62 loc) · 1.44 KB
/
STypeUtils.ulam
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
/**
Static (stable?) type value that can be used
to search for or build atoms.
*/
transient STypeUtils + Fail {
typedef EventWindow.SiteNum SiteNum;
typedef Unsigned SType;
constant SType cEMPTY = 0;
constant SType cDEFAULT = 1;
constant SType cPACKAGE = 2;
constant SType cMEMBRANE = 3;
constant SType cEXEC = 4;
constant SType cTREE_BUILDER = 5;
AtomUtils au;
EventWindow ew;
SType getSType(SiteNum site) {
return getSType(ew[site]);
}
SType getSType(C2D coord) {
return getSType(ew[coord]);
}
SType getSType(Atom& atom) {
if (au.isEmpty(atom))
return cEMPTY;
if (atom is Package)
return cPACKAGE;
if (atom is Membrane)
return cMEMBRANE;
if (atom is Exec)
return cEXEC;
if (atom is TreeBuilder)
return cTREE_BUILDER;
return cDEFAULT;
}
Atom make(SType stype) {
if (stype == cPACKAGE) {
Package atom;
return atom;
}
if (stype == cMEMBRANE) {
Membrane atom;
return atom;
}
if (stype == cEXEC) {
Exec exec;
return exec;
}
if (stype == cTREE_BUILDER) {
TreeBuilder builder;
return builder;
}
// keeping compiler happy by always returning something
if (stype != cEMPTY)
fail("unknown SType");
Empty atom;
return atom;
}
Unsigned getType(SType stype) {
Atom atom = make(stype);
return (Unsigned) au.getType(atom);
}
}