Index: sasmodels/py2c.py
===================================================================
--- sasmodels/py2c.py	(revision 0bd0877de0c83cef75a40dbe39227fa18c60fdb6)
+++ sasmodels/py2c.py	(revision 5dd7cfb20ef7f79099a8fa7d5f95fdf1ad92db68)
@@ -147,4 +147,8 @@
 import ast
 from ast import NodeVisitor
+try: # for debugging, astor lets us print out the node as python
+    import astor
+except ImportError:
+    pass
 
 BINOP_SYMBOLS = {}
@@ -193,4 +197,10 @@
         return False
 
+def render_expression(tree):
+    generator = SourceGenerator()
+    generator.visit(tree)
+    c_code = "".join(generator.current_statement)
+    return c_code
+
 class SourceGenerator(NodeVisitor):
     """This visitor is able to transform a well formed syntax tree into python
@@ -199,11 +209,7 @@
     """
 
-    def __init__(self, indent_with="    ", add_line_information=False,
-                 constants=None, fname=None, lineno=0):
-        self.result = []
+    def __init__(self, indent_with="    ", constants=None, fname=None, lineno=0):
         self.indent_with = indent_with
-        self.add_line_information = add_line_information
         self.indentation = 0
-        self.new_lines = 0
 
         # for C
@@ -215,5 +221,4 @@
         self.lineno_offset = lineno
         self.warnings = []
-        self.statements = []
         self.current_statement = ""
         # TODO: use set rather than list for c_vars, ...
@@ -230,18 +235,12 @@
         self.tuples = []
         self.required_functions = []
-        self.is_sequence = False
         self.visited_args = False
-
-    def write_python(self, x):
-        if self.new_lines:
-            if self.result:
-                self.result.append('\n' * self.new_lines)
-            self.result.append(self.indent_with * self.indentation)
-            self.new_lines = 0
-        self.result.append(x)
 
     def write_c(self, statement):
         # TODO: build up as a list rather than adding to string
         self.current_statement += statement
+
+    def write_python(self, x):
+        raise NotImplementedError("shouldn't be trying to write pythnon")
 
     def add_c_line(self, line):
@@ -267,12 +266,9 @@
             self.add_unique_var(arg.id)
 
-    def newline(self, node=None, extra=0):
-        self.new_lines = max(self.new_lines, 1 + extra)
-        if node is not None and self.add_line_information:
-            self.write_c('// line: %s' % node.lineno)
-            self.new_lines = 1
-        if self.current_statement:
-            self.statements.append(self.current_statement)
-            self.current_statement = ''
+    def track_lineno(self, node):
+        #print("newline", node, [s for s in dir(node) if not s.startswith('_')])
+        if hasattr(node, 'lineno'):
+            line = '#line %d "%s"\n' % (node.lineno+self.lineno_offset-1, self.fname)
+            self.c_proc.append(line)
 
     def body(self, statements):
@@ -293,5 +289,5 @@
             self.unsupported(node, "for...else/while...else not supported")
 
-            self.newline()
+            self.track_lineno(node)
             self.write_c('else:')
             self.body(node.orelse)
@@ -327,6 +323,8 @@
 
     def decorators(self, node):
+        if node.decorator_list:
+            self.unsupported(node.decorator_list[0])
         for decorator in node.decorator_list:
-            self.newline(decorator)
+            self.trac_lineno(decorator)
             self.write_python('@')
             self.visit(decorator)
@@ -335,5 +333,7 @@
 
     def visit_Assert(self, node):
-        self.newline(node)
+        self.unsupported(node)
+
+        self.track_lineno(node)
         self.write_c('assert ')
         self.visit(node.test)
@@ -369,4 +369,5 @@
     def visit_Assign(self, node):
         self.add_current_line()
+        self.track_lineno(node)
         self.in_expr = True
         for idx, target in enumerate(node.targets): # multi assign, as in 'a = b = c = 7'
@@ -379,5 +380,4 @@
         del self.tuples[:]
         self.write_c(' = ')
-        self.is_sequence = False
         self.visited_args = False
         self.visit(node.value)
@@ -392,12 +392,12 @@
             self.add_semi_colon()
             self.add_current_line()
-        if self.is_sequence and not self.visited_args:
-            for target in node.targets:
-                if hasattr(target, 'id'):
-                    if target.id in self.c_vars and target.id not in self.c_dcl_pointers:
-                        if target.id not in self.c_dcl_pointers:
-                            self.c_dcl_pointers.append(target.id)
-                            if target.id in self.c_vars:
-                                self.c_vars.remove(target.id)
+        #if self.is_sequence and not self.visited_args:
+        #    for target in node.targets:
+        #        if hasattr(target, 'id'):
+        #            if target.id in self.c_vars and target.id not in self.c_dcl_pointers:
+        #                if target.id not in self.c_dcl_pointers:
+        #                    self.c_dcl_pointers.append(target.id)
+        #                    if target.id in self.c_vars:
+        #                        self.c_vars.remove(target.id)
         self.current_statement = ''
         self.in_expr = False
@@ -417,5 +417,5 @@
     def visit_ImportFrom(self, node):
         return  # import ignored
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('from %s%s import ' %('.' * node.level, node.module))
         for idx, item in enumerate(node.names):
@@ -426,5 +426,5 @@
     def visit_Import(self, node):
         return  # import ignored
-        self.newline(node)
+        self.track_lineno(node)
         for item in node.names:
             self.write_python('import ')
@@ -433,5 +433,5 @@
     def visit_Expr(self, node):
         #self.in_expr = True
-        self.newline(node)
+        #self.track_lineno(node)
         self.generic_visit(node)
         #self.in_expr = False
