예제 #1
0
    def __init__(self,
                 converter,
                 output_file=sys.stdout,
                 preamble_comment_str=None):
        """
        converter:      converter object providing expr_full_convert method
        output_file:    file object or file-like object to be used for text output
                        (must be open for writing)
        preamble_comment_str:
                        if not None, then immediately output a comment line containing
                        this string to the top of the output_file

        Note: the expr_full method should have the definition

            expr_full_convert(expr)

        where expr is a dsl_* expression (comprised of dsl_binop and dsl_unop objects), 
        or a dsl_* object, and which returns corresponding expr or object with all
        dsl_* objects converted to src_dsl_* objects.
        If expr is not a dsl_* expression or object (e.g. it is a str, or int), then
        it should pass through expr_full without modification.
        """
        self.converter = converter
        self.printer_obj = printer(endl=';', output_file=output_file)
        if preamble_comment_str != None:
            assert isinstance( preamble_comment_str, str ), \
                    "preamble_comment_str must be instance of str"
            self.comment(preamble_comment_str)
    def __init__(self,converter,output_file=sys.stdout,preamble_comment_str=None):
        """
        converter:      converter object providing expr_full_convert method
        output_file:    file object or file-like object to be used for text output
                        (must be open for writing)
        preamble_comment_str:
                        if not None, then immediately output a comment line containing
                        this string to the top of the output_file

        Note: the expr_full method should have the definition

            expr_full_convert(expr)

        where expr is a dsl_* expression (comprised of dsl_binop and dsl_unop objects), 
        or a dsl_* object, and which returns corresponding expr or object with all
        dsl_* objects converted to src_dsl_* objects.
        If expr is not a dsl_* expression or object (e.g. it is a str, or int), then
        it should pass through expr_full without modification.
        """
        self.converter   = converter
        self.printer_obj = printer(endl=';', output_file=output_file)
        if preamble_comment_str != None:
            assert isinstance( preamble_comment_str, str ), \
                    "preamble_comment_str must be instance of str" 
            self.comment( preamble_comment_str )
예제 #3
0
    def __init__(self, m, x, varname='boys_f'):
        self._m = m  # should be dsl_index
        self._x = x  # should be dsl_scalar, or dsl_binop
        self._varname = varname

    def __str__(self):
        out = []
        out.append(self._varname)
        out.append('[ ')
        out.append(str(self._m))
        out.append(' ]')
        return ''.join(out)

    def m(self):
        return self._m

    def x(self):
        return self._x


# Test Boys function output code
if __name__ == "__main__":
    p = printer(endl=';', output_file=sys.stdout)
    boys = boys_function(smallx_data_file='boys_data_smallx.json',\
                         mediumx_data_file='boys_data_mediumx.json')
    p.out('#include<stdio.h>', endl='')
    p.out('#include<math.h>', endl='')
    p.out('#include"boys.h"', endl='')
    boys.datadump(p)
    boys.funcdump(p)
예제 #4
0
    boys_function_obj = boys_default
    def __init__(self,m,x,varname='boys_f'):
        self._m = m # should be dsl_index
        self._x = x # should be dsl_scalar, or dsl_binop
        self._varname = varname

    def __str__(self):
        out = []
        out.append(self._varname)
        out.append('[ ')
        out.append( str(self._m) )
        out.append(' ]')
        return ''.join(out)

    def m(self):
        return self._m

    def x(self):
        return self._x

# Test Boys function output code
if __name__ == "__main__":
     p = printer(endl=';',output_file=sys.stdout)
     boys = boys_function(smallx_data_file='boys_data_smallx.json',\
                          mediumx_data_file='boys_data_mediumx.json')
     p.out( '#include<stdio.h>',endl='' )
     p.out( '#include<math.h>',endl='' )
     p.out( '#include"boys.h"',endl='' )
     boys.datadump(p)
     boys.funcdump(p)