From 8cf67b95ab9f015e90b49edfc59a04c74c3d8e19 Mon Sep 17 00:00:00 2001 From: Sven-Bodo Scholz Date: Wed, 30 Sep 2020 13:08:47 +0200 Subject: [PATCH 1/2] added L9 examples --- L9_c4sac/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ L9_c4sac/simple.c | 6 ++++++ L9_c4sac/simple.h | 6 ++++++ L9_c4sac/simple.sac | 9 +++++++++ 4 files changed, 59 insertions(+) create mode 100644 L9_c4sac/Makefile create mode 100644 L9_c4sac/simple.c create mode 100644 L9_c4sac/simple.h create mode 100644 L9_c4sac/simple.sac diff --git a/L9_c4sac/Makefile b/L9_c4sac/Makefile new file mode 100644 index 0000000..be12877 --- /dev/null +++ b/L9_c4sac/Makefile @@ -0,0 +1,38 @@ +####################################################################################### +# +# General Setup: +# +SAC2CFLAGS = -check ctb -v2 -O3 + +ifdef EXCLUDE_ERRORS +SAC2CFLAGS += -DEXCLUDE_ERRORS +endif + +# +# Setup for Makefile.standard: +# +# EXCLUDE_FILES = +# TARGETDIR = . +# LIBTARGETDIR = . +# INCTARGETDIR = . +# LIBSRCDIR = . +# SUBDIRS = + +# +# Setup for Makefile.versions +# +# EXCLUDE_FILES_FOR_MT = +# MAKE_MT_ALSO = yes +# VERSDIR = . + +# +# Setup for Makefile.check: +# +CHECKLOGFILE = ./CHECKLOG +# CHECKDIR = .checkdir +# RT_FLAGS = +# INPSDIR = +# +####################################################################################### + +include $(SACBASE)/Makefiles/Makefile_template.prg diff --git a/L9_c4sac/simple.c b/L9_c4sac/simple.c new file mode 100644 index 0000000..357c9df --- /dev/null +++ b/L9_c4sac/simple.c @@ -0,0 +1,6 @@ +#include "simple.h" + +int add(int x, int y) 4{ + return x + y; +} + diff --git a/L9_c4sac/simple.h b/L9_c4sac/simple.h new file mode 100644 index 0000000..00ea7e3 --- /dev/null +++ b/L9_c4sac/simple.h @@ -0,0 +1,6 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + +extern int add(int x, int y); 5 + +#endif diff --git a/L9_c4sac/simple.sac b/L9_c4sac/simple.sac new file mode 100644 index 0000000..13da48e --- /dev/null +++ b/L9_c4sac/simple.sac @@ -0,0 +1,9 @@ +external int add(double x, double y); + #pragma linkobj "simple.o" + #pragma header "simple.h" + +int main() +{ + StdIO::printf("1 plus 1 is %d\n", add( 1, 1)); + return 0; +} From 70754fa9d21a86fa861c3e145dd4feac8a1c2a4d Mon Sep 17 00:00:00 2001 From: Sven-Bodo Scholz Date: Mon, 13 May 2024 18:48:12 +0900 Subject: [PATCH 2/2] adjusted L8 to TPs and TCs --- L8_case-study_mandelbrot/Fractal_tier1.sac | 41 +++++++---------- .../Fractal_tier1_empty.sac | 37 ++++++++------- L8_case-study_mandelbrot/Fractal_tier2.sac | 40 ++++++----------- .../Fractal_tier2_empty.sac | 45 +++++++++---------- L8_case-study_mandelbrot/mandelbrot.sac | 7 +-- .../mandelbrot_simple.sac | 7 +-- 6 files changed, 73 insertions(+), 104 deletions(-) diff --git a/L8_case-study_mandelbrot/Fractal_tier1.sac b/L8_case-study_mandelbrot/Fractal_tier1.sac index 04b58df..24b792e 100644 --- a/L8_case-study_mandelbrot/Fractal_tier1.sac +++ b/L8_case-study_mandelbrot/Fractal_tier1.sac @@ -8,7 +8,7 @@ export all; /** * - * @fn : complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax) + * @fn : complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax) * * @brief generates an array of complex numbers with shape "shp" and * linearly increasing/decreasing values between "cmin" and "cmax". @@ -17,13 +17,12 @@ export all; * *****************************************************************************/ inline -complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax) +complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax) { - res = with { - ( . <= iv <= .) : cmin + toc( reverse( (tod(iv) / tod(shp)) - * reverse( todv(cmax-cmin)))); - } : genarray( shp, toc( 0,0)); - return( res); + diff = cmax - cmin; + delta = [imag (diff) / tod( shp[0]) , real (diff) / tod (shp[1])]; + + return { iv -> cmin + toc (tod (iv) * delta) | iv < shp }; } @@ -41,31 +40,27 @@ complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax) inline int escapeTime(complex z, int depth) { - i=0; c=z; + i=0; c=z; - while( (normSq( c) <= 4d) && (i <= depth)) { - c=c*c+z; i++; - } + while( (normSq( c) <= 4d) && (i <= depth)) { + c=c*c+z; i++; + } - return(i); + return(i); } /** * - * @fn int[*] escapeTime(complex[*] z, int depth) + * @fn int[n:shp] escapeTime(complex[n:shp] z, int depth) * * @brief maps escapeTime to an entire array of complex numbers * *****************************************************************************/ inline -int[*] escapeTime( complex[*] plane, int depth) +int[n:shp] escapeTime( complex[n:shp] plane, int depth) { - values = with { - ( . <= iv <= .) : escapeTime( plane[iv], depth); - } : genarray( shape( plane), 0); - - return( values); + return { iv -> escapeTime (plane[iv], depth) }; } /** @@ -78,13 +73,11 @@ int[*] escapeTime( complex[*] plane, int depth) inline Color8::color[.,.] intArrayToMonochrome( int[.,.] a) { - clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red()); + clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red()); - a = (a * 255) / maxval(a); + a = (a * 255) / maxval(a); - d = with { - ( .<= iv <= .) : clut[ a[ iv]]; - } : genarray( shape(a), Color8::black()); + return { iv -> clut[ a[ iv]] }; return( d); } diff --git a/L8_case-study_mandelbrot/Fractal_tier1_empty.sac b/L8_case-study_mandelbrot/Fractal_tier1_empty.sac index a9621e2..3377f23 100644 --- a/L8_case-study_mandelbrot/Fractal_tier1_empty.sac +++ b/L8_case-study_mandelbrot/Fractal_tier1_empty.sac @@ -8,20 +8,20 @@ export all; /** * - * @fn : complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax) + * @fn : complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax) * * @brief generates an array of complex numbers with shape "shp" and * linearly increasing/decreasing values between "cmin" and "cmax". - * The element at index [0,0] should be "cmin". Increases in the + * The element at index [0,0] should be "cmin". Increases in the * 2nd index (!) should reflect increases in the real values! * *****************************************************************************/ inline -complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax) +complex[2:shp] genComplexArray( int[2] shp, complex cmin, complex cmax) { -/** - * fill in here... - */ + /** + * fill in here... + */ } @@ -39,24 +39,25 @@ complex[.,.] genComplexArray( int[2] shp, complex cmin, complex cmax) inline int escapeTime(complex z, int depth) { -/** - * fill in here... - */ + /** + * fill in here... + */ } /** * - * @fn int[*] escapeTime(complex[*] z, int depth) + * @fn int[n:shp] escapeTime(complex[n:shp] z, int depth) * * @brief maps escapeTime to an entire array of complex numbers * *****************************************************************************/ -inline int[*] escapeTime( complex[*] plane, int depth) +inline +int[n:shp] escapeTime( complex[n:shp] plane, int depth) { -/** - * fill in here... - */ + /** + * fill in here... + */ } /** @@ -69,13 +70,11 @@ inline int[*] escapeTime( complex[*] plane, int depth) inline Color8::color[.,.] intArrayToMonochrome( int[.,.] a) { - clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red()); + clut = genLogarithmicClut( 0.4d, 0.9d, Color8::black(), Color8::red()); - a = (a * 256) / maxval(a); + a = (a * 255) / maxval(a); - d = with { - ( .<= iv <= .) : clut[ a[ iv]]; - } : genarray( shape(a), Color8::black()); + return { iv -> clut[ a[ iv]] }; return( d); } diff --git a/L8_case-study_mandelbrot/Fractal_tier2.sac b/L8_case-study_mandelbrot/Fractal_tier2.sac index db0c181..9324355 100644 --- a/L8_case-study_mandelbrot/Fractal_tier2.sac +++ b/L8_case-study_mandelbrot/Fractal_tier2.sac @@ -7,7 +7,7 @@ export all; /** * - * @fn complex escapeValue(complex z, int depth) + * @fn int, complex escapeTimeAndValue (complex z, int depth) * * @brief iteratively computes c = c*c + z starting from c=z. * terminates either when |c| > 2 or depth iterations @@ -16,46 +16,34 @@ export all; * * @return final complex value *****************************************************************************/ -int, complex escapeTimeAndValue(complex z, int depth) +int, complex escapeTimeAndValue (complex z, int depth) { - i=0; c=z; + i=0; c=z; - while( (normSq( c) <= 4d) && (i <= depth)) { - c=c*c+z; i++; - } + while( (normSq( c) <= 4d) && (i <= depth)) { + c=c*c+z; i++; + } - return(i, c); + return(i, c); } /** * - * @fn complex[*] escapeValue(complex[*] z, int depth) + * @fn int[m,n], complex[m,n] escapeTimeAndValue (complex[m,n] z, int depth) * * @brief maps escapeValue to an entire array of complex numbers * *****************************************************************************/ inline -int[.,.], complex[.,.] escapeTimeAndValue( complex[.,.] plane, int depth) +int[m,n], complex[m,n] escapeTimeAndValue ( complex[m,n] plane, int depth) { - times = with { - ( . <= x <= .) { - t, v = escapeTimeAndValue( plane[x], depth); - } : t; - } : genarray( shape( plane), 0); - - values = with { - ( . <= x <= .) { - t, v = escapeTimeAndValue( plane[x], depth); - } : v; - } : genarray( shape( plane), toc(0)); - - return( times, values); + return { iv -> escapeTimeAndValue (plane[iv]) }; } /** * - * @fn double normalizedIterationCount(int n, complex zn) + * @fn double[d:shp] normalizedIterationCount (int[d:shp] n, complex[d:shp] zn) * * @brief normalizes the iteration counts in "n" taking the distance of the * corresponding final complex numbers from the origin into account. @@ -66,7 +54,7 @@ int[.,.], complex[.,.] escapeTimeAndValue( complex[.,.] plane, int depth) * @return the normalized iteration counts *****************************************************************************/ inline -double[*] normalizedIterationCount(int[*] n, complex[*] zn) +double[d:shp] normalizedIterationCount(int[d:shp] n, complex[d:shp] zn) { return( where( (norm( zn) <= 2d) , 0d , tod(n+1) - log2( log2( norm( zn))))); } @@ -74,7 +62,7 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn) /** * - * @fn color[.,.] doubleArrayToRGB( double[.,.] a) + * @fn color[d:shp] doubleArrayToRGB( double[d:shp] a) * * @brief transforms an array of doubles into RGB values, by * FIRST scaling them into values between 0.0 and 360.0, and @@ -85,7 +73,7 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn) * @return RGB values *****************************************************************************/ inline -Color8::color[.,.] doubleArrayToRGB( double[.,.] a) +Color8::color[d:shp] doubleArrayToRGB( double[d:shp] a) { max = maxval( a); min = minval( a); diff --git a/L8_case-study_mandelbrot/Fractal_tier2_empty.sac b/L8_case-study_mandelbrot/Fractal_tier2_empty.sac index 30484b8..57239cc 100644 --- a/L8_case-study_mandelbrot/Fractal_tier2_empty.sac +++ b/L8_case-study_mandelbrot/Fractal_tier2_empty.sac @@ -7,7 +7,7 @@ export all; /** * - * @fn complex escapeValue(complex z, int depth) + * @fn int, complex escapeTimeAndValue (complex z, int depth) * * @brief iteratively computes c = c*c + z starting from c=z. * terminates either when |c| > 2 or depth iterations @@ -16,39 +16,34 @@ export all; * * @return final complex value *****************************************************************************/ -inline -complex escapeValue(complex z, int depth) +int, complex escapeTimeAndValue (complex z, int depth) { - i=0; c=z; + i=0; c=z; - while( (normSq( c) <= 4d) && (i <= depth)) { - c=c*c+z; i++; - } + while( (normSq( c) <= 4d) && (i <= depth)) { + c=c*c+z; i++; + } - return(c); + return(i, c); } /** * - * @fn complex[*] escapeValue(complex[*] z, int depth) + * @fn int[m,n], complex[m,n] escapeTimeAndValue (complex[m,n] z, int depth) * * @brief maps escapeValue to an entire array of complex numbers * *****************************************************************************/ inline -complex[.,.] escapeValue( complex[.,.] plane, int depth) +int[m,n], complex[m,n] escapeTimeAndValue ( complex[m,n] plane, int depth) { - values = with { - ( . <= x <= .) : escapeValue( plane[x], depth); - } : genarray( shape( plane), toc(0)); - - return( values); + return { iv -> escapeTimeAndValue (plane[iv]) }; } /** * - * @fn double normalizedIterationCount(int n, complex zn) + * @fn double[d:shp] normalizedIterationCount (int[d:shp] n, complex[d:shp] zn) * * @brief normalizes the iteration counts in "n" taking the distance of the * corresponding final complex numbers from the origin into account. @@ -59,17 +54,17 @@ complex[.,.] escapeValue( complex[.,.] plane, int depth) * @return the normalized iteration counts *****************************************************************************/ inline -double[*] normalizedIterationCount(int[*] n, complex[*] zn) +double[d:shp] normalizedIterationCount(int[d:shp] n, complex[d:shp] zn) { -/** - * fill in here... - */ + /** + * fill in here... + */ } /** * - * @fn color[.,.] doubleArrayToRGB( double[.,.] a) + * @fn color[d:shp] doubleArrayToRGB( double[d:shp] a) * * @brief transforms an array of doubles into RGB values, by * FIRST scaling them into values between 0.0 and 360.0, and @@ -80,11 +75,11 @@ double[*] normalizedIterationCount(int[*] n, complex[*] zn) * @return RGB values *****************************************************************************/ inline -Color8::color[.,.] doubleArrayToRGB( double[.,.] a) +Color8::color[d:shp] doubleArrayToRGB( double[d:shp] a) { -/** - * fill in here... - */ + /** + * fill in here... + */ } diff --git a/L8_case-study_mandelbrot/mandelbrot.sac b/L8_case-study_mandelbrot/mandelbrot.sac index 8e0fded..77bd858 100644 --- a/L8_case-study_mandelbrot/mandelbrot.sac +++ b/L8_case-study_mandelbrot/mandelbrot.sac @@ -17,12 +17,9 @@ use Fractal_tier2 : all; use Stencil_tier3 : all; inline -color[.,.] stretchRgb( color[.,.] pic, int stretch) +color[ms,ns] stretchRgb( color[m,n] pic, int stretch) { - res = with { - (. <= iv <= .): pic[ iv / stretch]; - } : genarray( shape(pic) * stretch, black()); - return( res); + return { iv -> pic[ iv / stretch] | iv < shape(pic) * stretch }; } /* Main ******************************************************************** */ diff --git a/L8_case-study_mandelbrot/mandelbrot_simple.sac b/L8_case-study_mandelbrot/mandelbrot_simple.sac index 471b80d..0598730 100644 --- a/L8_case-study_mandelbrot/mandelbrot_simple.sac +++ b/L8_case-study_mandelbrot/mandelbrot_simple.sac @@ -12,12 +12,9 @@ use Fractal_tier1 : all; use Fractal_tier2 : all; inline -color[.,.] stretchRgb( color[.,.] pic, int stretch) +color[ms,ns] stretchRgb( color[m,n] pic, int stretch) { - res = with { - (. <= iv <= .): pic[ iv / stretch]; - } : genarray( shape(pic) * stretch, black()); - return( res); + return { iv -> pic[ iv / stretch] | iv < shape(pic) * stretch }; } /* Main ******************************************************************** */