summary refs log tree commit diff stats
path: root/rod/cgmeth.nim
diff options
context:
space:
mode:
Diffstat (limited to 'rod/cgmeth.nim')
-rwxr-xr-xrod/cgmeth.nim201
1 files changed, 0 insertions, 201 deletions
diff --git a/rod/cgmeth.nim b/rod/cgmeth.nim
deleted file mode 100755
index fe1b581f9..000000000
--- a/rod/cgmeth.nim
+++ /dev/null
@@ -1,201 +0,0 @@
-#
-#
-#           The Nimrod Compiler
-#        (c) Copyright 2010 Andreas Rumpf
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
-
-# This module implements code generation for multi methods.
-
-import 
-  options, ast, astalgo, msgs, idents, rnimsyn, types, magicsys
-
-proc methodDef*(s: PSym)
-proc methodCall*(n: PNode): PNode
-proc generateMethodDispatchers*(): PNode
-# implementation
-
-proc genConv(n: PNode, d: PType, downcast: bool): PNode = 
-  var 
-    dest, source: PType
-    diff: int
-  dest = skipTypes(d, abstractPtrs)
-  source = skipTypes(n.typ, abstractPtrs)
-  if (source.kind == tyObject) and (dest.kind == tyObject): 
-    diff = inheritanceDiff(dest, source)
-    if diff == high(int): InternalError(n.info, "cgmeth.genConv")
-    if diff < 0: 
-      result = newNodeIT(nkObjUpConv, n.info, d)
-      addSon(result, n)
-      if downCast: InternalError(n.info, "cgmeth.genConv: no upcast allowed")
-    elif diff > 0: 
-      result = newNodeIT(nkObjDownConv, n.info, d)
-      addSon(result, n)
-      if not downCast: 
-        InternalError(n.info, "cgmeth.genConv: no downcast allowed")
-    else: 
-      result = n
-  else: 
-    result = n
-  
-proc methodCall(n: PNode): PNode = 
-  var disp: PSym
-  result = n
-  disp = lastSon(result.sons[0].sym.ast).sym
-  result.sons[0].sym = disp
-  for i in countup(1, sonsLen(result) - 1): 
-    result.sons[i] = genConv(result.sons[i], disp.typ.sons[i], true)
-  
-var gMethods: seq[TSymSeq]
-
-proc sameMethodBucket(a, b: PSym): bool = 
-  var aa, bb: PType
-  result = false
-  if a.name.id != b.name.id: return 
-  if sonsLen(a.typ) != sonsLen(b.typ): 
-    return                    # check for return type:
-  if not sameTypeOrNil(a.typ.sons[0], b.typ.sons[0]): return 
-  for i in countup(1, sonsLen(a.typ) - 1): 
-    aa = a.typ.sons[i]
-    bb = b.typ.sons[i]
-    while true: 
-      aa = skipTypes(aa, {tyGenericInst})
-      bb = skipTypes(bb, {tyGenericInst})
-      if (aa.kind == bb.kind) and (aa.kind in {tyVar, tyPtr, tyRef}): 
-        aa = aa.sons[0]
-        bb = bb.sons[0]
-      else: 
-        break 
-    if sameType(aa, bb) or
-        (aa.kind == tyObject) and (bb.kind == tyObject) and
-        (inheritanceDiff(bb, aa) < 0): 
-      nil
-    else: 
-      return 
-  result = true
-
-proc methodDef(s: PSym) = 
-  var 
-    L, q: int
-    disp: PSym
-  L = len(gMethods)
-  for i in countup(0, L - 1): 
-    if sameMethodBucket(gMethods[i][0], s): 
-      add(gMethods[i], s)     # store a symbol to the dispatcher:
-      addSon(s.ast, lastSon(gMethods[i][0].ast))
-      return 
-  add(gMethods, @ [s])        # create a new dispatcher:
-  disp = copySym(s)
-  disp.typ = copyType(disp.typ, disp.typ.owner, false)
-  if disp.typ.callConv == ccInline: disp.typ.callConv = ccDefault
-  disp.ast = copyTree(s.ast)
-  disp.ast.sons[codePos] = nil
-  if s.typ.sons[0] != nil: 
-    disp.ast.sons[resultPos].sym = copySym(s.ast.sons[resultPos].sym)
-  addSon(s.ast, newSymNode(disp))
-
-proc relevantCol(methods: TSymSeq, col: int): bool = 
-  var t: PType
-  # returns true iff the position is relevant
-  t = methods[0].typ.sons[col]
-  result = false
-  if skipTypes(t, skipPtrs).kind == tyObject: 
-    for i in countup(1, high(methods)): 
-      if not SameType(methods[i].typ.sons[col], t): 
-        return true
-  
-proc cmpSignatures(a, b: PSym, relevantCols: TIntSet): int = 
-  var 
-    d: int
-    aa, bb: PType
-  result = 0
-  for col in countup(1, sonsLen(a.typ) - 1): 
-    if intSetContains(relevantCols, col): 
-      aa = skipTypes(a.typ.sons[col], skipPtrs)
-      bb = skipTypes(b.typ.sons[col], skipPtrs)
-      d = inheritanceDiff(aa, bb)
-      if (d != high(int)): 
-        return d
-  
-proc sortBucket(a: var TSymSeq, relevantCols: TIntSet) = 
-  # we use shellsort here; fast and simple
-  var 
-    N, j, h: int
-    v: PSym
-  N = len(a)
-  h = 1
-  while true: 
-    h = 3 * h + 1
-    if h > N: break 
-  while true: 
-    h = h div 3
-    for i in countup(h, N - 1): 
-      v = a[i]
-      j = i
-      while cmpSignatures(a[j - h], v, relevantCols) >= 0: 
-        a[j] = a[j - h]
-        j = j - h
-        if j < h: break 
-      a[j] = v
-    if h == 1: break 
-  
-proc genDispatcher(methods: TSymSeq, relevantCols: TIntSet): PSym = 
-  var 
-    disp, cond, call, ret, a, isn: PNode
-    base, curr, ands, iss: PSym
-    paramLen: int
-  base = lastSon(methods[0].ast).sym
-  result = base
-  paramLen = sonsLen(base.typ)
-  disp = newNodeI(nkIfStmt, base.info)
-  ands = getSysSym("and")
-  iss = getSysSym("is")
-  for meth in countup(0, high(methods)): 
-    curr = methods[meth]      # generate condition:
-    cond = nil
-    for col in countup(1, paramLen - 1): 
-      if IntSetContains(relevantCols, col): 
-        isn = newNodeIT(nkCall, base.info, getSysType(tyBool))
-        addSon(isn, newSymNode(iss))
-        addSon(isn, newSymNode(base.typ.n.sons[col].sym))
-        addSon(isn, newNodeIT(nkType, base.info, curr.typ.sons[col]))
-        if cond != nil: 
-          a = newNodeIT(nkCall, base.info, getSysType(tyBool))
-          addSon(a, newSymNode(ands))
-          addSon(a, cond)
-          addSon(a, isn)
-          cond = a
-        else: 
-          cond = isn
-    call = newNodeI(nkCall, base.info)
-    addSon(call, newSymNode(curr))
-    for col in countup(1, paramLen - 1): 
-      addSon(call, genConv(newSymNode(base.typ.n.sons[col].sym), 
-                           curr.typ.sons[col], false))
-    if base.typ.sons[0] != nil: 
-      a = newNodeI(nkAsgn, base.info)
-      addSon(a, newSymNode(base.ast.sons[resultPos].sym))
-      addSon(a, call)
-      ret = newNodeI(nkReturnStmt, base.info)
-      addSon(ret, a)
-    else: 
-      ret = call
-    a = newNodeI(nkElifBranch, base.info)
-    addSon(a, cond)
-    addSon(a, ret)
-    addSon(disp, a)
-  result.ast.sons[codePos] = disp
-
-proc generateMethodDispatchers(): PNode = 
-  var relevantCols: TIntSet
-  result = newNode(nkStmtList)
-  for bucket in countup(0, len(gMethods) - 1): 
-    IntSetInit(relevantCols)
-    for col in countup(1, sonsLen(gMethods[bucket][0].typ) - 1): 
-      if relevantCol(gMethods[bucket], col): IntSetIncl(relevantCols, col)
-    sortBucket(gMethods[bucket], relevantCols)
-    addSon(result, newSymNode(genDispatcher(gMethods[bucket], relevantCols)))
-
-gMethods = @[]
100 committer David Morgan <djm_uk@protonmail.com> 2024-09-07 16:58:59 +0100 Add eza config' href='/djm/dotfiles/commit/nix-conf/home/includes/zsh.nix?id=a901cdabc298fe37ede23cfd8c2e459bbbac917d'>a901cda ^
726b370 ^
a901cda ^
fb46fc7 ^
e8eba7e ^
fb46fc7 ^
95bc01f ^









