Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8535 superturbo 1
import sys
2
if not "tinypy" in sys.version:
3
    from boot import *
4
 
5
import tokenize,parse,encode
6
 
7
def _compile(s,fname):
8
    tokens = tokenize.tokenize(s)
9
    t = parse.parse(s,tokens)
10
    r = encode.encode(fname,s,t)
11
    return r
12
 
13
def _import(name):
14
    if name in MODULES:
15
        return MODULES[name]
16
    py = name+".py"
17
    tpc = name+".tpc"
18
    if exists(py):
19
        if not exists(tpc) or mtime(py) > mtime(tpc):
20
            s = load(py)
21
            code = _compile(s,py)
22
            save(tpc,code)
23
    if not exists(tpc): raise
24
    code = load(tpc)
25
    g = {'__name__':name,'__code__':code}
26
    g['__dict__'] = g
27
    MODULES[name] = g
28
    exec(code,g)
29
    return g
30
 
31
 
32
def _init():
33
    BUILTINS['compile'] = _compile
34
    BUILTINS['import'] = _import
35
 
36
def import_fname(fname,name):
37
    g = {}
38
    g['__name__'] = name
39
    MODULES[name] = g
40
    s = load(fname)
41
    code = _compile(s,fname)
42
    g['__code__'] = code
43
    exec(code,g)
44
    return g
45
 
46
def tinypy():
47
    return import_fname(ARGV[0],'__main__')
48
 
49
def main(src,dest):
50
    s = load(src)
51
    r = _compile(s,src)
52
    save(dest,r)
53
 
54
if __name__ == '__main__':
55
    main(ARGV[1],ARGV[2])
56
    main(ARGV[1],ARGV[2])
57
    main(ARGV[1],ARGV[2])
58
    main(ARGV[1],ARGV[2])
59
    main(ARGV[1],ARGV[2])
60
    main(ARGV[1],ARGV[2])
61
    main(ARGV[1],ARGV[2])
62
    main(ARGV[1],ARGV[2])