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 @@
As it can be seen, the keyword when is followed @@ -1266,52 +1268,62 @@
- 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; +
+ 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;
The program below uses the function flipCoin to flip a coin until the result is heads: @@ -1470,7 +1522,7 @@
Most parameters are not changed inside a function. Seed7 uses 'in' parameters to describe this situation: @@ -1598,7 +1650,7 @@
Functions are not only identified by identifiers but also via the types of their parameters. So several versions of a @@ -1678,7 +1730,35 @@
+ 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). +
+ +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
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 |