diff --git a/playground/samples/Hello.newt b/playground/samples/Hello.newt new file mode 100644 index 0000000..5899e4f --- /dev/null +++ b/playground/samples/Hello.newt @@ -0,0 +1,43 @@ +module Main + +-- Monad + +class Monad (m : U → U) where + bind : {a b} → m a → (a → m b) → m b + pure : {a} → a → m a + +infixl 1 _>>=_ _>>_ +_>>=_ : {m} {{Monad m}} {a b} -> (m a) -> (a -> m b) -> m b +ma >>= amb = bind ma amb + +_>>_ : {m} {{Monad m}} {a b} -> m a -> m b -> m b +ma >> mb = mb + +-- I don't want to use an empty type because it would be a proof of void +ptype World + +data IORes : U -> U where + MkIORes : {a : U} -> a -> World -> IORes a + +IO : U -> U +IO a = World -> IORes a + + +data Unit : U where + MkUnit : Unit + + +instance Monad IO where + bind ma mab = \ w => case ma w of + MkIORes a w => mab a w + pure a = \ w => MkIORes a w + +ptype String +pfunc putStrLn : String -> IO Unit := "(s) => (w) => { + console.log(s) + return MkIORes(Unit,MkUnit,w) +}" + +main : IO Unit +main = do + putStrLn "hello, world" diff --git a/playground/samples/frame.html b/playground/samples/frame.html new file mode 100644 index 0000000..9556a3c --- /dev/null +++ b/playground/samples/frame.html @@ -0,0 +1,29 @@ + +
+ + + + + + \ No newline at end of file diff --git a/playground/src/main.ts b/playground/src/main.ts index 7b4b703..b64961a 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -10,11 +10,31 @@ monaco.languages.setMonarchTokensProvider("newt", newtTokens); monaco.languages.setLanguageConfiguration("newt", newtConfig); const newtWorker = new Worker("worker.js"); //new URL("worker.js", import.meta.url)) +const iframe = document.createElement("iframe"); +iframe.src = "frame.html"; +iframe.style.display = "none"; +document.body.appendChild(iframe); function run(src: string) { newtWorker.postMessage({ src }); } +function runOutput() { + const src = state.javascript.value + console.log("RUN", iframe.contentWindow); + try { + iframe.contentWindow?.postMessage({ cmd: "exec", src }, "*"); + } catch (e) { + console.error(e); + } +} + +window.onmessage = (ev) => { + console.log("window got", ev.data); + if (ev.data.messages) + state.messages.value = ev.data.messages; +}; + newtWorker.onmessage = (ev) => { state.output.value = ev.data.output; state.javascript.value = ev.data.javascript; @@ -30,6 +50,7 @@ self.MonacoEnvironment = { const state = { output: signal(""), javascript: signal(""), + messages: signal