fb46fc7 ^
cf736c3 ^
79cdd27 ^

a6ebfc0 ^



95bc01f ^
c6b5676 ^
a434298 ^






4a9d3dc ^
95bc01f ^




a434298 ^

95bc01f ^
589ed39 ^
6942ab1 ^

fb42e8d ^

18f7371 ^
95bc01f ^



a80fb84 ^
a80fb84 ^
6942ab1 ^
a5035cb ^


a434298 ^
293b3f8 ^
a92ce69 ^
a434298 ^





293b3f8 ^




a434298 ^

a434298 ^

a434298 ^
ba35d6c ^

b042b51 ^
ba35d6c ^
a434298 ^
e8eba7e ^
a434298 ^
e8eba7e ^
a434298 ^


e8eba7e ^


a434298 ^
e8eba7e ^
589ed39 ^
0a7b9c8 ^


















e078ede ^
a434298 ^
5b7ad8f ^


6fa3a55 ^




95ed21b ^
6fa3a55 ^
























5c9dab0 ^

a434298 ^
87ec731 ^
39cd18a ^







a434298 ^
87ec731 ^




981174e ^

c09daad ^
e66a4c7 ^
981174e ^
c09daad ^
87ec731 ^












1e46e31 ^




f65bef6 ^

011c3d5 ^









cf5acce ^

011c3d5 ^
cf5acce ^








011c3d5 ^
cf5acce ^
1c46d4f ^
84f071a ^
011c3d5 ^

e244cf5 ^




c08264d ^

a434298 ^


95bc01f ^

e8eba7e ^


























e8eba7e ^























95bc01f ^
a434298 ^

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370