@@ -506,7 +506,6 @@
         warning_index = len(self.warnings)
 
-        self.newline(extra=1)
         self.decorators(node)
-        self.newline(node)
+        self.track_lineno(node)
         self.arguments = []
         self.visit(node.args)
@@ -525,4 +524,6 @@
 
     def visit_ClassDef(self, node):
+        self.unsupported(node)
+
         have_args = []
         def paren_or_comma():
@@ -533,7 +534,6 @@
                 self.write_python('(')
 
-        self.newline(extra=2)
         self.decorators(node)
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('class %s' % node.name)
         for base in node.bases:
@@ -559,4 +559,5 @@
     def visit_If(self, node):
 
+        self.track_lineno(node)
         self.write_c('if ')
         self.in_expr = True
@@ -573,5 +574,5 @@
             elif len(else_) == 1 and isinstance(else_[0], ast.If):
                 node = else_[0]
-                #self.newline()
+                self.track_lineno(node)
                 self.write_c('else if ')
                 self.in_expr = True
@@ -584,5 +585,5 @@
                 #break
             else:
-                self.newline()
+                self.track_lineno(else_)
                 self.write_c('else {')
                 self.body(else_)
@@ -651,5 +652,5 @@
 
     def visit_While(self, node):
-        self.newline(node)
+        self.track_lineno(node)
         self.write_c('while ')
         self.visit(node.test)
@@ -662,5 +663,5 @@
         self.unsupported(node)
 
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('with ')
         self.visit(node.context_expr)
@@ -672,6 +673,7 @@
 
     def visit_Pass(self, node):
-        self.newline(node)
+        #self.track_lineno(node)
         #self.write_python('pass')
+        pass
 
     def visit_Print(self, node):
@@ -679,5 +681,5 @@
 
         # CRUFT: python 2.6 only
-        self.newline(node)
+        self.track_lineno(node)
         self.write_c('print ')
         want_comma = False
@@ -697,5 +699,5 @@
         self.unsupported(node)
 
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('del ')
         for idx, target in enumerate(node):
@@ -707,5 +709,5 @@
         self.unsupported(node)
 
-        self.newline(node)
+        self.track_linno(node)
         self.write_python('try:')
         self.body(node.body)
@@ -716,8 +718,8 @@
         self.unsupported(node)
 
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('try:')
         self.body(node.body)
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('finally:')
         self.body(node.finalbody)
@@ -726,13 +728,14 @@
         self.unsupported(node)
 
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('global ' + ', '.join(node.names))
 
     def visit_Nonlocal(self, node):
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('nonlocal ' + ', '.join(node.names))
 
     def visit_Return(self, node):
         self.add_current_line()
+        self.track_lineno(node)
         self.in_expr = True
         if node.value is None:
@@ -747,9 +750,9 @@
 
     def visit_Break(self, node):
-        self.newline(node)
+        self.track_lineno(node)
         self.write_c('break')
 
     def visit_Continue(self, node):
-        self.newline(node)
+        self.track_lineno(node)
         self.write_c('continue')
 
@@ -758,5 +761,5 @@
 
         # CRUFT: Python 2.6 / 3.0 compatibility
-        self.newline(node)
+        self.track_lineno(node)
         self.write_python('raise')
         if hasattr(node, 'exc') and node.exc is not None:
@@ -870,5 +873,5 @@
     def visit_Str(self, node):
         s = node.s
-        s = s.replace('\\','\\\\').replace('"','\\"').replace('\n','\\n')
+        s = s.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')
         self.write_c('"')
         self.write_c(s)
@@ -877,5 +880,5 @@
     def visit_Bytes(self, node):
         s = node.s
-        s = s.replace('\\','\\\\').replace('"','\\"').replace('\n','\\n')
+        s = s.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n')
         self.write_c('"')
         self.write_c(s)
@@ -892,24 +895,17 @@
                 self.visit(item)
 
-    def sequence_visit(left, right):
-        def visit(self, node):
-            self.is_sequence = True
-            s = ""
-            for idx, item in enumerate(node.elts):
-                if idx > 0 and s:
-                    s += ', '
-                if hasattr(item, 'id'):
-                    s += item.id
-                elif hasattr(item, 'n'):
-                    s += str(item.n)
-            if s:
-                self.c_vectors.append(s)
-                vec_name = "vec"  + str(len(self.c_vectors))
-                self.write_c(vec_name)
-        return visit
-
-    visit_List = sequence_visit('[', ']')
-    visit_Set = sequence_visit('{', '}')
-    del sequence_visit
+    def visit_List(self, node):
+        #self.unsupported(node)
+        #print("visiting", node)
+        #print(astor.to_source(node))
+        #print(node.elts)
+        exprs = [render_expression(item) for item in node.elts]
+        if exprs:
+            self.c_vectors.append(', '.join(exprs))
+            vec_name = "vec"  + str(len(self.c_vectors))
+            self.write_c(vec_name)
+
+    def visit_Set(self, node):
+        self.unsupported(node)
 
     def visit_Dict(self, node):
@@ -1127,7 +1123,9 @@
 
     def visit_comprehension(self, node):
+        self.unsupported(node)
+
         self.write_c(' for ')
         self.visit(node.target)
-        self.write_C(' in ')
+        self.write_c(' in ')
         #self.write_python(' in ')
         self.visit(node.iter)
@@ -1286,11 +1284,4 @@
     return snippets, warnings
 
-def to_source(tree, constants=None, fname=None, lineno=0):
-    """
-    This function can convert a syntax tree into C sourcecode.
-    """
-    c_code = "".join(generator.c_proc)
-    return c_code
-
 
 C_HEADER = """
