Commit 500c3ca1 authored by Guido van Rossum's avatar Guido van Rossum

Add -m option to perform precompilation (i.e. macro expansion) only.

parent de880a7b
...@@ -105,17 +105,22 @@ FILE = "test/test1.xml" ...@@ -105,17 +105,22 @@ FILE = "test/test1.xml"
def main(): def main():
noVersionTest = 0 noVersionTest = 0
macros = 0
compile = 0 compile = 0
try: try:
opts, args = getopt.getopt(sys.argv[1:], "cn") opts, args = getopt.getopt(sys.argv[1:], "cmn")
except getopt.error, msg: except getopt.error, msg:
sys.stderr.write("%s\n" % str(msg)) sys.stderr.write("%s\n" % str(msg))
sys.stderr.write("usage: driver.py [-n] [file]\n") sys.stderr.write("usage: driver.py [-c] [-m] [-n] [file]\n")
sys.stderr.write("-n turns of the Python 1.5.2 test\n") sys.stderr.write("-c -- compiled mode (faster)\n")
sys.stderr.write("-m -- macro expansion only\n")
sys.stderr.write("-n -- turn of the Python 1.5.2 test\n")
sys.exit(2) sys.exit(2)
for o, a in opts: for o, a in opts:
if o == '-c': if o == '-c':
compile = not compile compile = 1
if o == '-m':
macros = 1
if o == '-n': if o == '-n':
noVersionTest = 1 noVersionTest = 1
if not noVersionTest: if not noVersionTest:
...@@ -128,8 +133,11 @@ def main(): ...@@ -128,8 +133,11 @@ def main():
else: else:
file = FILE file = FILE
doc = parsefile(file) doc = parsefile(file)
if compile: if macros or compile:
it = compiletree(doc) if macros:
it = precompiletree(doc)
else:
it = compiletree(doc)
interpretit(it) interpretit(it)
else: else:
doc = talizetree(doc) doc = talizetree(doc)
...@@ -156,6 +164,10 @@ def talizetree(root, dom=None, engine=None): ...@@ -156,6 +164,10 @@ def talizetree(root, dom=None, engine=None):
engine = DummyEngine() engine = DummyEngine()
return TALVisitor(root, dom, engine)() return TALVisitor(root, dom, engine)()
def precompiletree(root):
from TALCompiler import METALCompiler
return METALCompiler(root)()
def compiletree(root): def compiletree(root):
from TALCompiler import TALCompiler from TALCompiler import TALCompiler
return TALCompiler(root)() return TALCompiler(root)()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment