Changeset 98a4f14 in sasmodels


Ignore:
Timestamp:
Dec 15, 2017 2:34:17 PM (6 years ago)
Author:
Omer Eisenberg <omereis@…>
Children:
d9341fa, 1ddb794
Parents:
fa74acf
Message:

add for loop to translate, fixed bug in visit_BinOp that wrote multiple semicolons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/py2c.py

    rfa74acf r98a4f14  
    292292    def add_semi_colon(self): 
    293293        semi_pos = self.current_statement.find(';') 
    294         if(semi_pos < 0): 
    295             self.write_c(';') 
     294        if(semi_pos > 0.0): 
     295            self.current_statement = self.current_statement.replace(';','') 
     296        self.write_c(';') 
    296297 
    297298    def visit_Assign(self, node): 
     
    475476        self.visit(node.args) 
    476477# for C 
    477         self.writeInclude() 
     478#        self.writeInclude() 
    478479        self.getMethodSignature() 
    479480# for C 
     
    704705            self.write_c('return(') 
    705706            self.visit(node.value) 
    706         self.write_c(');') 
    707 #      self.add_current_statement(self) 
     707        self.write_c(')') 
     708        self.add_semi_colon() 
    708709        self.add_c_line(self.current_statement) 
    709710        self.current_statement = '' 
     
    11011102def translate(functions, constants=0): 
    11021103    sniplets = [] 
    1103     fname = functions[1] 
    1104     python_file = open(fname, "r") 
    1105     source = python_file.read() 
    1106     python_file.close() 
    1107     tree = ast.parse(source) 
    1108     sniplet = to_source(tree, functions) # in the future add filename, offset, constants 
    1109     sniplets.append(sniplet) 
     1104    sniplets.append("#include <math.h>") 
     1105    sniplets.append("static double pi = 3.14159265359;") 
     1106    for source,fname,line_no in functions: 
     1107        line_directive = '#line %d "%s"' %(line_no,fname) 
     1108        line_directive = line_directive.replace('\\','\\\\') 
     1109#        sniplets.append(line_directive) 
     1110        tree = ast.parse(source) 
     1111        sniplet = to_source(tree, functions) # in the future add filename, offset, constants 
     1112        sniplets.append(sniplet) 
     1113    c_code = "\n".join(sniplets) 
     1114    f_out = open ("xlate.c", "w+") 
     1115    f_out.write (c_code) 
     1116    f_out.close() 
    11101117    return("\n".join(sniplets)) 
    11111118 
Note: See TracChangeset for help on using the changeset viewer.