From 37fd534f89923223cbfbf4a4dd935bf9335f29f0 Mon Sep 17 00:00:00 2001 From: Ilya Rezvov Date: Thu, 31 May 2018 22:15:33 -0700 Subject: [PATCH] add readme --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++ src/IRTS/CodegenWasm.hs | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a77aa79 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# Idris WebAssembly CodeGen + +*It is still on early stages of development.* + +## Implemented + * [x] Control flow instructions + * [x] Garbadge Collection + * [x] String representation and implementation of primitive operations in RTS(with UTF8 support) + * [x] Char and native int operations + +## Todo + * [ ] Double operations + * [ ] BigNum primitives(now emulated as WASM i64 number) + * [ ] Bit8/16/32/64 operations + * [ ] Effective substrings representation as StrOffset + * [ ] Convertions (str to double, int to str, int to big num, etc) + * [ ] Pass Idris language test suite + * [ ] FFI and Idris-level support for new back-end + +## Build +Current implementation fully depends on [haskell-wasm](https://github.com/SPY/haskell-wasm). +It is not released yet and has unstable user API, but things will change soon. +To build you need clone [haskell-wasm](https://github.com/SPY/haskell-wasm) and [idris-codegen-wasm](https://github.com/SPY/idris-codegen-wasm) + +``` +cd ./haskell-wasm && stack build +cd ./idris-codegen-wasm && cabal sandbox --init && cabal sandbox add-source ../haskel-wasm && cabal build +``` + +Sample code fully functioning now + +``` +module Main + +factorial : Int -> Int +factorial 0 = 1 +factorial n = n * factorial (n - 1) + +range : Int -> Int -> List Int +range from to = if from == to then [to] else from :: range (from + 1) to + +moreThan : Int -> Int -> Maybe Int +moreThan lowLimit n = if n >= lowLimit then Just n else Nothing + +main : IO () +main = do + let hello = "Hello" + let world = "Мир" + -- long string to trigger GC + let longString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + putStrLn $ show $ range 1 10 + putStrLn $ show $ split (== ' ') longString + putStrLn $ hello ++ strCons ' ' world + putStrLn $ show $ sum $ range 0 256 + putStrLn $ show $ fromMaybe 42 $ moreThan 88 $ factorial 5 +``` + +To build it run: +``` +idris fact.idr --codegen wasm -o fact.wasm +``` + +For running compiled code you can use runner from `rts/index.html`. It contains some bootstrap code and simple tools for runtime introspection(print const section, stack, heap, fallback GC implementation, etc). \ No newline at end of file diff --git a/src/IRTS/CodegenWasm.hs b/src/IRTS/CodegenWasm.hs index ce4ed34..e2acab7 100644 --- a/src/IRTS/CodegenWasm.hs +++ b/src/IRTS/CodegenWasm.hs @@ -35,7 +35,7 @@ import Language.Wasm.Builder codegenWasm :: CodeGenerator codegenWasm ci = do let bc = map toBC $ simpleDecls ci - let wasmModule = mkWasm bc (64 * 1024) (4 * 1024) + let wasmModule = mkWasm bc (64 * 1024) (256 * 1024) LBS.writeFile (outputFile ci) $ WasmBinary.dumpModuleLazy wasmModule mkWasm :: [(Name, [BC])] -> Int -> Int -> Module