Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0286be3
Linux support for non-blocking IO
Rewbert Apr 23, 2026
8434f6f
remove conditional execution of test
Rewbert Apr 23, 2026
2f04f88
refactor to prepare for implementations for the other platforms
Rewbert Apr 23, 2026
0b1e26e
mac variant, generated
Rewbert Apr 23, 2026
463d224
make test better
Rewbert Apr 23, 2026
e1c0f4f
test
Rewbert Apr 23, 2026
2e69f43
update the test to use Client
Rewbert Apr 26, 2026
a7644d5
fix the test, after I broke it..
Rewbert Apr 26, 2026
01806d9
move the direct mthread/runq manipulation out of the io_poll machiner…
Rewbert Apr 26, 2026
e76571b
potential bugfix. Tests pass
Rewbert May 5, 2026
b9ee18d
address some of Lennarts comments
Rewbert May 15, 2026
8b344ad
replace with a simpler, but equally 'testive' test
Rewbert May 15, 2026
53d0ddf
remove macos support. Lennart will add it himself
Rewbert May 15, 2026
9c6ad1a
try to make the linter happy?
Rewbert May 15, 2026
35581bf
add a return value to waitFor*FD, to notice whether MHS_IO_POLL is de…
Rewbert May 15, 2026
58436cc
fix type issue
Rewbert May 20, 2026
902d183
Update documentation
augustss May 23, 2026
cd8362a
Show how long installtion took.
augustss May 23, 2026
d3f743c
More directory stuff
augustss May 5, 2026
9604052
Tweak
augustss May 24, 2026
7e91f0c
Merge pull request #471 from Rewbert/epoll-foreign-io
augustss May 24, 2026
7a1f1d0
Some minor cleanup.
augustss May 24, 2026
d6917af
Make polling work with emscripten
augustss May 24, 2026
6b390d8
Change the wait for IO on a descriptor to be more like the timeq.
augustss May 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ runtestgsan: bin/mhsevalsane bin/gmhs

# Run test examples going via JavaScript
runtestemscripten: bin/mhseval bin/mhs bin/cpphs
cd tests; $(MAKE) MHS=../bin/mhs cache; MHSDIR=.. $(MAKE) MHSTARGET="-temscripten" MHS="../bin/mhs -CR -oout.js" EVAL="$(NODE) $(NODEFLAGS) out.js" info test errtest
cd tests; $(MAKE) MHS=../bin/mhs cache; MHSDIR=.. $(MAKE) MHSTARGET="-temscripten" MHS="../bin/mhs -CR -oout.js" EVAL="$(NODE) $(NODEFLAGS) out.js" info test errtest testpipenonblockioem

runtestinstemscripten:
cd tests; $(MAKE) MHSTARGET="-temscripten" MHS="mhs.js -oout.js" EVAL="$(NODE) $(NODEFLAGS) out.js" test
Expand Down
53 changes: 4 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,63 +252,18 @@ separated list of directories.
## Setting the _packageDbPath_
The default _packageDbPath_ is take from the `mhs.conf` file
in the section `[mhs]` and key `packageDbPath`.

In case this does not exists the path defaults to `~/.mcabal/mhs-VERSION`,
where `~` will be replaced by the home directory and `VERSION` is the
compiler version (as displayed by `mhs --numeric-version`).
The path can contain environment variables that are expanded.
In addition $MHSPKG expand to the package directory relative to the executing binary.
Furthermore $VERSION expands to the mhs version number.

The path can be cleared by using the `-a` command line flag.
To append to the path use `-aPATH`, where `PATH` is a colon (':')
separated list if directories.

## Installing packages
The default _packageDb_ for installing packages is given by the
key `packageDbDefaultInstall`.
If absent, it defaults to `~/.mcabal/mhs-VERSION`.

The _packageDb_ directory can also be given directly with the `-Q`
The _packageDb_ directory can be given directly with the `-Q`
flag used to install.

The `mcabal` command can install to a particular package db by using
`--install=PATH`.

## Examples
### Status Quo
All packages go to the same place.

Compile a module with `mhs Foo`.


mhs.config:
```
[mhs]
packageDbPath=~/.mcabal/mhs-0.15.5.0
packageDbDefaultInstall=~/.mcabal/mhs-0.15.5.0
...
```

### GhcUp
Separate system and user package dbs.

Compile a module with `mhs Foo`.

mhs.config:
```
[mhs]
packageDbPath=~/.mcabal/system:~/.mcabal-user
packageDbDefaultInstall=~/.mcabal-user
...
```

### Nix
A system package db and then a separate db for each package.

Compile a module with `mhs -a%transformers:%mtl Foo`.

```
[mhs]
packageDbPath=~/.mcabal/system
packageDbDefaultInstall=NO_INSTALL_GIVEN
packageDbPrefix=~/.mcabal-user-dbs
...
```
7 changes: 7 additions & 0 deletions Tools/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import System.Directory
import System.Environment
import System.FilePath
import System.Process
import System.IO.TimeMilli
import MicroHs.Config

type CConf = [(Key, Value)]


main :: IO ()
main = do
start <- getTimeMilli
args <- getArgs
let flags = decodeArgs defaultFlags args
confText <- macroExpand flags <$> readFile (confFile flags)
Expand All @@ -33,6 +35,11 @@ main = do

install flags'

end <- getTimeMilli
let delta = (end - start) `quot` 100
(sec, tenths) = delta `quotRem` 10
putStrLn $ "Install time: " ++ show sec ++ "." ++ show tenths ++ "s"

install :: Flags -> IO ()
install flags = do
instBin flags
Expand Down
2,568 changes: 1,285 additions & 1,283 deletions generated/install.c

