Uploaded tinypy sources.

git-svn-id: svn://kolibrios.org@1913 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
jaeger
2011-03-31 09:59:54 +00:00
parent 00ac1c33b5
commit 9fd32b8cdf
34 changed files with 9410 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
print("Starting py2bc")
if not (str(1.0) == "1"):
from boot import *
import tokenize,parse,encode
def _compile(s,fname):
tokens = tokenize.tokenize(s)
t = parse.parse(s,tokens)
r = encode.encode(fname,s,t)
return r
def _import(name):
if name in MODULES:
return MODULES[name]
py = name+".py"
tpc = name+".tpc"
print("CP")
if exists(py):
if not exists(tpc) or mtime(py) > mtime(tpc):
s = load(py)
code = _compile(s,py)
save(tpc,code)
if not exists(tpc): raise
code = load(tpc)
g = {'__name__':name,'__code__':code}
g['__dict__'] = g
MODULES[name] = g
exec(code,g)
return g
def _init():
BUILTINS['compile'] = _compile
BUILTINS['import'] = _import
def import_fname(fname,name):
g = {}
g['__name__'] = name
MODULES[name] = g
s = load(fname)
code = _compile(s,fname)
g['__code__'] = code
exec(code,g)
return g
def tinypy():
print("tinypy called")
return import_fname(ARGV[0],'__main__')
def main(src,dest):
s = load(src)
r = _compile(s,src)
save(dest,r)
if __name__ == '__main__':
print("Running main")
main(ARGV[1],ARGV[2])