Commits

Anonymous committed 99329e0

Add --include-yoob-playfield-inline option (for node.js testing.)

  • Participants
  • Parent commits ba407ed

Comments (0)

Files changed (3)

File src/alpaca/backends/javascript.py

 """
 
 class Compiler(object):
-    def __init__(self, alpaca, file):
+    def __init__(self, alpaca, file, options=None):
         """alpaca is an ALPACA description in AST form.  file is a file-like
         object to which the compiled code will be written.
 
         """
         self.alpaca = alpaca
         self.file = file
+        self.options = options
 
     def compile(self):
         bb = BoundingBox(0, 0, 0, 0)
  */
 
 """)
-        self.file.write(YOOB_PLAYFIELD_JS)
+        if self.options is not None and \
+           self.options.include_yoob_playfield_inline:
+            self.file.write(YOOB_PLAYFIELD_JS)
         self.file.write("""
 function in_nbhd_pred(pf, x, y, pred, nbhd) {
   var count = 0;

File src/alpaca/main.py

     optparser.add_option("-t", "--test",
                          action="store_true", dest="test", default=False,
                          help="run test cases and exit")
+    optparser.add_option("-y", "--include-yoob-playfield-inline",
+                         action="store_true",
+                         dest="include_yoob_playfield_inline", default=False,
+                         help="include yoob/playfield.js (from yoob.js) "
+                              "inline in generated Javascript (javascript "
+                              "backend only)")
     (options, args) = optparser.parse_args(argv[1:])
     if options.test:
         import doctest
         # XXX generalize
         if options.compile_to == 'javascript':
             from alpaca.backends.javascript import Compiler
-            compiler = Compiler(ast, sys.stdout)
+            compiler = Compiler(ast, sys.stdout, options=options)
             success = compiler.compile()
             if success:
                 sys.exit(0)
 
     -> Functionality "Evolve ALPACA CA one generation" is implemented by
     -> shell command
-    -> "./bin/alpaca -c javascript %(test-file) > ca.js && node ca.js"
+    -> "./bin/alpaca -y -c javascript %(test-file) > ca.js && node ca.js"
 EOF
 fi