ref: 9bb5a048bba763551a2725f4be2e721e86452447
parent: 12dd072194bb0476419122d29913fceb767840a5
author: Lennart Augustsson <lennart@augustsson.net>
date: Sat Nov 23 07:35:42 EST 2024
Format related changes
--- a/Makefile
+++ b/Makefile
@@ -167,7 +167,7 @@
#
clean:
- rm -rf src/*/*.hi src/*/*.o *.comb *.tmp *~ bin/* a.out $(GHCOUTDIR) Tools/*.o Tools/*.hi dist-newstyle generated/*-stage* .mhscache targets.conf .mhscache dist-mcabal cpphssrc Interactive.hs .mhsi
+ rm -rf src/*/*.hi src/*/*.o *.comb *.js *.tmp *~ bin/* a.out $(GHCOUTDIR) Tools/*.o Tools/*.hi dist-newstyle generated/*-stage* .mhscache targets.conf .mhscache dist-mcabal cpphssrc Interactive.hs .mhsi
cd tests; make clean
-cabal clean
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@
To compile on Windows make sure `cl` is in the path, and then use `nmake` with `Makefile.windows`.
-The compiler can also be used with emscripten to produce JavaScript/WASM, see `Makefile.emscripten`.
+The compiler can also be used with emscripten to produce JavaScript/WASM.
## Language
The language is an extended subset of Haskell-2010.
@@ -186,6 +186,17 @@
the cache.
Do **NOT** use `-C` when you are changing the compiler itself; if the cached data types change the compiler will probably just crash.
+### Targets
+The configuration file `targets.conf` (in the installation directory) defines how to compile for
+different targets. As distributed it contains thetargets `default` and `emscripten`.
+The first is the normal target to run on the host.
+The `emscripten` target uses `emcc` to generate JavaScript.
+If you have `emcc` and node installed you can do
+ ```
+ mhs -temscripten Example -oout.js; node out.js
+ ```
+to compile and run the JavaScript. There generated JavaScript file has some regular JavaScript,
+and also the WASM code embedded as a blob. Running via JavaScript/WASM is almost as fast as running natively.
### Environment variables
* `MHSDIR` the directory where `lib/` and `src/` are expected to be. Defaults to `./`.
--- a/lib/Data/FloatW.hs
+++ b/lib/Data/FloatW.hs
@@ -63,7 +63,7 @@
-- For now, cheat and call C
instance Show FloatW where
- show = primFloatWShow
+ show = primFloatWShow -- should be Numeric.FormatFloat.showFloat, but that drags in a lot of stuff
{- in Text.Read.Internal
instance Read FloatW where
--- a/lib/Numeric/FormatFloat.hs
+++ b/lib/Numeric/FormatFloat.hs
@@ -1,4 +1,6 @@
module Numeric.FormatFloat(
+ showFloat,
+
formatRealFloat, formatRealFloatAlt,
showEFloat,
@@ -9,11 +11,13 @@
showHFloat,
) where
+import Prelude()
+import MiniPrelude
import Data.Char
import Numeric.Show
---showFloat :: (RealFloat a) => a -> ShowS
---showFloat x = showString (formatRealFloat FFGeneric Nothing x)
+showFloat :: (RealFloat a) => a -> ShowS
+showFloat x = showString (formatRealFloat FFGeneric Nothing x)
-- These are the format types. This type is not exported.
data FFFormat = FFExponent | FFFixed | FFGeneric
--- a/src/runtime/config-unix-64.h
+++ b/src/runtime/config-unix-64.h
@@ -45,6 +45,7 @@
/*
* Number of bits in a word. Only 32 and 64 are supported.
+ * WORD_SIZE set in mhsffi.h
*/
//#define WORD_SIZE 64
--- a/src/runtime/eval.c
+++ b/src/runtime/eval.c
@@ -1898,6 +1898,11 @@
NODEPTR mkStringC(char *str);
#if WANT_STDIO
+#if WORD_SIZE == 64
+#define CONVDBL "%.16g"
+#elif WORD_SIZE == 32
+#define CONVDBL "%.8g"
+#endif
void
convdbl(char *str, flt_t x)
{
@@ -1904,7 +1909,7 @@
/* Using 16 decimals will lose some precision.
* 17 would keep the precision, but it frequently looks very ugly.
*/
- (void)snprintf(str, 25, "%.16g", x);
+ (void)snprintf(str, 25, CONVDBL, x);
if (strcmp(str, "nan") != 0 && strcmp(str, "-nan") != 0 &&
strcmp(str, "inf") != 0 && strcmp(str, "-inf") != 0 &&
!strchr(str, '.') && !strchr(str, 'e') && !strchr(str, 'E')) {