https://github.com/roguh/core
Implementation of SPJ's Tutorial Core compilers in modern Haskell (unfinished)
https://github.com/roguh/core
Last synced: about 1 year ago
JSON representation
Implementation of SPJ's Tutorial Core compilers in modern Haskell (unfinished)
- Host: GitHub
- URL: https://github.com/roguh/core
- Owner: roguh
- Created: 2015-01-22T16:37:48.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2021-09-08T05:41:19.000Z (almost 5 years ago)
- Last Synced: 2025-03-27T10:51:17.280Z (about 1 year ago)
- Language: Haskell
- Homepage:
- Size: 1.36 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CORE
SPJ's Tutorial Core compilers written using circa 2015 Haskell
programming practices. Big changes include Monadic error handling and parsing
using Parsec.
The template instantiation machine was partially implemented and the GMachine is
entirely implemented (up to Mk6).
Simply run Main.hs. You can change the compiler used in this simple REPL,
though it doesn't have multiline editing or a nice file-loading interface (yet).
```
runhaskell Main.hs
core >>> main = fac 20 ; fac n = if (n <= 0) 1 (n * (fac (n - 1)))
2432902008176640000
core >>> .compiler gmachinemk1
changing compiler to gmachinemk1
core >>> main = 4 * 10
undeclared global: *
core >>> .compiler gmachinemk4
changing compiler to gmachinemk4
core >>> main = 4 * 10
NNum 40
```
Can also run through GHCi
```haskell
ghci Main.hs
>>> runCore gmachineMk5
"NNum 2432902008176640000"
>>> runCore gmachineMk6 "main = fac 20 ; fac n = if (n <= 0) 1 (n * (fac (n - 1)))"
"2432902008176640000 "
```
Also, I mainly used NixOS for this (Cabal file broken, atm). Sandboxed installation is easy with
```
nix-shell shell.nix
```
Referencing [Implementing functional languages: a tutorial](http://research.microsoft.com/en-us/um/people/simonpj/Papers/pj-lester-book/i).