chiark / gitweb /
symbolic.py: wip making output good
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Nov 2017 11:47:12 +0000 (11:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 19 Nov 2017 11:47:12 +0000 (11:47 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
symbolic.py

index 08da2bdc983ef6e973e7db752d1d2973b5ad7d99..f219788e41485a9901da4ff8c337b37aa12d98b3 100755 (executable)
@@ -168,8 +168,15 @@ dbg('result_dirnscaled')
 
 params = ('sh','th','la','mu','gamma','kappa')
 
+def ourccode(*a, **kw):
+  return ccode(*a, user_functions={'sinc':'sinc'}, **kw)
+
+def cprintraw(*s):
+  print(*s)
+
 def cprint(s):
-  print(s)
+  for l in s.split('\n'):
+    cprintraw(l, '\\')
 
 def cse_prep_cprint(v, tmp_prefix):
   # => v, but also having cprint'd the common subexpression assignments
@@ -177,12 +184,12 @@ def cse_prep_cprint(v, tmp_prefix):
                  itertools.count())
   (defs, vs) = cse(v, symbols=sym_iter)
   for defname, defval in defs:
-    cprint(ccode(defval, assign_to=defname))
+    cprint('double '+ourccode(defval, assign_to=defname))
   return vs[0]
 
 def cassign(v, assign_to, tmp_prefix):
   v = cse_prep_cprint(v, tmp_prefix)
-  cprint(ccode(v, assign_to=assign_to))
+  cprint(ourccode(v, assign_to=assign_to))
 
 def gen_diff(current, smalls):
   global j
@@ -197,12 +204,12 @@ def gen_diff(current, smalls):
     dbg('j')
     j = cse_prep_cprint(j, 'jtmp')
     for ix in range(0, j.cols):
-      cprint(ccode(j.col(ix), 'J(%d)' % ix))
+      cprint(ourccode(j.col(ix), 'J(%d)' % ix))
       cprint('J_END_COL(%d)' % ix)
   else:
     small = smalls[0]
     smalls = smalls[1:]
-    cprint('if (!IS_SMALL(' + ccode(small) + ')) {')
+    cprint('if (!IS_SMALL(' + ourccode(small) + ')) {')
     gen_diff(current, smalls)
     cprint('} else { /* %s small */' % small)
     gen_diff(current.replace(
@@ -211,9 +218,11 @@ def gen_diff(current, smalls):
       ),
       smalls
     )
-    print('} /* %s small */' % small)
+    cprint('} /* %s small */' % small)
 
+cprintraw('#define J_POPULATE \\')
 gen_diff(result_dirnscaled, (sh*sh*la, th*th*la))
+cprintraw('')
 
 #bad = q_orgcoords[0]
 #badd = diff(bad, la)