Compare commits
10 Commits
test-examp
...
v0.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
585130cfac | ||
|
|
bc3bd92c43 | ||
|
|
81a324111e | ||
|
|
1d5af748b3 | ||
|
|
ce0a135666 | ||
|
|
eaac7ad7a3 | ||
|
|
633882119b | ||
|
|
1f2d540c72 | ||
|
|
9c7c9c4730 | ||
|
|
f45c06cad5 |
11
README.md
11
README.md
@@ -12,14 +12,15 @@ $ cabal build # Build the rlpc compiler
|
||||
$ cabal install # Install rlpc to $PATH
|
||||
$ cabal haddock # Build the API docs w/ Haddock
|
||||
$ make -C doc html # Build the primary docs w/ Sphinx
|
||||
|
||||
# run the test suite
|
||||
$ cabal test --test-show-details=direct
|
||||
```
|
||||
|
||||
### Use
|
||||
```sh
|
||||
# Compile and evaluate t.hs
|
||||
$ rlpc t.hs
|
||||
# Compile and evaluate t.hs, with evaluation info dumped to stderr
|
||||
$ rlpc -ddump-eval t.hs
|
||||
# Compile and evaluate examples/factorial.hs, with evaluation info dumped to stderr
|
||||
$ rlpc -ddump-eval examples/factorial.hs
|
||||
# Compile and evaluate t.hs, with evaluation info dumped to t.log
|
||||
$ rlpc -ddump-eval -l t.log t.hs
|
||||
# Print the raw structure describing the compiler options and die
|
||||
@@ -80,7 +81,7 @@ Listed in order of importance.
|
||||
- [ ] Tail call optimisation
|
||||
- [x] Parsing rlp
|
||||
- [ ] Tests
|
||||
- [ ] Generic example programs
|
||||
- [x] Generic example programs
|
||||
- [ ] Parser
|
||||
|
||||
### December Release Plan
|
||||
|
||||
3
examples/constDivZero.hs
Normal file
3
examples/constDivZero.hs
Normal file
@@ -0,0 +1,3 @@
|
||||
k x y = x;
|
||||
main = k 3 ((/#) 1 0);
|
||||
|
||||
7
examples/factorial.hs
Normal file
7
examples/factorial.hs
Normal file
@@ -0,0 +1,7 @@
|
||||
fac n = case (==#) n 0 of
|
||||
{ 1 -> 1
|
||||
; 0 -> (*#) n (fac ((-#) n 1))
|
||||
};
|
||||
|
||||
main = fac 3;
|
||||
|
||||
9
examples/sumList.hs
Normal file
9
examples/sumList.hs
Normal file
@@ -0,0 +1,9 @@
|
||||
nil = Pack{0 0};
|
||||
cons x y = Pack{1 2} x y;
|
||||
list = cons 1 (cons 2 (cons 3 nil));
|
||||
sum l = case l of
|
||||
{ 0 -> 0
|
||||
; 1 x xs -> (+#) x (sum xs)
|
||||
};
|
||||
main = sum list;
|
||||
|
||||
@@ -8,6 +8,7 @@ module Core.Examples
|
||||
( fac3
|
||||
, sumList
|
||||
, constDivZero
|
||||
, idCase
|
||||
) where
|
||||
----------------------------------------------------------------------------------
|
||||
import Core.Syntax
|
||||
@@ -181,6 +182,15 @@ constDivZero = [coreProg|
|
||||
main = k 3 ((/#) 1 0);
|
||||
|]
|
||||
|
||||
idCase :: Program'
|
||||
idCase = [coreProg|
|
||||
id x = x;
|
||||
|
||||
main = id (case Pack{1 0} of
|
||||
{ 1 -> (+#) 2 3
|
||||
})
|
||||
|]
|
||||
|
||||
corePrelude :: Module Name
|
||||
corePrelude = Module (Just ("Prelude", [])) $
|
||||
-- non-primitive defs
|
||||
|
||||
@@ -46,8 +46,7 @@ type Floater = StateT [Name] (Writer [ScDef'])
|
||||
runFloater :: Floater a -> (a, [ScDef'])
|
||||
runFloater = flip evalStateT ns >>> runWriter
|
||||
where
|
||||
-- TODO: safer, uncapturable names
|
||||
ns = [ "nonstrict_case_" ++ showHex n "" | n <- [0..] ]
|
||||
ns = [ "$nonstrict_case_" ++ showHex n "" | n <- [0..] ]
|
||||
|
||||
-- TODO: formally define a "strict context" and reference that here
|
||||
-- the returned ScDefs are guaranteed to be free of non-strict cases.
|
||||
|
||||
@@ -48,7 +48,7 @@ instance Arbitrary ArithExpr where
|
||||
-- i don't feel like dealing with division at the moment
|
||||
[ IntA <$> int
|
||||
, NegateA <$> arbitrary
|
||||
-- , IdA <$> arbitrary
|
||||
, IdA <$> arbitrary
|
||||
, b (:+)
|
||||
, b (:-)
|
||||
, b (:*)
|
||||
|
||||
@@ -36,3 +36,6 @@ spec = do
|
||||
it "k 3 ((/#) 1 0)" $ do
|
||||
resultOf Ex.constDivZero `shouldBe` Just (NNum 3)
|
||||
|
||||
it "id (case ... of { ... })" $ do
|
||||
resultOf Ex.idCase `shouldBe` Just (NNum 5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user