diff --git a/doc/chlog.txt b/doc/chlog.txt index 1a5e6c8e..c26da3a4 100644 --- a/doc/chlog.txt +++ b/doc/chlog.txt @@ -1,3 +1,156 @@ +20240429: +- The compilation of s7c with tcc has been fixed. Many thanks to + Cheap-Ad9743 for pointing out that compiling s7c with tcc failed. +- Chapters about hashes and templates have been added to the manual. +- The library hash.s7i has been improved to support hash table + literals and the comparison of hash tables with = and <> . +- The new library scanjson.s7i has been added. This library supports + scanning (reading) JSON (JavaScript Object Notation) symbols from + strings and files. +- The experimental readjson.s7i library has been removed. +- The new library fixarray.s7i has been added. This library supports + arrays with a fixed size. The minimum and maximum index of these + arrays is encoded in the type. The functions minIdx(), maxIdx() + and length() can be used with an array or the type as parameter. + The times operator can be used with: arrayType times elementValue. +- The library msgdigest.s7i has been refactored to use fixed size + arrays. The reduction in run-time for some functions is md5: 6%, + sha1: 26%, sha256: 21%, sha512: 22%. +- The library lzma.s7i has been refactored to use fixed size arrays. + The run-time of the XZ decompression has been reduced by 10%. +- The library jpeg.s7i has been refactored to use the fixed size + array type dataBlockType instead of array integer. +- In jpeg.s7i the restart interval handling (with mcuCount) has been + improved. +- The libraries deflate.s7i and gzip.s7i have been refactored to use + a fixed size array for the sliding window. +- The library aes_gcm.s7i has been refactored to use fixed size + arrays for the factor H. +- The interface types for bitStream and huffmanTable have been + removed. This way, bitStream and huffmanTable functions are called + without dynamic dispatch. This change reduces the run-time of the + function readJpeg() by 5.2% (measured with gcc and valgrind and + the s7c options -oc3 -O3). +- The templates DECLARE_CcittModifiedGroup3Fax_FUNCTIONS, + DECLARE_CcittT6Fax_FUNCTIONS and DECLARE_CcittT4Fax2d_FUNCTIONS + have been added to ccittfax.s7i. The templates are instantiated + for MSB and LSB bit ordering. This way ccittfax functions work + without dynamic dispatch. +- A declaration of the template DECLARE_MIN_MAX has been added to + integer.s7i. This template is used to define the functions min() + and max() for the types bigInteger, bigRational, float, integer + and rational (in bigint.s7i, bigrat.s7i, float.s7i, integer.s7i + and rational.s7i respectively). +- Now non-SYMLINK getters and setters in cpio.s7i, tar.s7i and + rpm.s7i follow relative symlinks inside the archive. +- Getters for fileMode, mTime, owner and group of symbolic links + have been added to cpio.s7i, tar.s7i and rpm.s7i. +- Setters for mTime, owner and group of symbolic links have been + added to cpio.s7i, tar.s7i and rpm.s7i. +- In osfiles.s7i SYMLINK setters for mTime, owner and group have + been added for the type osFileSys. +- Setter interface functions for mTime, owner and group of symbolic + links have been added to filesys.s7i. +- The functions removeDotFiles and symlinkDestination have been + added to filesys.s7i. +- In encoding.s7i the functions toBase and toBase58 have been fixed + to allow encoding "". The functions toBase and fromBase have been + improved to work with any digit for 0 (toBase58 encodes 0 with 1). +- In scanfile.s7i the function getLineComment has been fixed to + leave line endings unchanged. +- In scanstri.s7i the function getEscapeSequence has been fixed to + assume that numeric escape sequences end with a semicolon (;). + The function getNumber has been refactored as well. +- A definition of HASHELEMOBJECT has been added to category.s7i. +- The function conv2unicode in the charsets.s7i library has been + improved to use a for-each loop. +- A declaration of the function arrayLength has been added to the + progs.s7i library. This function is used by the compiler. +- The Seed7 compiler (s7c.sd7) has been improved: + - The maximum and minimum values in a constant integer array are + determined. This way the range of possible values for indexing + into this array can be estimated. This allows for the removal of + some overflow checks. The run-time of the function md5() has + been reduced by 2.6% (measured with gcc and valgrind and the s7c + options -oc3 -O3). + - Now assignments with the times operator like + dest := aSize times 0 + are optimized to use memset(). + - Assignments to an integer array where the source array contains + only zeros are optimized to use memset(). The assignment does + realloc the array if the size changes. For fixed size arrays the + check of the size and the call of realloc is optimized away. + - For fixed size arrays index checks are optimized away if the + range of possible index values is always inside the array. This + optimization reduces the run-time of the function readJpeg() + by 7.5% (measured with gcc and valgrind and the s7c options + -oc3 -O3). + - Fixed size array assignments have been improved to omit the + copy of minIdx and maxIdx (for fixed size arrays they cannot + change with an assignment). + - The index check for fixed size arrays has been simplified. For + these arrays the lower and upper bounds of the index are known + at compile time. This optimization reduces the run-time of the + function readJpeg() by 7.9% (measured with gcc and valgrind and + the s7c options -oc3 -O3). + - Indexing into an array has been improved for fixed size arrays + if the index checks are suppressed. + - In str_act.s7i the index check for the fixLen substring + operation (stri[start fixLen length]) has been simplified. + - Now the division of product with mdiv is optimized. The division + or the multiplication is removed if possible. + - The recognition of constant expressions has been improved. + Constants defined with a parameter list are not considered + constant if at least one parameter is not constant. + - The code generation in set_act.s7i has been improved to avoid + adjacent - operators (e.g. number--1). + - Now a generic function for user defined hashCode function is + generated. + - In int_act.s7i the statistic of suppressed range checks has been + improved. +- Regression tests which create adjacent - operators in the + generated C code have been added to chkset.sd7. +- In drw_x11.c the graphics driver has been improved to support + window titles with Unicode. +- In chkccomp.c test programs have been improved to call + XRenderQueryExtension() only if XOpenDisplay("") succeeded. +- In bitdata.s7i the deprecated functions getBitLsb(), getBitsLsb(), + peekBitsLsb(), skipBitsLsb(), getBitMsb(), getBitsMsb(), + peekBitsMsb() and skipBitsMsb() with a string as parameter have + been removed. The functions with the types lsbBitStream and + msbBitStream should be used instead. +- Tests for the deprecated bitdata functions with a string as + parameter (getBitLsb, getBitsLsb, peekBitsLsb, getBitMsb, + getBitsMsb and peekBitsMsb) have been removed from chkbitdata.sd7. +- In huffman.s7i the deprecated functions + getHuffmanSymbolMsb(string, ...) and + getHuffmanSymbolLsb(string, ...) have been removed. The functions + getHuffmanSymbol(msbBitStream, ...) and + getHuffmanSymbol(lsbBitStream, ...) should be used instead. +- In strifile.s7i the deprecated function openStrifile() has been + removed. The function openStriFile() should be used instead. +- In stritext.s7i the deprecated function openStritext() has been + removed. The function openStriText() should be used instead. +- The syntax of hash literals and fixed size arrays has been added + to syntax.s7i. +- Generic hashCode functions have been introduced in big_gmp.c, + big_rtl.c, bst_rtl.c, int_rtl.c, pcs_rtl.c, set_rtl.c and + str_rtl.c. Function prototypes of these functions are defined + in big_act.s7i, bst_act.s7i, pcs_act.s7i, set_act.s7i and + str_act.s7i. Function pointers to these functions are used by + s7c.sd7 in the function action_address. +- The functions hsh_concat_key_value, hsh_gen_hash and + hsh_gen_key_value have been added to hshlib.c. +- The functions hshConcatKeyValue, hshGenHash and hshGenKeyValue + have been added to hsh_rtl.c. +- The function bld_hashelem_temp has been added to objutl.c. +- Interpreter and compiler have been improved to support the actions + HSH_CONCAT_KEY_VALUE, HSH_GEN_HASH and HSH_GEN_KEY_VALUE. +- Logging functions have been improved in drw_win.c, drw_x11.c, + hshlib.c and sctlib.c. +- Documentation comments have been improved in array.s7i, bin32.s7i, + bin64.s7i, cpio.s7i, hash.s7i, rpm.s7i, tar.s7i and int_rtl.c. + 20240322: - The compiler has been fixed to be able to compile itself without using the X11 library. Many thanks to Pietro Cerutti for pointing diff --git a/doc/faq.htm b/doc/faq.htm index ab48e3ba..1b37582c 100644 --- a/doc/faq.htm +++ b/doc/faq.htm @@ -2274,11 +2274,13 @@

