Add --include-yoob-playfield-inline option (for node.js testing.)
catseye
12 years ago
248 | 248 |
"""
|
249 | 249 |
|
250 | 250 |
class Compiler(object):
|
251 | |
def __init__(self, alpaca, file):
|
|
251 |
def __init__(self, alpaca, file, options=None):
|
252 | 252 |
"""alpaca is an ALPACA description in AST form. file is a file-like
|
253 | 253 |
object to which the compiled code will be written.
|
254 | 254 |
|
255 | 255 |
"""
|
256 | 256 |
self.alpaca = alpaca
|
257 | 257 |
self.file = file
|
|
258 |
self.options = options
|
258 | 259 |
|
259 | 260 |
def compile(self):
|
260 | 261 |
bb = BoundingBox(0, 0, 0, 0)
|
|
266 | 267 |
*/
|
267 | 268 |
|
268 | 269 |
""")
|
269 | |
self.file.write(YOOB_PLAYFIELD_JS)
|
|
270 |
if self.options is not None and \
|
|
271 |
self.options.include_yoob_playfield_inline:
|
|
272 |
self.file.write(YOOB_PLAYFIELD_JS)
|
270 | 273 |
self.file.write("""
|
271 | 274 |
function in_nbhd_pred(pf, x, y, pred, nbhd) {
|
272 | 275 |
var count = 0;
|
57 | 57 |
optparser.add_option("-t", "--test",
|
58 | 58 |
action="store_true", dest="test", default=False,
|
59 | 59 |
help="run test cases and exit")
|
|
60 |
optparser.add_option("-y", "--include-yoob-playfield-inline",
|
|
61 |
action="store_true",
|
|
62 |
dest="include_yoob_playfield_inline", default=False,
|
|
63 |
help="include yoob/playfield.js (from yoob.js) "
|
|
64 |
"inline in generated Javascript (javascript "
|
|
65 |
"backend only)")
|
60 | 66 |
(options, args) = optparser.parse_args(argv[1:])
|
61 | 67 |
if options.test:
|
62 | 68 |
import doctest
|
|
84 | 90 |
# XXX generalize
|
85 | 91 |
if options.compile_to == 'javascript':
|
86 | 92 |
from alpaca.backends.javascript import Compiler
|
87 | |
compiler = Compiler(ast, sys.stdout)
|
|
93 |
compiler = Compiler(ast, sys.stdout, options=options)
|
88 | 94 |
success = compiler.compile()
|
89 | 95 |
if success:
|
90 | 96 |
sys.exit(0)
|
16 | 16 |
|
17 | 17 |
-> Functionality "Evolve ALPACA CA one generation" is implemented by
|
18 | 18 |
-> shell command
|
19 | |
-> "./bin/alpaca -c javascript %(test-file) > ca.js && node ca.js"
|
|
19 |
-> "./bin/alpaca -y -c javascript %(test-file) > ca.js && node ca.js"
|
20 | 20 |
EOF
|
21 | 21 |
fi
|
22 | 22 |
|