Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SPY committed Jun 1, 2018
1 parent 04e2a79 commit 37fd534
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion src/IRTS/CodegenWasm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37fd534

Please sign in to comment.