Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/slava0135/stg-example
Example Haskell program translated to STG and compiled to C
https://github.com/slava0135/stg-example
compiler functional-programming haskell lazy-evaluation stg
Last synced: 27 days ago
JSON representation
Example Haskell program translated to STG and compiled to C
- Host: GitHub
- URL: https://github.com/slava0135/stg-example
- Owner: Slava0135
- License: mit
- Created: 2025-01-16T17:13:18.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-01-16T17:14:06.000Z (about 1 month ago)
- Last Synced: 2025-01-16T18:34:29.358Z (about 1 month ago)
- Topics: compiler, functional-programming, haskell, lazy-evaluation, stg
- Language: C
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# STG Example
STG (Spineless Tagless G-machine) is implementation of lazy functional language as described in:
> Simon Peyton Jones. Implementing Lazy Functional Languages on Stock Hardware: The Spineless Tagless G-machine. Journal of Functional Programming 1992
[haskell.hs](./haskell.hs) is example program written in Haskell (except there is no monad IO, i am sure you can figure it out).
[stg.hs](./stg.hs) is the program translated to STG as explained in book (`.hs` extension is for better editing).
[stgi.hs](./stgi.hs) is the program, but in format, supported by . The STG machine explained there too in details, so check it out!
[stg.c](./stg.c) is the program, translated (compiled) from STG to C as explained in book.
To run:
```sh
gcc stg.c && ./a.out
```You should get the following results in the end:
```text
...
Result = 91
Steps = 281
Stack A size = 0
Stack B size = 0
Heap size = 1008
Objects allocated = 47
```Tested on Linux (gcc version 14.2.1)