Changeset 0bd0877 in sasmodels


Ignore:
Timestamp:
Jan 8, 2018 9:07:32 AM (6 years ago)
Author:
Omer Eisenberg <omereis@…>
Children:
ff431ca
Parents:
4339764
Message:

working main in translated python

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/py2c.py

    r4339764 r0bd0877  
    123123    generator = SourceGenerator(constants=constants, fname=fname, lineno=lineno) 
    124124    generator.visit(tree) 
    125     c_code = "\n".join(generator.c_proc) 
     125#    c_code = "\n".join(generator.c_proc) 
    126126    c_code = "".join(generator.c_proc) 
    127127    return (c_code, generator.warnings) 
     
    12801280    return valid_params, fname_in,fname_out 
    12811281 
     1282C_HEADER = """ 
     1283#include <stdio.h> 
     1284#include <stdbool.h> 
     1285#include <math.h> 
     1286#define constant const 
     1287double square(double x) { return x*x; } 
     1288double cube(double x) { return x*x*x; } 
     1289double polyval(constant double *coef, double x, int N) 
     1290{ 
     1291    int i = 0; 
     1292    double ans = coef[0]; 
     1293 
     1294    while (i < N) { 
     1295        ans = ans * x + coef[i++]; 
     1296    } 
     1297 
     1298    return ans; 
     1299} 
     1300""" 
    12821301def main(): 
    12831302    print("Parsing...using Python" + sys.version) 
     
    12931312            .replace(name+'.n', 'GAUSS_N') 
    12941313            .replace(name+'.z', 'GAUSS_Z') 
    1295             .replace(name+'.w', 'GAUSS_W')) 
    1296  
     1314            .replace(name+'.w', 'GAUSS_W') 
     1315            .replace('if __name__ == "__main__"', "def main()") 
     1316           ) 
    12971317    translation,warnings = translate([(code, fname_in, 1)]) 
     1318    translation = translation.replace("double main()", "int main(int argc, char *argv[])") 
    12981319 
    12991320    with open(fname_out, "w") as file_out: 
     1321        file_out.write(C_HEADER) 
    13001322        file_out.write(str(translation)) 
    13011323    if warnings: 
Note: See TracChangeset for help on using the changeset viewer.