Large diffs are not rendered by default.

38,282 changes: 33,050 additions & 5,232 deletions generated/mhs.c

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions lib/Control/Concurrent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ threadStatus thr = do
st <- primThreadStatus thr
return $
case st of
0 -> ThreadRunning -- ts_runnable
1 -> ThreadBlocked BlockedOnMVar -- ts_wait_mvar
2 -> ThreadBlocked BlockedOnOther -- ts_wait_time
3 -> ThreadFinished -- ts_finished
4 -> ThreadDied -- ts_died
0 -> ThreadRunning -- ts_runnable
1 -> ThreadBlocked BlockedOnMVar -- ts_wait_mvar
2 -> ThreadBlocked BlockedOnOther -- ts_wait_time
3 -> ThreadFinished -- ts_finished
4 -> ThreadDied -- ts_died
5 -> ThreadBlocked BlockedOnForeignCall -- ts_wait_io

-------------------------------------------------------
-- Just for GHC compatibility.
Expand Down
3 changes: 3 additions & 0 deletions lib/Foreign/C/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ instance Eq Errno where
| isValidErrno errno1 = no1 == no2
| otherwise = False

instance Show Errno where
showsPrec p (Errno e) = showsPrec p e

eOK :: Errno
eOK = Errno 0

Expand Down
6 changes: 6 additions & 0 deletions lib/Primitives.hs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ primTryPutMVar = _primitive "IO.tryputmvar"
primTryReadMVar :: MVar a -> IO b {-(Maybe a)-}
primTryReadMVar = _primitive "IO.tryreadmvar"

primWaitWriteFD :: Int -> IO Int
primWaitWriteFD = _primitive "IO.waitwrfd"

primWaitReadFD :: Int -> IO Int
primWaitReadFD = _primitive "IO.waitrdfd"

primThreadDelay :: Int -> IO ()
primThreadDelay = _primitive "IO.threaddelay"

Expand Down
94 changes: 70 additions & 24 deletions lib/System/Directory.hs
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
module System.Directory(
removeFile,
doesFileExist,
doesDirectoryExist,
getDirectoryContents,
listDirectory,
setCurrentDirectory,
getCurrentDirectory,
withCurrentDirectory,
createDirectory,
createDirectoryIfMissing,
copyFile,
getHomeDirectory,
getTemporaryDirectory,
--
Permissions(..),
emptyPermissions,
setOwnerReadable,
setOwnerWritable,
setOwnerExecutable,
setOwnerSearchable,
getPermissions,
setPermissions,
copyPermissions,
createDirectory
, createDirectoryIfMissing
-- , removeDirectory
-- , removeDirectoryRecursive
-- , removePathForcibly
-- , renameDirectory
, listDirectory
, getDirectoryContents
, getCurrentDirectory
, setCurrentDirectory
, withCurrentDirectory

, getHomeDirectory
-- , XdgDirectory(..)
-- , getXdgDirectory
-- , XdgDirectoryList(..)
-- , getXdgDirectoryList
-- , getAppUserDataDirectory
-- , getUserDocumentsDirectory
, getTemporaryDirectory

-- , getExecSearchPath

, removeFile
-- , renameFile
-- , renamePath
, copyFile
-- , copyFileWithMetadata
-- , getFileSize

-- , canonicalizePath
-- , makeAbsolute
-- , makeRelativeToCurrentDirectory

-- , doesPathExist
, doesFileExist
, doesDirectoryExist

-- , findExecutable
-- , findExecutables
-- , findExecutablesInDirectories
-- , findFile
-- , findFiles
-- , findFileWith
-- , findFilesWith
-- , exeExtension

-- , createFileLink
-- , createDirectoryLink
-- , removeDirectoryLink
-- , pathIsSymbolicLink
-- , getSymbolicLinkTarget

, Permissions(..)
, emptyPermissions
, setOwnerReadable
, setOwnerWritable
, setOwnerExecutable
, setOwnerSearchable

, getPermissions
, setPermissions
, copyPermissions

-- , getAccessTime
-- , getModificationTime
-- , setAccessTime
-- , setModificationTime

-- , isSymbolicLink
) where
import qualified Prelude(); import MiniPrelude
import Control.Exception(bracket)
Expand Down Expand Up @@ -166,7 +213,6 @@ data Permissions
, searchable :: Bool
} deriving (Eq, Ord, Show)

emptyPermissions :: Permissions
emptyPermissions :: Permissions
emptyPermissions = Permissions {
readable = False,
Expand Down
9 changes: 9 additions & 0 deletions lib/System/IO/FD.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module System.IO.FD (waitForReadFD, waitForWriteFD) where

import Primitives

waitForReadFD :: Int -> IO Int
waitForReadFD = primWaitReadFD

waitForWriteFD :: Int -> IO Int
waitForWriteFD = primWaitWriteFD
1 change: 1 addition & 0 deletions lib/base.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ library base
System.Environment
System.Exit
System.IO
System.IO.FD
System.IO.Error
System.IO.MD5
System.IO.PrintOrRun
Expand Down
2 changes: 2 additions & 0 deletions src/MicroHs/Translate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ primTable = [
("bs2fp", _primitive "bs2fp"),
("IO.fork", _primitive "IO.fork"),
("IO.thid", _primitive "IO.thid"),
("IO.waitrdfd", _primitive "IO.waitrdfd"),
("IO.waitwrfd", _primitive "IO.waitwrfd"),
("thnum", _primitive "thnum"),
("IO.throwto", _primitive "IO.throwto"),
("IO.yield", _primitive "IO.yield"),
Expand Down
Loading
Loading