Changeset 15be191 in sasmodels
- Timestamp:
- Jan 3, 2018 2:34:04 PM (7 years ago)
- Children:
- 4c87de0
- Parents:
- c01ed3e
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/autoc.py
rc01ed3e r15be191 93 93 constants[name] = obj 94 94 # Claim all constants are declared on line 1 95 snippets.append('#line 1 "%s" '%escaped_filename)95 snippets.append('#line 1 "%s"\n'%escaped_filename) 96 96 snippets.append(py2c.define_constant(name, obj)) 97 97 elif isinstance(obj, special.Gauss): … … 99 99 var = "GAUSS_"+var 100 100 constants[var] = value 101 snippets.append('#line 1 "%s" '%escaped_filename)101 snippets.append('#line 1 "%s"\n'%escaped_filename) 102 102 snippets.append(py2c.define_constant(var, value)) 103 103 #libs.append('lib/gauss%d.c'%obj.n) … … 125 125 # update model info 126 126 info.source = unique_libs 127 info.c_code = " \n".join(snippets)127 info.c_code = "".join(snippets) 128 128 info.Iq = info.Iqac = info.Iqabc = info.Iqxy = info.form_volume = None -
sasmodels/py2c.py
rc01ed3e r15be191 113 113 generator = SourceGenerator(constants=constants, fname=fname, lineno=lineno) 114 114 generator.visit(tree) 115 c_code = " \n".join(generator.c_proc)115 c_code = "".join(generator.c_proc) 116 116 return c_code 117 117 … … 199 199 self.new_lines = max(self.new_lines, 1 + extra) 200 200 if node is not None and self.add_line_information: 201 self.write_c(' #line: %s' % node.lineno)201 self.write_c('// line: %s' % node.lineno) 202 202 self.new_lines = 1 203 203 if self.current_statement: … … 220 220 self.body(node.body) 221 221 if node.orelse: 222 self.unsupported(node, "for...else/while...else not supported") 223 222 224 self.newline() 223 225 self.write_c('else:') … … 250 252 arg_name = arg.id 251 253 w_str = ("Default Parameters are unknown to C: '%s = %s" 252 % arg_name, str(default.n))254 % (arg_name, str(default.n))) 253 255 self.warnings.append(w_str) 254 256 … … 435 437 self.insert_signature() 436 438 self.insert_c_vars(start_vars) 437 self.c_pointers = []439 del self.c_pointers[:] 438 440 self.current_function = "" 439 441 … … 554 556 self.write_c(':') 555 557 # report the error 556 self.unsupported( "unsupported " + self.current_statement)558 self.unsupported(node, "unsupported " + self.current_statement) 557 559 558 560 def visit_While(self, node): 561 self.unsupported(node) 562 559 563 self.newline(node) 560 564 self.write_c('while ') … … 565 569 def visit_With(self, node): 566 570 self.unsupported(node) 571 567 572 self.newline(node) 568 573 self.write_python('with ') … … 581 586 # TODO: print support would be nice, though hard to do 582 587 self.unsupported(node) 588 583 589 # CRUFT: python 2.6 only 584 590 self.newline(node) … … 599 605 def visit_Delete(self, node): 600 606 self.unsupported(node) 607 601 608 self.newline(node) 602 609 self.write_python('del ') … … 608 615 def visit_TryExcept(self, node): 609 616 self.unsupported(node) 617 610 618 self.newline(node) 611 619 self.write_python('try:') … … 616 624 def visit_TryFinally(self, node): 617 625 self.unsupported(node) 626 618 627 self.newline(node) 619 628 self.write_python('try:') … … 625 634 def visit_Global(self, node): 626 635 self.unsupported(node) 636 627 637 self.newline(node) 628 638 self.write_python('global ' + ', '.join(node.names)) … … 654 664 def visit_Raise(self, node): 655 665 self.unsupported(node) 666 656 667 # CRUFT: Python 2.6 / 3.0 compatibility 657 668 self.newline(node) … … 676 687 def visit_Attribute(self, node): 677 688 self.unsupported(node, "attribute reference a.b not supported") 689 678 690 self.visit(node.value) 679 691 self.write_python('.' + node.attr) … … 779 791 def visit_Dict(self, node): 780 792 self.unsupported(node) 793 781 794 self.write_python('{') 782 795 for idx, (key, value) in enumerate(zip(node.keys, node.values)): … … 908 921 def visit_Yield(self, node): 909 922 self.unsupported(node) 923 910 924 self.write_python('yield ') 911 925 self.visit(node.value) … … 913 927 def visit_Lambda(self, node): 914 928 self.unsupported(node) 929 915 930 self.write_python('lambda ') 916 931 self.visit(node.args) … … 920 935 def visit_Ellipsis(self, node): 921 936 self.unsupported(node) 937 922 938 self.write_python('Ellipsis') 923 939 … … 940 956 def visit_DictComp(self, node): 941 957 self.unsupported(node) 958 942 959 self.write_python('{') 943 960 self.visit(node.key) … … 969 986 def visit_alias(self, node): 970 987 self.unsupported(node) 988 971 989 self.write_python(node.name) 972 990 if node.asname is not None: … … 1031 1049 const = "constant " # OpenCL needs globals to be constant 1032 1050 if isinstance(value, int): 1033 parts = [const + "int ", name, " = ", "%d"%value, "; "]1051 parts = [const + "int ", name, " = ", "%d"%value, ";\n"] 1034 1052 elif isinstance(value, float): 1035 parts = [const + "double ", name, " = ", "%.15g"%value, "; "]1053 parts = [const + "double ", name, " = ", "%.15g"%value, ";\n"] 1036 1054 else: 1037 1055 try: … … 1047 1065 elements = ["%.15g"%v for v in value] 1048 1066 parts = [const + "double ", name, "[]", " = ", 1049 "{\n ", ", ".join(elements), "\n}; "]1067 "{\n ", ", ".join(elements), "\n};\n"] 1050 1068 1051 1069 return "".join(parts) … … 1100 1118 #snippets.append("") 1101 1119 for source, fname, lineno in functions: 1102 line_directive = '#line %d "%s" '%(lineno, fname.replace('\\', '\\\\'))1120 line_directive = '#line %d "%s"\n'%(lineno, fname.replace('\\', '\\\\')) 1103 1121 snippets.append(line_directive) 1104 1122 tree = ast.parse(source) … … 1133 1151 .replace(name+'.w', 'GAUSS_W')) 1134 1152 1135 translation = translate([(code, fname_in, 1)]) [0]1153 translation = translate([(code, fname_in, 1)]) 1136 1154 1137 1155 with open(fname_out, "w") as file_out: 1138 file_out.write( translation)1156 file_out.write("".join(translation)) 1139 1157 print("...Done") 1140 1158
Note: See TracChangeset
for help on using the changeset viewer.