Permalink
Browse files

added "inline" flag to ./game/build.py, added python script to identi…

…fy possible inplace spots
  • Loading branch information...
1 parent 8206fba commit 5579ae8b7837cf7d97398fedb4b2a598763a4601 Evan Wallace committed Jan 9, 2011
Showing with 32 additions and 5 deletions.
  1. +1 −1 build.py
  2. +2 −4 game/build.py
  3. +29 −0 game/find_inplace_candidates.py
View
@@ -18,7 +18,7 @@ def background(command):
subprocess.Popen(command, shell=True)
op = foreground if release else background
-suffix = ' release' if release else ''
+suffix = ' inline release' if release else ''
op('cd editor && python build.py' + suffix)
op('cd game && python build.py' + suffix)
View
@@ -5,8 +5,6 @@
import re, os, time, sys
-release = 'release' in sys.argv
-
class CompileError(Exception):
def __init__(self, text):
Exception.__init__(self, text)
@@ -75,7 +73,7 @@ def compile(sources):
def build():
try:
data = compile(sources())
- if release:
+ if 'inline' in sys.argv:
print 'inlining javascript...'
from js_inline import js_inline
data = js_inline(data)
@@ -102,5 +100,5 @@ def monitor():
if __name__ == '__main__':
build()
- if not release:
+ if 'release' not in sys.argv:
monitor()
@@ -0,0 +1,29 @@
+# make sure we read an up-to-date build
+import os
+os.system('python build.py release')
+lines = open('./www/rapt.js').read().split('\n')
+
+funcs = [
+ 'add',
+ 'sub',
+ 'mul',
+ 'div',
+ 'minComponents',
+ 'maxComponents'
+]
+
+# find all uses of functions we want to inline
+def is_candidate(line):
+ return any('.' + f + '(' in line for f in funcs)
+lines = [(i, line.strip()) for i, line in enumerate(lines) if is_candidate(line)]
+
+# check uses
+for i, line in lines:
+ parts = line.split()
+ if len(parts) < 3:
+ continue
+ if len(parts) > 3:
+ parts = [parts[0], parts[1], ' '.join(parts[3:])]
+ start, equals, end = parts
+ if equals == '=' and end.startswith(start):
+ print line

0 comments on commit 5579ae8

Please sign in to comment.