From 6418a9febcbcaae2b0da5ed3da51e58955950d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Mon, 22 Feb 2016 17:34:44 +0100 Subject: [PATCH] codegen: provide generator instead of printing --- pysstv/examples/codegen.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pysstv/examples/codegen.py b/pysstv/examples/codegen.py index cb04130..817e1e3 100644 --- a/pysstv/examples/codegen.py +++ b/pysstv/examples/codegen.py @@ -50,10 +50,10 @@ def main(sstv_class=None): raise NotImplementedError() sstv = sstv_class(Image('img'), 44100, 16) n = 0 - print '#define ROW(x) x' - print '#define COL(x) x' - print '#define RGB(x) (2 - (x))' - print 'void convert(unsigned char *img, float *freqs, float *msecs) {\nint frq = 0;' + yield '#define ROW(x) x' + yield '#define COL(x) x' + yield '#define RGB(x) (2 - (x))' + yield 'void convert(unsigned char *img, float *freqs, float *msecs) {\nint frq = 0;' history = [] lut = {} same_as = {} @@ -71,13 +71,13 @@ def main(sstv_class=None): mgen = iter(gen_matches(same_as, history, n)) m_start, m_len, m_end = next(mgen) for i in xrange(same_as[m_start]): - print history[i][0] - print 'for (int row = {0}; row >= 0; row -= {1}) {{'.format( + yield history[i][0] + yield 'for (int row = {0}; row >= 0; row -= {1}) {{'.format( (sstv.HEIGHT - 1) * sstv.WIDTH, sstv.WIDTH) for i in xrange(same_as[m_start], same_as[m_start] + m_len - 1): - print ' ', history[i][1] - print '}' - print '}}\n\n#define FREQ_COUNT {0}'.format(n) + yield ' ' + history[i][1] + yield '}' + yield '}}\n\n#define FREQ_COUNT {0}'.format(n)