File: mychecker.py

package info (click to toggle)
psyco-doc 1.6-1
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 1,832 kB
  • ctags: 3,236
  • sloc: ansic: 23,895; python: 5,646; perl: 1,309; makefile: 153
file content (78 lines) | stat: -rw-r--r-- 1,825 bytes parent folder | download | duplicates (7)
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
import re, dis
recase = re.compile(r'case\s+([A-Z_][A-Z_+0-9]*)\s*[:]')
rebin  = re.compile(r'BINARY_OPCODE[(]([A-Z_][A-Z_+0-9]*),')
remiss = re.compile(r'[/*]*MISSING_OPCODE[(]([A-Z_][A-Z_+0-9]*)[)]')

if dis.opname[86] == 'YIELD_STMT':
    dis.opname[86] = 'YIELD_VALUE'

inswitch = 0
lst = []
miss = []
warn = 0

def register(op):
    global warn
    print "%29s" % op,
    if op not in lst:
        lst.append(op)
    if op not in dis.opname:
        print "%29s" % "<--- unknown opcode",
        #warn += 1
    print

print "+++ Found +++"
print

for line in open('Python/pycompiler.c').readlines():
    line = line.strip()
    if line.startswith('switch (opcode)'):
        inswitch = 1
    elif line.endswith('/* switch (opcode) */'):
        inswitch = 0
    elif inswitch:
        m = recase.match(line) or rebin.match(line)
        if m:
            register(m.group(1))
        else:
            m = remiss.match(line)
            if m:
                miss.append(m.group(1))
print
print

assert not inswitch

print '+++ Not implemented +++'
print
for i, opname in zip(range(1,256), dis.opname[1:]):
    if not opname.startswith('<') and opname not in lst:
        print "%4d %29s" % (i, opname),
        if opname not in miss:
            print "%29s" % "<--- forgotten ?",
            warn += 1
        else:
            miss.remove(opname)
        print
print

for opname in miss:
    print "%29s" % opname, "%29s" % "<--- marked as missing, don't know why"

print

for line in open('mergepoints.c').readlines():
    for word in lst:
        if line.find(word) >= 0:
            lst.remove(word)
            break

for word in lst:
    print '!!! Not found in mergepoints.c !!!'
    print
    print word
    print
    warn += 1

if warn:
    print '                               !!! %d warning(s) !!!' % warn