Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold / Basic Dev Environment #7

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
12 changes: 12 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
repository cardano-haskell-packages
url: https://input-output-hk.github.io/cardano-haskell-packages
secure: True
root-keys:
3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f
443abb7fb497a134c343faf52f0b659bd7999bc06b7f63fa76dc99d631f9bea1
a86a1f6ce86c449c46666bda44268677abf29b5b2d2eb5ec7af903ec2f117a82
bcec67e8e99cabfa7764d75ad9b158d72bfacf70ca1d0ec8bc6b4406d1bf8413
c00aae8461a256275598500ea0e187588c35a5d5d7454fb57eac18d9edb86a56
d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee


packages:
purescript.cabal
43 changes: 43 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cradle:
cabal:
- path: "src"
component: "lib:purescript"

- path: "app/Main.hs"
component: "purescript:exe:purs"

- path: "app/Command/Bundle.hs"
component: "purescript:exe:purs"

- path: "app/Command/Compile.hs"
component: "purescript:exe:purs"

- path: "app/Command/Docs.hs"
component: "purescript:exe:purs"

- path: "app/Command/Docs/Html.hs"
component: "purescript:exe:purs"

- path: "app/Command/Docs/Markdown.hs"
component: "purescript:exe:purs"

- path: "app/Command/Graph.hs"
component: "purescript:exe:purs"

- path: "app/Command/Hierarchy.hs"
component: "purescript:exe:purs"

- path: "app/Command/Ide.hs"
component: "purescript:exe:purs"

- path: "app/Command/Publish.hs"
component: "purescript:exe:purs"

- path: "app/Command/REPL.hs"
component: "purescript:exe:purs"

- path: "app/Version.hs"
component: "purescript:exe:purs"

- path: "tests"
component: "purescript:test:tests"
13 changes: 8 additions & 5 deletions purescript.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.4
cabal-version: 3.0

name: purescript
-- Note: don't add prerelease identifiers here! Add them in app/Version.hs and npm-package/package.json instead.
Expand Down Expand Up @@ -34,7 +34,7 @@ extra-source-files:
tests/support/pscide/src/**/*.purs
tests/support/pscide/src/**/*.js
tests/support/pscide/src/**/*.fail
stack.yaml
-- stack.yaml
README.md
INSTALL.md
CONTRIBUTORS.md
Expand Down Expand Up @@ -157,7 +157,7 @@ common defaults
aeson-better-errors >=0.9.1.1 && <0.10,
ansi-terminal >=0.11.3 && <0.12,
array >=0.5.4.0 && <0.6,
base >=4.16.2.0 && <4.17,
base >=4.16.2.0 && <4.18,
blaze-html >=0.9.1.2 && <0.10,
bower-json >=1.1.0.0 && <1.2,
boxes >=0.1.5 && <0.2,
Expand Down Expand Up @@ -201,14 +201,16 @@ common defaults
stm >=2.5.0.2 && <2.6,
stringsearch >=0.3.6.6 && <0.4,
template-haskell >=2.18.0.0 && <2.19,
text >=1.2.5.0 && <1.3,
text >=1.2.5.0 && <2.3,
these >=1.1.1.1 && <1.2,
time >=1.11.1.1 && <1.12,
transformers >=0.5.6.2 && <0.6,
transformers-base >=0.4.6 && <0.5,
utf8-string >=1.0.2 && <1.1,
vector >=0.12.3.1 && <0.13,
witherable >=0.4.2 && <0.5
witherable >=0.4.2 && <0.5,
plutus-core,
plutus-core:plutus-ir

library
import: defaults
Expand All @@ -230,6 +232,7 @@ library
Language.PureScript.AST.Utils
Language.PureScript.Bundle
Language.PureScript.CodeGen
Language.PureScript.CodeGen.UPLC
Language.PureScript.CodeGen.JS
Language.PureScript.CodeGen.JS.Common
Language.PureScript.CodeGen.JS.Printer
Expand Down
21 changes: 21 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
with (import <nixpkgs> {});
let haskell928 = haskell.packages.ghc928;
ghc928 = haskell.compiler.ghc928;
in mkShell {
nativeBuildInputs = [
pkg-config
haskell928.haskell-language-server
ghc928
cabal-install
];

buildInputs = [
zlib
libsodium
secp256k1
];

shellHook = ''
export LC_ALL=C.utf8
'';
}
31 changes: 31 additions & 0 deletions src/Language/PureScript/CodeGen/UPLC.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Language.PureScript.CodeGen.UPLC (moduleToUPLC, printUPLC) where

import Prelude ((.), ($))
import Protolude (print)
import Protolude.Error (error)

import Control.Monad.Except (MonadError)
import Control.Monad.Reader (MonadReader)
import Control.Monad.Supply.Class (MonadSupply)
import Control.Monad.IO.Class (MonadIO (liftIO))

import Language.PureScript.CoreFn (Ann, Module(..))
import Language.PureScript.Errors (MultipleErrors(..))
import Language.PureScript.Options (Options(..))


import UntypedPlutusCore
( DeBruijn, DefaultFun, DefaultUni, Program )
import PlutusCore.Pretty ( prettyPlcReadableDef )

-- Stolen from Ply, not 100% sure if this is what we want, i.e. maybe there should be an annotation?
type UPLCProgram = Program DeBruijn DefaultUni DefaultFun ()

moduleToUPLC :: forall m
. (MonadReader Options m, MonadSupply m, MonadError MultipleErrors m)
=> Module Ann -> m UPLCProgram
moduleToUPLC = error "Error: UPLC Backend not yet implemented!"

printUPLC :: forall m. MonadIO m => UPLCProgram -> m ()
printUPLC program = liftIO . print $ prettyPlcReadableDef program
4 changes: 4 additions & 0 deletions src/Language/PureScript/Make/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Language.PureScript.AST (SourcePos(..))
import Language.PureScript.Bundle qualified as Bundle
import Language.PureScript.CodeGen.JS qualified as J
import Language.PureScript.CodeGen.JS.Printer (prettyPrintJS, prettyPrintJSWithSourceMaps)
import Language.PureScript.CodeGen.UPLC qualified as PC
import Language.PureScript.CoreFn qualified as CF
import Language.PureScript.CoreFn.ToJSON qualified as CFJ
import Language.PureScript.Crash (internalError)
Expand Down Expand Up @@ -277,6 +278,9 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings
when (S.member Docs codegenTargets) $ do
lift $ writeJSONFile (outputFilename mn "docs.json") docs
when (S.member UPLC codegenTargets) $ do
uplc <- PC.moduleToUPLC m
lift $ PC.printUPLC uplc

ffiCodegen :: CF.Module CF.Ann -> Make ()
ffiCodegen m = do
Expand Down
3 changes: 2 additions & 1 deletion src/Language/PureScript/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ data Options = Options
defaultOptions :: Options
defaultOptions = Options False False (S.singleton JS)

data CodegenTarget = JS | JSSourceMap | CoreFn | Docs
data CodegenTarget = JS | JSSourceMap | CoreFn | Docs | UPLC
deriving (Eq, Ord, Show)

codegenTargets :: Map String CodegenTarget
codegenTargets = Map.fromList
[ ("js", JS)
, ("uplc", UPLC)
, ("sourcemaps", JSSourceMap)
, ("corefn", CoreFn)
, ("docs", Docs)
Expand Down
Loading