string from its byte-length. In an UTF-8 or UTF-16 string the number of code points must be computed by processing the whole string. Computing the length of an UTF-32 string does not need such an effort. -
  • Accessing a code point with an index in an UTF-32 string is simple as well. +
  • Accessing a code point with an index into an UTF-32 string is simple as well. With UTF-8 and UTF-16 it is necessary to process all code points up to the index. It has been argued, that most strings are processed - sequentially. UTF-32 strings can be processed sequentially, but if - the processing is not sequentially UTF-32 has a big advantage.
  • + sequentially. To process UTF-8 strings sequentially multi-byte + encodings must be decoded to code points. UTF-32 strings don't need + any decoding when code points are accessed. Additionally the + processing of UTF-32 strings is not restricted to be sequencial.
  • UTF-8 has invalid byte sequences. In UTF-16, single surrogate characters are invalid. A string library, that is based on UTF-8 or UTF-16 must check for valid byte sequences. UTF-32 does not have invalid byte diff --git a/doc/faq.txt b/doc/faq.txt index dd369ce1..4325f1b3 100644 --- a/doc/faq.txt +++ b/doc/faq.txt @@ -1741,11 +1741,13 @@ The usage of UTF-32 for strings in a program has several advantages: string from its byte-length. In an UTF-8 or UTF-16 string the number of code points must be computed by processing the whole string. Computing the length of an UTF-32 string does not need such an effort. - - Accessing a code point with an index in an UTF-32 string is simple as well. + - Accessing a code point with an index into an UTF-32 string is simple as well. With UTF-8 and UTF-16 it is necessary to process all code points up to the index. It has been argued, that most strings are processed - sequentially. UTF-32 strings can be processed sequentially, but if - the processing is not sequentially UTF-32 has a big advantage. + sequentially. To process UTF-8 strings sequentially multi-byte + encodings must be decoded to code points. UTF-32 strings don't need + any decoding when code points are accessed. Additionally the + processing of UTF-32 strings is not restricted to be sequencial. - UTF-8 has invalid byte sequences. In UTF-16, single surrogate characters are invalid. A string library, that is based on UTF-8 or UTF-16 must check for valid byte sequences. UTF-32 does not have invalid byte diff --git a/doc/manual.htm b/doc/manual.htm index f96069ba..7557ee30 100644 --- a/doc/manual.htm +++ b/doc/manual.htm @@ -242,10 +242,12 @@

    CONTENTS

  • Constants
  • For loop and float expressions
  • Arrays
  • +
  • Hashes
  • For loop and containers
  • Functions
  • Parameters
  • Overloading
  • +
  • Templates
  • Declare a statement
  • Template declaring a statement
  • DECLARATIONS
      @@ -889,7 +891,7 @@

      CONTENTS

      writeln("Are you the inventor of Linux?"); otherwise: writeln("Hi " <& name <& "!"); - end case; + end case; end func;

      As it can be seen, the keyword when is followed @@ -1266,52 +1268,62 @@

      CONTENTS

      This array literal has the type array [char] string. The minimum index of this array is the character '0'.

      -

      2.7 For loop and containers

      +

      2.7 Hashes

      - For-loops can also iterate over the elements of a set: + A hash is similar to an array with the difference that the index + can be any type (not just one that can be converted to integer). The + type hash [string] integer defines a hash with a string as index + and an integer as value. This type can be used in a type declaration:

      -$ include "seed7_05.s7i";
      -
      -const proc: main is func
      -  local
      -    var string: innerPlanet is "";
      -  begin
      -    for innerPlanet range {"Mercury", "Venus", "Earth", "Mars"} do
      -      write(innerPlanet <& " ");
      -    end for;
      -    writeln;
      -  end func;
      +const type: nameToDigitType is hash [string] integer;
       

      - In the example above {"Mercury", "Venus", "Earth", "Mars"} is a set - literal. The type of this literal is set of string. Other set literals are: + A hash literal can be used to initialize hash constants or variables:

      -{1, 2}
      -{'a', 'e', 'i', 'o', 'u'}
      +const nameToDigitType: nameToDigit is [] (
      +    ["zero" : 0], ["one" : 1], ["two"   : 2], ["three" : 3], ["four" : 4],
      +    ["five" : 5], ["six" : 6], ["seven" : 7], ["eight" : 8], ["nine" : 9]);
       

      - For-loops can iterate over the characters of a string: + Like with arrays an element in the hash can be accessed with +

      +nameToDigit[name]
      +

      + The following example asks for digit names and writes the + corresponding digit:

       $ include "seed7_05.s7i";
       
      +const type: nameToDigitType is hash [string] integer;
      +
       const proc: main is func
         local
      -    const set of char: vowels is {'a', 'e', 'i', 'o', 'u'};
      -    var char: letter is ' ';
      +    const nameToDigitType: nameToDigit is [] (
      +        ["zero" : 0], ["one" : 1], ["two"   : 2], ["three" : 3], ["four" : 4],
      +        ["five" : 5], ["six" : 6], ["seven" : 7], ["eight" : 8], ["nine" : 9]);
      +    var string: name is "";
         begin
      -    for letter range "the quick brown fox jumps over the lazy dog" do
      -      if letter not in vowels then
      -        write(letter);
      -      end if;
      -    end for;
      -    writeln;
      +    write("Enter the name of a digit: ");
      +    readln(name);
      +    if name in nameToDigit then
      +      writeln("The value of " <& name <& " is " <& nameToDigit[name]);
      +    else
      +      writeln("You entered " <& name <& ", which is not the name of a digit.");
      +    end if;
         end func;
       

      - A hash is similar to an array with the difference that the index - can be any type (not just one that can be converted to integer). The - type hash [string] integer defines a hash with a string as index - and an integer as value. The example below uses keyDescription - which is defined as hash [char] string in "keydescr.s7i". It - contains descriptive texts for keyboard keys. A for-loop can loop - over the values of a hash: + In the example above +

      +name in nameToDigit
      +

      + checks if the key name is in the hash table nameToDigit. This + assures that getting the corresponding value with +

      +nameToDigit[name]
      +

      + succeeds. For-each loops can be used with hash tables as well. + The example below uses keyDescription which is defined as + hash [char] string in "keydescr.s7i". It contains descriptive + texts for keyboard keys. A for-loop can loop over the values of + a hash:

       $ include "seed7_05.s7i";
         include "keydescr.s7i";
      @@ -1340,6 +1352,46 @@ 

      CONTENTS

      writeln("const char: " <& description <& " is " <& literal(aChar)); end for; end func; +

      + +

      2.8 For loop and containers

      +

      + For-loops can also iterate over the elements of a set: +

      +$ include "seed7_05.s7i";
      +
      +const proc: main is func
      +  local
      +    var string: innerPlanet is "";
      +  begin
      +    for innerPlanet range {"Mercury", "Venus", "Earth", "Mars"} do
      +      write(innerPlanet <& " ");
      +    end for;
      +    writeln;
      +  end func;
      +

      + In the example above {"Mercury", "Venus", "Earth", "Mars"} is a set + literal. The type of this literal is set of string. Other set literals are: +

      +{1, 2}
      +{'a', 'e', 'i', 'o', 'u'}
      +

      + For-loops can iterate over the characters of a string: +

      +$ include "seed7_05.s7i";
      +
      +const proc: main is func
      +  local
      +    const set of char: vowels is {'a', 'e', 'i', 'o', 'u'};
      +    var char: letter is ' ';
      +  begin
      +    for letter range "the quick brown fox jumps over the lazy dog" do
      +      if letter not in vowels then
      +        write(letter);
      +      end if;
      +    end for;
      +    writeln;
      +  end func;
       

      A for-loop can loop over the keys (indices) and values of a array:

      @@ -1377,7 +1429,7 @@ 

      CONTENTS

      end func;
      -

      2.8 Functions

      +

      2.9 Functions

      The program below uses the function flipCoin to flip a coin until the result is heads: @@ -1470,7 +1522,7 @@

      CONTENTS

      the result part is mandatory.

      -

      2.9 Parameters

      +

      2.10 Parameters

      Most parameters are not changed inside a function. Seed7 uses 'in' parameters to describe this situation: @@ -1598,7 +1650,7 @@

      CONTENTS

      over an explicit 'val' and 'ref' parameter.

      -

      2.10 Overloading

      +

      2.11 Overloading

      Functions are not only identified by identifiers but also via the types of their parameters. So several versions of a @@ -1678,7 +1730,35 @@

      CONTENTS

      above are taken from the mixarith.s7i library.

      -

      2.11 Declare a statement

      +

      2.12 Templates

      +

      + Templates allow the declaration of functions where the actual + types are specified later. The function declaraions are done + inside a procedure that has a type as parameter. E.g.: +

      +const proc: DECLARE_MIN_MAX (in type: aType) is func
      +  begin
      +
      +    const func aType: min (in aType: value1, in aType: value2) is
      +        return value1 < value2 ? value1 : value2;
      +
      +    const func aType: max (in aType: value1, in aType: value2) is
      +        return value1 > value2 ? value1 : value2;
      +
      +  end func;
      +

      + The procedure DECLARE_MIN_MAX uses the type parameter aType + to declare the functions min and max. The template must be + instantiated for every concret type which needs min and max. E.g.: +

      +DECLARE_MIN_MAX(integer);
      +DECLARE_MIN_MAX(bigInteger);
      +DECLARE_MIN_MAX(float);
      +

      + This allows expressions like min(2, 5) or min(PI, E). +

      + +

      2.13 Declare a statement

      This example program writes its arguments

      @@ -1721,7 +1801,7 @@ 

      CONTENTS

      Because of these powerful features Seed7 does not need iterators.

      -

      2.12 Template declaring a statement

      +

      2.14 Template declaring a statement

      Templates are just normal functions with types as parameters. The following template function declares for-statements: @@ -5314,7 +5394,8 @@

      CONTENTS

      This defines aHashType as a hash type with integer elements and string keys. Variables of this type are declared with:

      -var aHashType: aHashTable is aHashType.value;
      +var aHashType: aHashTable1 is aHashType.value;                # Empty hash table.
      +var aHashType: aHashTable2 is [] (["one" : 1], ["two" : 2]);  # Hash with two elements which map strings to integers.
       

      The expressions aHashType.value and aHashType.EMPTY_HASH describe empty hash tables. Beside them there are no hash table literals. @@ -5322,6 +5403,8 @@

      CONTENTS

      and compare. Besides this the keyType can be any type. The hash functions are defined in the library "hash.s7i".

      +    Literal:
      +      [] ([key1 : value1], [key2 : value2])  Create a hash with the given keys and corresponding values.
           Constants:
             hashType.EMPTY_HASH  Empty hash table
           Infix operators:
      @@ -5335,6 +5418,8 @@ 

      CONTENTS

      [ A ] Access one hash table element ( Type of argument A: keyType, Type of result: baseType ) + Relations: + =, <> Functions: length(A) Number of elements in hash table A ( Type of result: integer, @@ -14504,8 +14589,8 @@

      CONTENTS

      - - + + diff --git a/doc/manual.txt b/doc/manual.txt index 3826dee3..e4a35848 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -31,12 +31,14 @@ CONTENTS 2.4 Constants 2.5 For loop and float expressions 2.6 Arrays - 2.7 For loop and containers - 2.8 Functions - 2.9 Parameters - 2.10 Overloading - 2.11 Declare a statement - 2.12 Template declaring a statement + 2.7 Hashes + 2.8 For loop and containers + 2.9 Functions + 2.10 Parameters + 2.11 Overloading + 2.12 Templates + 2.13 Declare a statement + 2.14 Template declaring a statement 3. DECLARATIONS 3.1 Variable declarations 3.2 Constant declarations @@ -1055,52 +1057,62 @@ CONTENTS This array literal has the type 'array [char] string'. The minimum index of this array is the character '0'. -2.7 For loop and containers +2.7 Hashes - For-loops can also iterate over the elements of a 'set': + A 'hash' is similar to an 'array' with the difference that the index + can be any type (not just one that can be converted to 'integer'). The + type 'hash [string] integer' defines a hash with a 'string' as index + and an 'integer' as value. This type can be used in a type declaration: - $ include "seed7_05.s7i"; + const type: nameToDigitType is hash [string] integer; - const proc: main is func - local - var string: innerPlanet is ""; - begin - for innerPlanet range {"Mercury", "Venus", "Earth", "Mars"} do - write(innerPlanet <& " "); - end for; - writeln; - end func; + A hash literal can be used to initialize hash constants or variables: - In the example above '{"Mercury", "Venus", "Earth", "Mars"}' is a set - literal. The type of this literal is 'set of string'. Other set literals are: + const nameToDigitType: nameToDigit is [] ( + ["zero" : 0], ["one" : 1], ["two" : 2], ["three" : 3], ["four" : 4], + ["five" : 5], ["six" : 6], ["seven" : 7], ["eight" : 8], ["nine" : 9]); - {1, 2} - {'a', 'e', 'i', 'o', 'u'} + Like with arrays an element in the hash can be accessed with - For-loops can iterate over the characters of a 'string': + nameToDigit[name] + + The following example asks for digit names and writes the + corresponding digit: $ include "seed7_05.s7i"; + const type: nameToDigitType is hash [string] integer; + const proc: main is func local - const set of char: vowels is {'a', 'e', 'i', 'o', 'u'}; - var char: letter is ' '; + const nameToDigitType: nameToDigit is [] ( + ["zero" : 0], ["one" : 1], ["two" : 2], ["three" : 3], ["four" : 4], + ["five" : 5], ["six" : 6], ["seven" : 7], ["eight" : 8], ["nine" : 9]); + var string: name is ""; begin - for letter range "the quick brown fox jumps over the lazy dog" do - if letter not in vowels then - write(letter); - end if; - end for; - writeln; + write("Enter the name of a digit: "); + readln(name); + if name in nameToDigit then + writeln("The value of " <& name <& " is " <& nameToDigit[name]); + else + writeln("You entered " <& name <& ", which is not the name of a digit."); + end if; end func; - A 'hash' is similar to an 'array' with the difference that the index - can be any type (not just one that can be converted to 'integer'). The - type 'hash [string] integer' defines a hash with a 'string' as index - and an 'integer' as value. The example below uses 'keyDescription' - which is defined as 'hash [char] string' in "keydescr.s7i". It - contains descriptive texts for keyboard keys. A for-loop can loop - over the values of a 'hash': + In the example above + + name in nameToDigit + + checks if the key 'name' is in the hash table 'nameToDigit'. This + assures that getting the corresponding value with + + nameToDigit[name] + + succeeds. For-each loops can be used with hash tables as well. + The example below uses 'keyDescription' which is defined as + 'hash [char] string' in "keydescr.s7i". It contains descriptive + texts for keyboard keys. A for-loop can loop over the values of + a 'hash': $ include "seed7_05.s7i"; include "keydescr.s7i"; @@ -1130,6 +1142,46 @@ CONTENTS end for; end func; + +2.8 For loop and containers + + For-loops can also iterate over the elements of a 'set': + + $ include "seed7_05.s7i"; + + const proc: main is func + local + var string: innerPlanet is ""; + begin + for innerPlanet range {"Mercury", "Venus", "Earth", "Mars"} do + write(innerPlanet <& " "); + end for; + writeln; + end func; + + In the example above '{"Mercury", "Venus", "Earth", "Mars"}' is a set + literal. The type of this literal is 'set of string'. Other set literals are: + + {1, 2} + {'a', 'e', 'i', 'o', 'u'} + + For-loops can iterate over the characters of a 'string': + + $ include "seed7_05.s7i"; + + const proc: main is func + local + const set of char: vowels is {'a', 'e', 'i', 'o', 'u'}; + var char: letter is ' '; + begin + for letter range "the quick brown fox jumps over the lazy dog" do + if letter not in vowels then + write(letter); + end if; + end for; + writeln; + end func; + A for-loop can loop over the keys (indices) and values of a 'array': $ include "seed7_05.s7i"; @@ -1166,7 +1218,7 @@ CONTENTS end func; -2.8 Functions +2.9 Functions The program below uses the function 'flipCoin' to flip a coin until the result is heads: @@ -1259,7 +1311,7 @@ CONTENTS the 'result' part is mandatory. -2.9 Parameters +2.10 Parameters Most parameters are not changed inside a function. Seed7 uses 'in' parameters to describe this situation: @@ -1387,7 +1439,7 @@ CONTENTS over an explicit 'val' and 'ref' parameter. -2.10 Overloading +2.11 Overloading Functions are not only identified by identifiers but also via the types of their parameters. So several versions of a @@ -1467,7 +1519,35 @@ CONTENTS above are taken from the "mixarith.s7i" library. -2.11 Declare a statement +2.12 Templates + + Templates allow the declaration of functions where the actual + types are specified later. The function declaraions are done + inside a procedure that has a type as parameter. E.g.: + + const proc: DECLARE_MIN_MAX (in type: aType) is func + begin + + const func aType: min (in aType: value1, in aType: value2) is + return value1 < value2 ? value1 : value2; + + const func aType: max (in aType: value1, in aType: value2) is + return value1 > value2 ? value1 : value2; + + end func; + + The procedure 'DECLARE_MIN_MAX' uses the type parameter 'aType' + to declare the functions 'min' and 'max'. The template must be + instantiated for every concret type which needs 'min' and 'max'. E.g.: + + DECLARE_MIN_MAX(integer); + DECLARE_MIN_MAX(bigInteger); + DECLARE_MIN_MAX(float); + + This allows expressions like 'min(2, 5)' or 'min(PI, E)'. + + +2.13 Declare a statement This example program writes its arguments @@ -1510,7 +1590,7 @@ CONTENTS Because of these powerful features Seed7 does not need iterators. -2.12 Template declaring a statement +2.14 Template declaring a statement Templates are just normal functions with types as parameters. The following template function declares for-statements: @@ -5103,7 +5183,8 @@ CONTENTS This defines 'aHashType' as a hash type with 'integer' elements and 'string' keys. Variables of this type are declared with: - var aHashType: aHashTable is aHashType.value; + var aHashType: aHashTable1 is aHashType.value; # Empty hash table. + var aHashType: aHashTable2 is [] (["one" : 1], ["two" : 2]); # Hash with two elements which map strings to integers. The expressions 'aHashType.value' and 'aHashType.EMPTY_HASH' describe empty hash tables. Beside them there are no hash table literals. @@ -5111,6 +5192,8 @@ CONTENTS and 'compare'. Besides this the 'keyType' can be any type. The 'hash' functions are defined in the library "hash.s7i". + Literal: + [] ([key1 : value1], [key2 : value2]) Create a 'hash' with the given keys and corresponding values. Constants: hashType.EMPTY_HASH Empty hash table Infix operators: @@ -5124,6 +5207,8 @@ CONTENTS [ A ] Access one hash table element ( Type of argument A: keyType, Type of result: baseType ) + Relations: + =, <> Functions: length(A) Number of elements in hash table A ( Type of result: integer, @@ -14293,8 +14378,8 @@ This way a program can also receive KEY_CLOSE and KEY_RESIZE: Action name drwlib.c function kbd_rtl.c/drw_x11.c/drw_win.c function GKB_BUTTON_PRESSED gkb_button_pressed gkbButtonPressed - GKB_BUTTON_XPOS gkb_button_xpos gkbButtonXpos - GKB_BUTTON_YPOS gkb_button_ypos gkbButtonYpos + GKB_CLICKED_XPOS gkb_clicked_xpos gkbClickedXpos + GKB_CLICKED_YPOS gkb_clicked_ypos gkbClickedYpos GKB_GETC gkb_getc gkbGetc GKB_GETS gkb_gets gkbGets GKB_INPUT_READY gkb_input_ready gkbInputReady diff --git a/prg/files.txt b/prg/files.txt index 60e11eb6..b376add8 100644 --- a/prg/files.txt +++ b/prg/files.txt @@ -185,6 +185,7 @@ file.s7i Interface type describing sequential files. filebits.s7i File mode bits used by archive file systems. filesys.s7i Interface for file systems (os, tar, zip, ...) fileutil.s7i File utility functions. +fixarray.s7i Support for arrays with a fixed size float.s7i Floating point support library font.s7i Defines the font interface font8x8.s7i font with 8x8 pixel used by TI-99/4A. @@ -251,12 +252,12 @@ process.s7i Support for creating processes progs.s7i Program handling support library propertyfile.s7i Read key-value pairs from a property file rational.s7i Rational number support library -readjson.s7i Experimental functions to read JSON files ref_list.s7i Reference list support library reference.s7i Reference to object support library reverse.s7i Filter file which writes right to left on output rpm.s7i Rpm archive library scanfile.s7i File scanner functions +scanjson.s7i String and file scanner functions for JSON scanstri.s7i String scanner functions seed7_05.s7i Standard Seed7 library set.s7i Support for sets of a base type diff --git a/src/read_me.htm b/src/read_me.htm index 2ba74f17..fb33f676 100644 --- a/src/read_me.htm +++ b/src/read_me.htm @@ -721,12 +721,18 @@ contain the C compilers clang and gcc. They also provide a 'make' utility. Depending on the version of macOS it might be necessary to install also XQuartz (the X11 support of macOS). - If the x11 lib is not found it can be installed using brew: + XQuartz can be installed using brew: +

      +brew install --cask xquartz
      +

      + After installing XQuartz the computer should be rebooted. If + the x11 lib is not found it can be installed using brew:

       brew install libx11
       

      - The brew location must be linked to to /usr/local/include, - so the C compiler can find it: + If /usr/local/include/X11 does not exist the brew location + must be linked to to /usr/local/include, so the C compiler + can find it:

       sudo ln -s /opt/homebrew/include/X11 /usr/local/include/X11
       

      diff --git a/src/read_me.txt b/src/read_me.txt index 7f00433f..ee3233b1 100644 --- a/src/read_me.txt +++ b/src/read_me.txt @@ -510,12 +510,18 @@ COMPILING UNDER MAC OS contain the C compilers clang and gcc. They also provide a 'make' utility. Depending on the version of macOS it might be necessary to install also XQuartz (the X11 support of macOS). - If the x11 lib is not found it can be installed using brew: + XQuartz can be installed using brew: + + brew install --cask xquartz + + After installing XQuartz the computer should be rebooted. If + the x11 lib is not found it can be installed using brew: brew install libx11 - The brew location must be linked to to /usr/local/include, - so the C compiler can find it: + If /usr/local/include/X11 does not exist the brew location + must be linked to to /usr/local/include, so the C compiler + can find it: sudo ln -s /opt/homebrew/include/X11 /usr/local/include/X11

      Action name drwlib.c function kbd_rtl.c/drw_x11.c/drw_win.c function
      GKB_BUTTON_PRESSED gkb_button_pressed gkbButtonPressed
      GKB_BUTTON_XPOS gkb_button_xpos gkbButtonXpos
      GKB_BUTTON_YPOS gkb_button_ypos gkbButtonYpos
      GKB_CLICKED_XPOS gkb_clicked_xpos gkbClickedXpos
      GKB_CLICKED_YPOS gkb_clicked_ypos gkbClickedYpos
      GKB_GETC gkb_getc gkbGetc
      GKB_GETS gkb_gets gkbGets
      GKB_INPUT_READY gkb_input_ready gkbInputReady