-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtrampoline.py
More file actions
28 lines (23 loc) · 734 Bytes
/
trampoline.py
File metadata and controls
28 lines (23 loc) · 734 Bytes
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
# -*- Mode: Python -*-
import ast
import sys
from transform import *
class trampoline (transformer):
def invoke_continuation (self, name, dead=False):
if dead:
return dead_cont (lambda: Call ('schedule', [name], NullCont))
else:
return make_cont (lambda var: Call ('schedule', [name, var], NullCont))
def dofile (path):
import os
cps = transform (path, trampoline)
base, ext = os.path.splitext (path)
fout = open (base + '.cps.py', 'wb')
fout.write (b'\nfrom scheduler import schedule, run\n\n')
w = writer (fout)
cps.emit_all (w)
fout.write (b'\nrun()\n')
fout.close()
if __name__ == '__main__':
for path in sys.argv[1:]:
dofile (path)