-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters