aboutsummaryrefslogtreecommitdiff
path: root/gcc/m2
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2023-12-13 17:35:02 +0000
committerGaius Mulley <gaiusmod2@gmail.com>2023-12-13 17:35:02 +0000
commit33a3f85ee4b5bc562a84c6896294278e0a5ab160 (patch)
treeddef3e0fba0eb60905c5f0ccb1caed7747d8beb6 /gcc/m2
parent90bc2d09b5bfcc913f79543c3b65202e7246e162 (diff)
downloadgcc-33a3f85ee4b5bc562a84c6896294278e0a5ab160.zip
gcc-33a3f85ee4b5bc562a84c6896294278e0a5ab160.tar.gz
gcc-33a3f85ee4b5bc562a84c6896294278e0a5ab160.tar.bz2
PR modula2/112921 missing modules shortreal shortstr shortconv convstringshort
For completeness here are three SHORTREAL modules which match their LONGREAL and REAL counterparts. The datatype SHORTREAL is a GNU extension and these modules were missing. gcc/m2/ChangeLog: PR modula2/112921 * gm2-libs-iso/ConvStringShort.def: New file. * gm2-libs-iso/ConvStringShort.mod: New file. * gm2-libs-iso/ShortConv.def: New file. * gm2-libs-iso/ShortConv.mod: New file. * gm2-libs-iso/ShortMath.def: New file. * gm2-libs-iso/ShortMath.mod: New file. * gm2-libs-iso/ShortStr.def: New file. * gm2-libs-iso/ShortStr.mod: New file. libgm2/ChangeLog: PR modula2/112921 * libm2iso/Makefile.am (M2DEFS): Add ConvStringShort.def, ShortConv.def, ShortMath.def and ShortStr.def. (M2MODS): Add ConvStringShort.mod, ShortConv.mod, ShortMath.mod and ShortStr.mod. * libm2iso/Makefile.in: Regenerate. gcc/testsuite/ChangeLog: PR modula2/112921 * gm2/iso/run/pass/shorttest.mod: New test. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc/m2')
-rw-r--r--gcc/m2/gm2-libs-iso/ConvStringShort.def60
-rw-r--r--gcc/m2/gm2-libs-iso/ConvStringShort.mod69
-rw-r--r--gcc/m2/gm2-libs-iso/ShortConv.def73
-rw-r--r--gcc/m2/gm2-libs-iso/ShortConv.mod350
-rw-r--r--gcc/m2/gm2-libs-iso/ShortMath.def76
-rw-r--r--gcc/m2/gm2-libs-iso/ShortMath.mod110
-rw-r--r--gcc/m2/gm2-libs-iso/ShortStr.def87
-rw-r--r--gcc/m2/gm2-libs-iso/ShortStr.mod150
8 files changed, 975 insertions, 0 deletions
diff --git a/gcc/m2/gm2-libs-iso/ConvStringShort.def b/gcc/m2/gm2-libs-iso/ConvStringShort.def
new file mode 100644
index 0000000..a6b485c
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ConvStringShort.def
@@ -0,0 +1,60 @@
+(* ConvStringShort.def converts floating point numbers to Strings.
+
+Copyright (C) 2009-2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+DEFINITION MODULE ConvStringShort ;
+
+FROM DynamicStrings IMPORT String ;
+
+
+(*
+ RealToFloatString - converts a real with, sigFigs, into a string
+ and returns the result as a string.
+*)
+
+PROCEDURE RealToFloatString (real: SHORTREAL; sigFigs: CARDINAL) : String ;
+
+
+(*
+ RealToEngString - converts the value of real to floating-point
+ string form, with sigFigs significant figures.
+ The number is scaled with one to three digits
+ in the whole number part and with an exponent
+ that is a multiple of three.
+*)
+
+PROCEDURE RealToEngString (real: SHORTREAL; sigFigs: CARDINAL) : String ;
+
+
+(*
+ RealToFixedString - returns the number of characters in the fixed-point
+ string representation of real rounded to the given
+ place relative to the decimal point.
+*)
+
+PROCEDURE RealToFixedString (real: SHORTREAL; place: INTEGER) : String ;
+
+
+END ConvStringShort.
diff --git a/gcc/m2/gm2-libs-iso/ConvStringShort.mod b/gcc/m2/gm2-libs-iso/ConvStringShort.mod
new file mode 100644
index 0000000..064027c
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ConvStringShort.mod
@@ -0,0 +1,69 @@
+(* ConvStringShort.mod converts floating point numbers to Strings.
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+IMPLEMENTATION MODULE ConvStringShort ;
+
+IMPORT ConvStringReal ;
+
+
+(*
+ RealToFloatString - converts a real with, sigFigs, into a string
+ and returns the result as a string.
+*)
+
+PROCEDURE RealToFloatString (real: SHORTREAL; sigFigs: CARDINAL) : String ;
+BEGIN
+ RETURN ConvStringReal.RealToFloatString (real, sigFigs)
+END RealToFloatString ;
+
+
+(*
+ RealToEngString - converts the value of real to floating-point
+ string form, with sigFigs significant figures.
+ The number is scaled with one to three digits
+ in the whole number part and with an exponent
+ that is a multiple of three.
+*)
+
+PROCEDURE RealToEngString (real: SHORTREAL; sigFigs: CARDINAL) : String ;
+BEGIN
+ RETURN ConvStringReal.RealToEngString (real, sigFigs)
+END RealToEngString ;
+
+
+(*
+ RealToFixedString - returns the number of characters in the fixed-point
+ string representation of real rounded to the given
+ place relative to the decimal point.
+*)
+
+PROCEDURE RealToFixedString (real: SHORTREAL; place: INTEGER) : String ;
+BEGIN
+ RETURN ConvStringReal.RealToFixedString (real, place)
+END RealToFixedString ;
+
+
+END ConvStringShort.
diff --git a/gcc/m2/gm2-libs-iso/ShortConv.def b/gcc/m2/gm2-libs-iso/ShortConv.def
new file mode 100644
index 0000000..2373c7b
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ShortConv.def
@@ -0,0 +1,73 @@
+(* ShortStr.mod provides low level SHORTREAL/string conversions.
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+DEFINITION MODULE ShortConv;
+
+IMPORT
+ ConvTypes;
+
+TYPE
+ ConvResults = ConvTypes.ConvResults; (* strAllRight, strOutOfRange,
+ strWrongFormat, strEmpty *)
+
+PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState);
+ (* Represents the start state of a finite state scanner for real
+ numbers - assigns class of inputCh to chClass and a procedure
+ representing the next state to nextState.
+ *)
+
+PROCEDURE FormatReal (str: ARRAY OF CHAR): ConvResults;
+ (* Returns the format of the string value for conversion to LONGREAL. *)
+
+PROCEDURE ValueReal (str: ARRAY OF CHAR): SHORTREAL;
+ (* Returns the value corresponding to the real number string value
+ str if str is well-formed; otherwise raises the ShortConv exception.
+ *)
+
+PROCEDURE LengthFloatReal (real: SHORTREAL; sigFigs: CARDINAL): CARDINAL;
+ (* Returns the number of characters in the floating-point string
+ representation of real with sigFigs significant figures.
+ *)
+
+PROCEDURE LengthEngReal (real: SHORTREAL; sigFigs: CARDINAL): CARDINAL;
+ (* Returns the number of characters in the floating-point engineering
+ string representation of real with sigFigs significant figures.
+ *)
+
+PROCEDURE LengthFixedReal (real: SHORTREAL; place: INTEGER): CARDINAL;
+ (* Returns the number of characters in the fixed-point string
+ representation of real rounded to the given place relative to the
+ decimal point.
+ *)
+
+PROCEDURE IsRConvException (): BOOLEAN;
+ (* Returns TRUE if the current coroutine is in the exceptional
+ execution state because of the raising of an exception in a
+ routine from this module; otherwise returns FALSE.
+ *)
+
+END ShortConv.
diff --git a/gcc/m2/gm2-libs-iso/ShortConv.mod b/gcc/m2/gm2-libs-iso/ShortConv.mod
new file mode 100644
index 0000000..66f31b5
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ShortConv.mod
@@ -0,0 +1,350 @@
+(* ShortConv.mod implement the ISO ShortConv specification.
+
+Copyright (C) 2009-2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+IMPLEMENTATION MODULE ShortConv ;
+
+FROM SYSTEM IMPORT ADDRESS ;
+FROM ConvTypes IMPORT ScanClass ;
+FROM CharClass IMPORT IsNumeric, IsWhiteSpace ;
+FROM DynamicStrings IMPORT String, InitString, InitStringCharStar, KillString, Length, Slice, Mark, Index, string ;
+FROM dtoa IMPORT strtod ;
+FROM ConvStringShort IMPORT RealToFloatString, RealToEngString, RealToFixedString ;
+FROM M2RTS IMPORT Halt ;
+FROM libc IMPORT free ;
+IMPORT EXCEPTIONS ;
+
+
+TYPE
+ RealConvException = (noException, invalid, outofrange) ;
+
+VAR
+ realConv: EXCEPTIONS.ExceptionSource ;
+
+
+(* Low-level LONGREAL/string conversions. *)
+
+(* Represents the start state of a finite state scanner for real
+ numbers - assigns class of inputCh to chClass and a procedure
+ representing the next state to nextState.
+*)
+
+PROCEDURE ScanReal (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanSecondDigit ;
+ chClass := valid
+ ELSIF (inputCh='+') OR (inputCh='-')
+ THEN
+ nextState := scanFirstDigit ;
+ chClass := valid
+ ELSIF IsWhiteSpace(inputCh)
+ THEN
+ nextState := ScanReal ;
+ chClass := padding
+ ELSE
+ nextState := ScanReal ;
+ chClass := invalid
+ END
+END ScanReal ;
+
+
+(*
+ scanFirstDigit -
+*)
+
+PROCEDURE scanFirstDigit (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanSecondDigit ;
+ chClass := valid
+ ELSE
+ nextState := scanFirstDigit ;
+ chClass := invalid
+ END
+END scanFirstDigit ;
+
+
+(*
+ scanSecondDigit -
+*)
+
+PROCEDURE scanSecondDigit (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanSecondDigit ;
+ chClass := valid
+ ELSIF inputCh='.'
+ THEN
+ nextState := scanFixed ;
+ chClass := valid
+ ELSIF inputCh='E'
+ THEN
+ nextState := scanScientific ;
+ chClass := valid
+ ELSE
+ nextState := noOpFinished ;
+ chClass := terminator
+ END
+END scanSecondDigit ;
+
+
+(*
+ scanFixed -
+*)
+
+PROCEDURE scanFixed (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanFixed ;
+ chClass := valid
+ ELSIF inputCh='E'
+ THEN
+ nextState := scanScientific ;
+ chClass := valid
+ ELSE
+ nextState := noOpFinished ;
+ chClass := terminator
+ END
+END scanFixed ;
+
+
+(*
+ scanScientific -
+*)
+
+PROCEDURE scanScientific (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanScientificSecond ;
+ chClass := valid
+ ELSIF (inputCh='-') OR (inputCh='+')
+ THEN
+ nextState := scanScientificSign ;
+ chClass := valid
+ ELSE
+ nextState := scanScientific ;
+ chClass := invalid
+ END
+END scanScientific ;
+
+
+(*
+ scanScientificSign -
+*)
+
+PROCEDURE scanScientificSign (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanScientificSecond ;
+ chClass := valid
+ ELSE
+ nextState := scanScientificSign ;
+ chClass := invalid
+ END
+END scanScientificSign ;
+
+
+(*
+ scanScientificSecond -
+*)
+
+PROCEDURE scanScientificSecond (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ IF IsNumeric(inputCh)
+ THEN
+ nextState := scanScientificSecond ;
+ chClass := valid
+ ELSE
+ nextState := noOpFinished ;
+ chClass := terminator
+ END
+END scanScientificSecond ;
+
+
+(*
+ noOpFinished -
+*)
+
+PROCEDURE noOpFinished (inputCh: CHAR; VAR chClass: ConvTypes.ScanClass;
+ VAR nextState: ConvTypes.ScanState) ;
+BEGIN
+ nextState := noOpFinished ;
+ chClass := terminator ;
+ (* should we raise an exception here? *)
+END noOpFinished ;
+
+
+(* Returns the format of the string value for conversion to LONGREAL. *)
+
+PROCEDURE FormatReal (str: ARRAY OF CHAR) : ConvResults ;
+VAR
+ proc : ConvTypes.ScanState ;
+ chClass: ConvTypes.ScanClass ;
+ i, h : CARDINAL ;
+BEGIN
+ i := 1 ;
+ h := LENGTH(str) ;
+ ScanReal(str[0], chClass, proc) ;
+ WHILE (i<h) AND (chClass=padding) DO
+ proc(str[i], chClass, proc) ;
+ INC(i)
+ END ;
+
+ IF chClass=terminator
+ THEN
+ RETURN( strEmpty )
+ END ;
+ WHILE (i<h) AND (chClass=valid) DO
+ proc(str[i], chClass, proc) ;
+ INC(i)
+ END ;
+ CASE chClass OF
+
+ padding : RETURN( strWrongFormat ) |
+ terminator,
+ valid : RETURN( strAllRight ) |
+ invalid : RETURN( strWrongFormat )
+
+ END
+END FormatReal ;
+
+
+(* Returns the value corresponding to the real number string value
+ str if str is well-formed; otherwise raises the RealConv
+ exception.
+*)
+
+PROCEDURE ValueReal (str: ARRAY OF CHAR) : SHORTREAL ;
+BEGIN
+ IF FormatReal(str)=strAllRight
+ THEN
+ RETURN( doValueReal(str) )
+ ELSE
+ EXCEPTIONS.RAISE(realConv, ORD(invalid),
+ 'ShortConv.' + __FUNCTION__ + ': real number is invalid')
+ END
+END ValueReal ;
+
+
+(*
+ doValueReal - str, is a well-formed real number and its
+ value is returned.
+*)
+
+PROCEDURE doValueReal (str: ARRAY OF CHAR) : SHORTREAL ;
+VAR
+ r : SHORTREAL ;
+ error: BOOLEAN ;
+ s : String ;
+BEGIN
+ s := InitString(str) ;
+ r := strtod (string(s), error) ;
+ s := KillString(s) ;
+ IF error
+ THEN
+ EXCEPTIONS.RAISE (realConv, ORD(outofrange),
+ 'ShortConv.' + __FUNCTION__ + ': real number is out of range')
+ END ;
+ RETURN r
+END doValueReal ;
+
+
+(* Returns the number of characters in the floating-point string
+ representation of real with sigFigs significant figures.
+*)
+
+PROCEDURE LengthFloatReal (real: SHORTREAL; sigFigs: CARDINAL) : CARDINAL ;
+VAR
+ s: String ;
+ l: CARDINAL ;
+BEGIN
+ s := RealToFloatString (real, sigFigs) ;
+ l := Length (s) ;
+ s := KillString (s) ;
+ RETURN l
+END LengthFloatReal ;
+
+
+(* Returns the number of characters in the floating-point engineering
+ string representation of real with sigFigs significant figures.
+*)
+
+PROCEDURE LengthEngReal (real: SHORTREAL; sigFigs: CARDINAL) : CARDINAL ;
+VAR
+ s: String ;
+ l: CARDINAL ;
+BEGIN
+ s := RealToEngString (real, sigFigs) ;
+ l := Length (s) ;
+ s := KillString (s) ;
+ RETURN l
+END LengthEngReal ;
+
+
+(* Returns the number of characters in the fixed-point string
+ representation of real rounded to the given place relative to the
+ decimal point.
+*)
+
+PROCEDURE LengthFixedReal (real: SHORTREAL; place: INTEGER) : CARDINAL ;
+VAR
+ s: String ;
+ l: CARDINAL ;
+BEGIN
+ s := RealToFixedString (real, place) ;
+ l := Length (s) ;
+ s := KillString (s) ;
+ RETURN l
+END LengthFixedReal ;
+
+
+(* Returns TRUE if the current coroutine is in the exceptional
+ execution state because of the raising of an exception in a
+ routine from this module; otherwise returns FALSE.
+*)
+
+PROCEDURE IsRConvException () : BOOLEAN ;
+BEGIN
+ RETURN( EXCEPTIONS.IsCurrentSource(realConv) )
+END IsRConvException ;
+
+
+BEGIN
+ EXCEPTIONS.AllocateSource (realConv)
+END ShortConv.
diff --git a/gcc/m2/gm2-libs-iso/ShortMath.def b/gcc/m2/gm2-libs-iso/ShortMath.def
new file mode 100644
index 0000000..b672e77
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ShortMath.def
@@ -0,0 +1,76 @@
+(* LongMath.def provides access to the ShortReal intrinsics.
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+DEFINITION MODULE ShortMath;
+
+ (* Mathematical functions for the type LONGREAL *)
+
+CONST
+ pi = 3.1415926535897932384626433832795028841972;
+ exp1 = 2.7182818284590452353602874713526624977572;
+
+PROCEDURE __BUILTIN__ sqrt (x: SHORTREAL): SHORTREAL;
+ (* Returns the positive square root of x *)
+
+PROCEDURE __BUILTIN__ exp (x: SHORTREAL): SHORTREAL;
+ (* Returns the exponential of x *)
+
+PROCEDURE __BUILTIN__ ln (x: SHORTREAL): SHORTREAL;
+ (* Returns the natural logarithm of x *)
+
+ (* The angle in all trigonometric functions is measured in radians *)
+
+PROCEDURE __BUILTIN__ sin (x: SHORTREAL): SHORTREAL;
+ (* Returns the sine of x *)
+
+PROCEDURE __BUILTIN__ cos (x: SHORTREAL): SHORTREAL;
+ (* Returns the cosine of x *)
+
+PROCEDURE tan (x: SHORTREAL): SHORTREAL;
+ (* Returns the tangent of x *)
+
+PROCEDURE arcsin (x: SHORTREAL): SHORTREAL;
+ (* Returns the arcsine of x *)
+
+PROCEDURE arccos (x: SHORTREAL): SHORTREAL;
+ (* Returns the arccosine of x *)
+
+PROCEDURE arctan (x: SHORTREAL): SHORTREAL;
+ (* Returns the arctangent of x *)
+
+PROCEDURE power (base, exponent: SHORTREAL): SHORTREAL;
+ (* Returns the value of the number base raised to the power exponent *)
+
+PROCEDURE round (x: SHORTREAL): INTEGER;
+ (* Returns the value of x rounded to the nearest integer *)
+
+PROCEDURE IsRMathException (): BOOLEAN;
+ (* Returns TRUE if the current coroutine is in the exceptional
+ execution state because of the raising of an exception in a
+ routine from this module; otherwise returns FALSE.
+ *)
+
+END ShortMath.
diff --git a/gcc/m2/gm2-libs-iso/ShortMath.mod b/gcc/m2/gm2-libs-iso/ShortMath.mod
new file mode 100644
index 0000000..3776b3b
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ShortMath.mod
@@ -0,0 +1,110 @@
+(* LongMath.mod implement the ISO LongMath specification.
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+IMPLEMENTATION MODULE ShortMath ;
+
+IMPORT libm ;
+IMPORT cbuiltin ;
+
+PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sqrtf)) sqrt (x: SHORTREAL): SHORTREAL;
+ (* Returns the positive square root of x *)
+BEGIN
+ RETURN cbuiltin.sqrtf (x)
+END sqrt ;
+
+PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_expf)) exp (x: SHORTREAL): SHORTREAL;
+ (* Returns the exponential of x *)
+BEGIN
+ RETURN cbuiltin.expf (x)
+END exp ;
+
+PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_logf)) ln (x: SHORTREAL): SHORTREAL;
+ (* Returns the natural logarithm of x *)
+BEGIN
+ RETURN cbuiltin.logf (x)
+END ln ;
+
+ (* The angle in all trigonometric functions is measured in radians *)
+
+PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sinf)) sin (x: SHORTREAL): SHORTREAL;
+ (* Returns the sine of x *)
+BEGIN
+ RETURN cbuiltin.sinf (x)
+END sin ;
+
+PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cosf)) cos (x: SHORTREAL): SHORTREAL;
+ (* Returns the cosine of x *)
+BEGIN
+ RETURN cbuiltin.cosf (x)
+END cos ;
+
+PROCEDURE tan (x: SHORTREAL): SHORTREAL;
+ (* Returns the tangent of x *)
+BEGIN
+ RETURN libm.tanf (x)
+END tan ;
+
+PROCEDURE arcsin (x: SHORTREAL): SHORTREAL;
+ (* Returns the arcsine of x *)
+BEGIN
+ RETURN libm.asinf (x)
+END arcsin ;
+
+PROCEDURE arccos (x: SHORTREAL): SHORTREAL;
+ (* Returns the arccosine of x *)
+BEGIN
+ RETURN libm.acosf (x)
+END arccos ;
+
+PROCEDURE arctan (x: SHORTREAL): SHORTREAL;
+ (* Returns the arctangent of x *)
+BEGIN
+ RETURN libm.atanf (x)
+END arctan ;
+
+PROCEDURE power (base, exponent: SHORTREAL): SHORTREAL;
+ (* Returns the value of the number base raised to the power exponent *)
+BEGIN
+ RETURN libm.powf (base, exponent)
+END power ;
+
+PROCEDURE round (x: SHORTREAL) : INTEGER;
+ (* Returns the value of x rounded to the nearest integer *)
+BEGIN
+ RETURN TRUNC (x)
+END round ;
+
+PROCEDURE IsRMathException (): BOOLEAN;
+ (* Returns TRUE if the current coroutine is in the
+ exceptional execution state because of the raising
+ of an exception in a routine from this module; otherwise
+ returns FALSE.
+ *)
+BEGIN
+ RETURN FALSE
+END IsRMathException ;
+
+END ShortMath.
diff --git a/gcc/m2/gm2-libs-iso/ShortStr.def b/gcc/m2/gm2-libs-iso/ShortStr.def
new file mode 100644
index 0000000..42fa9dd
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ShortStr.def
@@ -0,0 +1,87 @@
+(* ShortStr.def provides conversion between shortreal and strings.
+
+Copyright (C) 2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+DEFINITION MODULE ShortStr;
+
+ (* SHORTREAL/string conversions *)
+
+IMPORT
+ ConvTypes;
+
+TYPE
+ (* strAllRight, strOutOfRange, strWrongFormat, strEmpty *)
+ ConvResults = ConvTypes.ConvResults;
+
+(* the string form of a signed fixed-point real number is
+ ["+" | "-"], decimal digit, {decimal digit}, [".",
+ {decimal digit}]
+*)
+
+(* the string form of a signed floating-point real number is
+ signed fixed-point real number, "E", ["+" | "-"],
+ decimal digit, {decimal digit}
+*)
+
+PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: SHORTREAL;
+ VAR res: ConvResults);
+ (* Ignores any leading spaces in str. If the subsequent characters
+ in str are in the format of a signed real number, assigns a
+ corresponding value to real. Assigns a value indicating the
+ format of str to res.
+ *)
+
+PROCEDURE RealToFloat (real: SHORTREAL; sigFigs: CARDINAL;
+ VAR str: ARRAY OF CHAR);
+ (* Converts the value of real to floating-point string form, with
+ sigFigs significant figures, and copies the possibly truncated
+ result to str.
+ *)
+
+PROCEDURE RealToEng (real: SHORTREAL; sigFigs: CARDINAL;
+ VAR str: ARRAY OF CHAR);
+ (* Converts the value of real to floating-point string form, with
+ sigFigs significant figures, and copies the possibly truncated
+ result to str. The number is scaled with one to three digits
+ in the whole number part and with an exponent that is a
+ multiple of three.
+ *)
+
+PROCEDURE RealToFixed (real: SHORTREAL; place: INTEGER;
+ VAR str: ARRAY OF CHAR);
+ (* Converts the value of real to fixed-point string form, rounded
+ to the given place relative to the decimal point, and copies
+ the possibly truncated result to str.
+ *)
+
+PROCEDURE RealToStr (real: SHORTREAL; VAR str: ARRAY OF CHAR);
+ (* Converts the value of real as RealToFixed if the sign and
+ magnitude can be shown within the capacity of str, or
+ otherwise as RealToFloat, and copies the possibly truncated
+ result to str. The number of places or significant digits
+ depend on the capacity of str.
+ *)
+
+END ShortStr.
diff --git a/gcc/m2/gm2-libs-iso/ShortStr.mod b/gcc/m2/gm2-libs-iso/ShortStr.mod
new file mode 100644
index 0000000..946d8ae
--- /dev/null
+++ b/gcc/m2/gm2-libs-iso/ShortStr.mod
@@ -0,0 +1,150 @@
+(* ShortStr.mod implement the ISO ShortStr specification.
+
+Copyright (C) 2009-2023 Free Software Foundation, Inc.
+Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
+
+This file is part of GNU Modula-2.
+
+GNU Modula-2 is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GNU Modula-2 is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. *)
+
+IMPLEMENTATION MODULE ShortStr;
+
+(* REAL/string conversions *)
+
+IMPORT ShortConv ;
+
+FROM DynamicStrings IMPORT String, InitString, KillString, Length, CopyOut ;
+
+FROM ConvStringShort IMPORT RealToFixedString, RealToFloatString,
+ RealToEngString ;
+
+
+(* the string form of a signed fixed-point real number is
+ ["+" | "-"], decimal digit, {decimal digit}, [".",
+ {decimal digit}]
+*)
+
+(* the string form of a signed floating-point real number is
+ signed fixed-point real number, "E", ["+" | "-"],
+ decimal digit, {decimal digit}
+*)
+
+PROCEDURE StrToReal (str: ARRAY OF CHAR; VAR real: SHORTREAL;
+ VAR res: ConvResults) ;
+ (* Ignores any leading spaces in str. If the subsequent characters
+ in str are in the format of a signed real number, assigns a
+ corresponding value to real. Assigns a value indicating the
+ format of str to res.
+ *)
+BEGIN
+ res := ShortConv.FormatReal(str) ;
+ IF res=strAllRight
+ THEN
+ real := ShortConv.ValueReal(str)
+ END
+END StrToReal ;
+
+
+PROCEDURE RealToFloat (real: SHORTREAL; sigFigs: CARDINAL;
+ VAR str: ARRAY OF CHAR) ;
+ (* Converts the value of real to floating-point string form, with
+ sigFigs significant figures, and copies the possibly truncated
+ result to str.
+ *)
+VAR
+ s: String ;
+BEGIN
+ s := RealToFloatString(real, sigFigs) ;
+ CopyOut(str, s) ;
+ s := KillString(s)
+END RealToFloat ;
+
+
+PROCEDURE RealToEng (real: SHORTREAL; sigFigs: CARDINAL;
+ VAR str: ARRAY OF CHAR) ;
+ (* Converts the value of real to floating-point string form, with
+ sigFigs significant figures, and copies the possibly truncated
+ result to str. The number is scaled with one to three digits
+ in the whole number part and with an exponent that is a multiple
+ of three.
+ *)
+VAR
+ s: String ;
+BEGIN
+ s := RealToEngString(real, sigFigs) ;
+ CopyOut(str, s) ;
+ s := KillString(s)
+END RealToEng ;
+
+
+PROCEDURE RealToFixed (real: SHORTREAL; place: INTEGER;
+ VAR str: ARRAY OF CHAR) ;
+ (* Converts the value of real to fixed-point string form, rounded
+ to the given place relative to the decimal point, and copies
+ the possibly truncated result to str.
+ *)
+VAR
+ s: String ;
+BEGIN
+ s := RealToFixedString(real, place) ;
+ CopyOut(str, s) ;
+ s := KillString(s)
+END RealToFixed ;
+
+
+PROCEDURE RealToStr (real: SHORTREAL; VAR str: ARRAY OF CHAR) ;
+ (* Converts the value of real as RealToFixed if the sign and
+ magnitude can be shown within the capacity of str, or
+ otherwise as RealToFloat, and copies the possibly truncated
+ result to str. The number of places or significant digits
+ are implementation-defined.
+ *)
+VAR
+ s : String ;
+ sigFigs: CARDINAL ;
+BEGIN
+ sigFigs := HIGH(str) ;
+ WHILE sigFigs>1 DO
+ s := RealToFixedString(real, sigFigs) ;
+ IF Length(s)<=HIGH(str)
+ THEN
+ CopyOut(str, s) ;
+ s := KillString(s) ;
+ RETURN
+ END ;
+ s := KillString(s) ;
+ DEC(sigFigs)
+ END ;
+ sigFigs := HIGH(str) ;
+ WHILE sigFigs#0 DO
+ s := RealToFloatString(real, sigFigs) ;
+ IF Length(s)<=HIGH(str)
+ THEN
+ CopyOut(str, s) ;
+ s := KillString(s) ;
+ RETURN
+ END ;
+ s := KillString(s) ;
+ DEC(sigFigs)
+ END
+END RealToStr ;
+
+
+END ShortStr.