vt100/hs/WebMain.hs

boot main

1module Main (main) where23-- The browser build is a wasm reactor: the page calls the C entry points in4-- vt100/src/web_main.c, which reach the simulator through csrc/Therac.h.5--6-- This module passes a JavaScript value through the JavaScript FFI, which is what makes the7-- linker include GHC's JSFFI runtime support. That support starts the Haskell runtime from8-- _initialize and makes threadDelay wait with setTimeout instead of blocking the page (GHC's9-- Note [threadDelay on wasm]), so the simulator's Treat, housekeeper and Ptime tasks run on the10-- browser's event loop, unchanged.1112import GHC.Wasm.Prim (JSVal, freeJSVal)1314foreign import javascript unsafe "console.info('Therac-25 simulator running'); return globalThis;"15  js_hello :: IO JSVal1617foreign export javascript "therac_boot sync" boot :: IO ()1819boot :: IO ()20boot = js_hello >>= freeJSVal2122main :: IO ()23main = pure ()