-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathontooid.m
94 lines (83 loc) · 1.93 KB
/
ontooid.m
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
export OpNameToOID
const OpNameToOID <- immutable object OpNameToOID
const table : SITable <- SITable.create[513]
var count : Integer <- 0
var opoidname : String <- nil
var initialized : Boolean <- false
export function Lookup [name : String] -> [r : Integer]
if !initialized then
self.loadGlobals
end if
r <- table.Lookup[name]
if r == nil then
r <- count
table.insert[name, r]
count <- count + 1
if opoidname !== nil then
const file <- OutStream.toUnix[opoidname, "a"]
if file == nil then
const env : EnvironmentType <- Environment$env
env.SemanticError[1, "Can't open op-oid file \"%s\"", {opoidname}]
else
file.putString[name]
file.putChar['\n']
file.close
end if
end if
end if
end Lookup
operation loadGlobals
var file : InStream
var name : String
var root : String
count <- 0
primitive "GETROOTDIR" [root] <- []
begin
file <- InStream.fromUnix[root||"/lib/opoid", "r"]
failure file <- nil end failure
end
if file !== nil then
loop
begin
name <- file.getString
failure
name <- nil
end failure
end
exit when name == nil
name <- name[0, name.length - 1]
table.Insert[name, count]
count <- count + 1
end loop
file.close
end if
count <- 2000
initialized <- true
end loadGlobals
export operation load[fn : String]
var file : InStream
var name : String
opoidname <- fn || ".opd"
table.reset
if ! Environment$env$compilingBuiltins then
self.loadGlobals
end if
begin
file <- InStream.fromUnix[opoidname, "r"]
failure file <- nil end failure
end
if file !== nil then
loop
begin
name <- file.getString
failure name <- nil end failure
end
exit when name == nil
name <- name[0, name.length - 1]
table.Insert[name, count]
count <- count + 1
end loop
file.close
end if
end load
end OpNameToOID