10 Commits

Author SHA1 Message Date
crumbtoo
585130cfac update readme 2023-12-14 14:27:16 -07:00
crumbtoo
bc3bd92c43 update readme 2023-12-14 14:16:46 -07:00
msydneyslaga
81a324111e Merge pull request #7 from msydneyslaga/dev
idCase test
2023-12-14 14:06:48 -07:00
crumbtoo
1d5af748b3 idCase test 2023-12-14 14:04:51 -07:00
msydneyslaga
ce0a135666 Merge pull request #6 from msydneyslaga/dev
Dev
2023-12-14 13:43:21 -07:00
msydneyslaga
eaac7ad7a3 Merge branch 'main' into dev 2023-12-14 13:43:07 -07:00
crumbtoo
633882119b add examples 2023-12-14 13:29:08 -07:00
crumbtoo
1f2d540c72 test lazy arith 2023-12-13 11:45:03 -07:00
crumbtoo
9c7c9c4730 arith fixes 2023-12-13 11:38:34 -07:00
msydneyslaga
f45c06cad5 Merge pull request #5 from msydneyslaga/dev
towards stabilising main branch
2023-12-13 11:05:27 -07:00
8 changed files with 40 additions and 8 deletions

View File

@@ -12,14 +12,15 @@ $ cabal build # Build the rlpc compiler
$ cabal install # Install rlpc to $PATH $ cabal install # Install rlpc to $PATH
$ cabal haddock # Build the API docs w/ Haddock $ cabal haddock # Build the API docs w/ Haddock
$ make -C doc html # Build the primary docs w/ Sphinx $ make -C doc html # Build the primary docs w/ Sphinx
# run the test suite
$ cabal test --test-show-details=direct
``` ```
### Use ### Use
```sh ```sh
# Compile and evaluate t.hs # Compile and evaluate examples/factorial.hs, with evaluation info dumped to stderr
$ rlpc t.hs $ rlpc -ddump-eval examples/factorial.hs
# Compile and evaluate t.hs, with evaluation info dumped to stderr
$ rlpc -ddump-eval t.hs
# Compile and evaluate t.hs, with evaluation info dumped to t.log # Compile and evaluate t.hs, with evaluation info dumped to t.log
$ rlpc -ddump-eval -l t.log t.hs $ rlpc -ddump-eval -l t.log t.hs
# Print the raw structure describing the compiler options and die # Print the raw structure describing the compiler options and die
@@ -80,7 +81,7 @@ Listed in order of importance.
- [ ] Tail call optimisation - [ ] Tail call optimisation
- [x] Parsing rlp - [x] Parsing rlp
- [ ] Tests - [ ] Tests
- [ ] Generic example programs - [x] Generic example programs
- [ ] Parser - [ ] Parser
### December Release Plan ### December Release Plan

3
examples/constDivZero.hs Normal file
View File

@@ -0,0 +1,3 @@
k x y = x;
main = k 3 ((/#) 1 0);

7
examples/factorial.hs Normal file
View 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
View 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;

View File

@@ -8,6 +8,7 @@ module Core.Examples
( fac3 ( fac3
, sumList , sumList
, constDivZero , constDivZero
, idCase
) where ) where
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
import Core.Syntax import Core.Syntax
@@ -181,6 +182,15 @@ constDivZero = [coreProg|
main = k 3 ((/#) 1 0); 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 Name
corePrelude = Module (Just ("Prelude", [])) $ corePrelude = Module (Just ("Prelude", [])) $
-- non-primitive defs -- non-primitive defs

View File

@@ -46,8 +46,7 @@ type Floater = StateT [Name] (Writer [ScDef'])
runFloater :: Floater a -> (a, [ScDef']) runFloater :: Floater a -> (a, [ScDef'])
runFloater = flip evalStateT ns >>> runWriter runFloater = flip evalStateT ns >>> runWriter
where 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 -- TODO: formally define a "strict context" and reference that here
-- the returned ScDefs are guaranteed to be free of non-strict cases. -- the returned ScDefs are guaranteed to be free of non-strict cases.

View File

@@ -48,7 +48,7 @@ instance Arbitrary ArithExpr where
-- i don't feel like dealing with division at the moment -- i don't feel like dealing with division at the moment
[ IntA <$> int [ IntA <$> int
, NegateA <$> arbitrary , NegateA <$> arbitrary
-- , IdA <$> arbitrary , IdA <$> arbitrary
, b (:+) , b (:+)
, b (:-) , b (:-)
, b (:*) , b (:*)

View File

@@ -36,3 +36,6 @@ spec = do
it "k 3 ((/#) 1 0)" $ do it "k 3 ((/#) 1 0)" $ do
resultOf Ex.constDivZero `shouldBe` Just (NNum 3) resultOf Ex.constDivZero `shouldBe` Just (NNum 3)
it "id (case ... of { ... })" $ do
resultOf Ex.idCase `shouldBe` Just (NNum 5)