-
Notifications
You must be signed in to change notification settings - Fork 0
Rust codegen #156
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
Merged
Merged
Rust codegen #156
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7d051f3
Implement Rust type definition codegen
szg251 9ae86d2
Partial implementation of Rust syntax
szg251 8bb9976
Implement case_json_constructor for Rust
szg251 8cf89fc
Implement LamVal json builtins
szg251 b8c23ce
Update lbr-prelude-derive with proper LamVal builtins
szg251 fcd419b
Implement curried LamVal builtins
szg251 e534cac
Rename Rust LamVal builtins module json::curried to json::lamval
szg251 d468884
More Rust codegen implementation
szg251 9a1c65f
lbr-prelude-rust: All LamVal builtins should accept a refence
szg251 b728547
lbr-prelude-derive: adapt to changes made in lbr-prelude for Rust
szg251 51fbbf3
Implementation of Rust codegen
szg251 5b64bee
Merge branch 'main' of github.com:mlabs-haskell/lambda-buffers into s…
szg251 40de8b7
Fix LamVal builtins
szg251 583e61f
Fix Record instances
szg251 a337a37
Rust codegen: Phantom Data constructors
szg251 7e49af8
Rust codegen: Phantom Data deconstructors
szg251 a265191
Rust codegen: Sum type with PhantomData build and pattern match
szg251 8ed9230
Rust codegen: add type information to top level LamEs in instance def…
szg251 ed80e51
Rust codegen: fix trait bound printing
szg251 08c1906
Rust codegen: Fix PhantomData record constructor
szg251 1edc537
Remove failed LamVal printer unit test attempts
szg251 cbfffd6
Remove test files
szg251 f28a918
Remove incomplete nix derivation for rust
szg251 975d04d
Rust codegen: suppress Rust warnings
szg251 3f0e50a
Rust codegen: recursive types support for type definitions
szg251 03c997d
Rust codegen: recursive type support for data constructors in LamVal
szg251 a868760
Merge branch 'main' of github.com:mlabs-haskell/lambda-buffers into s…
szg251 c3b6cdc
Add RedeemerHash
szg251 59e3157
Rust codegen: refactor Rust ModuleName and Qualified types
szg251 6f60a48
Rust codegen: collect all Rust foreign references under Refs module
szg251 3dbd6ab
Rust codegen: update code comments
szg251 84523e4
Rust codegen: Add explicit exports to refs
szg251 29aa622
Rust codegen: update config parser a json data
szg251 7df6711
Merge branch 'main' into szg251/rust-codegen
szg251 625c1de
Fix auto-merge problems
szg251 9b4c30e
Fix document typos and mistakes
szg251 aaf556f
Rust codegen: remove PhantomData type from eq builtins
szg251 cf7b7cd
Rust codegen: document reference printing
szg251 c12481e
Rust codegen: fix wrong Plutus version in rust config
szg251 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
lambda-buffers-codegen/app/LambdaBuffers/Codegen/Cli/GenRust.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module LambdaBuffers.Codegen.Cli.GenRust (GenOpts (..), gen) where | ||
|
||
import Control.Lens (makeLenses, (^.)) | ||
import Control.Monad (unless) | ||
import Data.Aeson (decodeFileStrict') | ||
import LambdaBuffers.Codegen.Cli.Gen (logError) | ||
import LambdaBuffers.Codegen.Cli.Gen qualified as Gen | ||
import LambdaBuffers.Codegen.Rust (runPrint) | ||
import LambdaBuffers.Codegen.Rust.Config qualified as R | ||
import Paths_lambda_buffers_codegen qualified as Paths | ||
import System.Directory (doesFileExist) | ||
import System.Directory.Internal.Prelude (exitFailure) | ||
|
||
data GenOpts = MkGenOpts | ||
{ _config :: [FilePath] | ||
, _common :: Gen.GenOpts | ||
} | ||
|
||
makeLenses 'MkGenOpts | ||
|
||
gen :: GenOpts -> IO () | ||
gen opts = do | ||
cfg <- case opts ^. config of | ||
[] -> do | ||
fp <- Paths.getDataFileName "data/rust-prelude-base.json" | ||
readRustConfig fp | ||
fps -> do | ||
cfgs <- traverse readRustConfig fps | ||
return (mconcat cfgs) | ||
|
||
Gen.gen | ||
(opts ^. common) | ||
(\ci -> fmap (\(fp, code, deps) -> Gen.Generated fp code deps) . runPrint cfg ci <$> (ci ^. #modules)) | ||
|
||
readRustConfig :: FilePath -> IO R.Config | ||
readRustConfig f = do | ||
fExists <- doesFileExist f | ||
unless | ||
fExists | ||
( do | ||
logError "" $ "Provided Rust Codegen configuration file doesn't exists: " <> f | ||
exitFailure | ||
) | ||
mayCfg <- decodeFileStrict' f | ||
case mayCfg of | ||
Nothing -> do | ||
logError "" $ "Invalid Rust configuration file " <> f | ||
exitFailure | ||
Just cfg -> return cfg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"opaquesConfig": { | ||
"Plutus.V1.PlutusData": [ | ||
"plutus-ledger-api", | ||
"plutus_data", | ||
"PlutusData" | ||
], | ||
"Plutus.V1.Address": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"address", | ||
"Address" | ||
], | ||
"Plutus.V1.Credential": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"address", | ||
"Credential" | ||
], | ||
"Plutus.V1.StakingCredential": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"address", | ||
"StakingCredential" | ||
], | ||
"Plutus.V1.PubKeyHash": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"crypto", | ||
"Ed25519PubKeyHash" | ||
], | ||
"Plutus.V1.Bytes": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"crypto", | ||
"LedgerBytes" | ||
], | ||
"Plutus.V1.Interval": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"interval", | ||
"Interval" | ||
], | ||
"Plutus.V1.Extended": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"interval", | ||
"Extended" | ||
], | ||
"Plutus.V1.LowerBound": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"interval", | ||
"LowerBound" | ||
], | ||
"Plutus.V1.UpperBound": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"interval", | ||
"UpperBound" | ||
], | ||
"Plutus.V1.POSIXTime": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"transaction", | ||
"POSIXTime" | ||
], | ||
"Plutus.V1.POSIXTimeRange": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"transaction", | ||
"POSIXTimeRange" | ||
], | ||
"Plutus.V1.Value": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"value", | ||
"Value" | ||
], | ||
"Plutus.V1.CurrencySymbol": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"value", | ||
"CurrencySymbol" | ||
], | ||
"Plutus.V1.AssetClass": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"value", | ||
"AssetClass" | ||
], | ||
"Plutus.V1.TokenName": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"value", | ||
"TokenName" | ||
], | ||
"Plutus.V1.Redeemer": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"redeemer", | ||
"Redeemer" | ||
], | ||
"Plutus.V1.Datum": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"datum", | ||
"Datum" | ||
], | ||
"Plutus.V1.DatumHash": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"datum", | ||
"DatumHash" | ||
], | ||
"Plutus.V1.RedeemerHash": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"redeemer", | ||
"RedeemerHash" | ||
], | ||
"Plutus.V1.ScriptHash": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"script", | ||
"ScriptHash" | ||
], | ||
"Plutus.V1.TxInInfo": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"transaction", | ||
"TxInInfo" | ||
], | ||
"Plutus.V1.TxId": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"transaction", | ||
"TransactionHash" | ||
], | ||
"Plutus.V1.TxOut": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"transaction", | ||
"TransactionOutput" | ||
], | ||
"Plutus.V1.TxOutRef": [ | ||
"plutus-ledger-api", | ||
"v1", | ||
"transaction", | ||
"TransactionInput" | ||
], | ||
"Plutus.V1.Map": [ | ||
"std", | ||
"collections", | ||
"BTreeMap" | ||
], | ||
"Plutus.V2.TxInInfo": [ | ||
"plutus-ledger-api", | ||
"v2", | ||
"transaction", | ||
"TxInInfo" | ||
], | ||
"Plutus.V2.OutputDatum": [ | ||
"plutus-ledger-api", | ||
"v2", | ||
"datum", | ||
"OutputDatum" | ||
], | ||
"Plutus.V2.TxOut": [ | ||
"plutus-ledger-api", | ||
"v2", | ||
"transaction", | ||
"TransactionOutput" | ||
] | ||
}, | ||
"classesConfig": { | ||
"Plutus.V1.PlutusData": [ | ||
[ | ||
"plutus-ledger-api", | ||
"plutus_data", | ||
"IsPlutusData" | ||
] | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"opaquesConfig": { | ||
"Prelude.Map": [ | ||
"std", | ||
"collections", | ||
"BTreeMap" | ||
], | ||
"Prelude.Set": [ | ||
"std", | ||
"collections", | ||
"BTreeSet" | ||
], | ||
"Prelude.List": [ | ||
"std", | ||
"vec", | ||
"Vec" | ||
], | ||
"Prelude.Either": [ | ||
"std", | ||
"result", | ||
"Result" | ||
], | ||
"Prelude.Maybe": [ | ||
"std", | ||
"option", | ||
"Option" | ||
], | ||
"Prelude.Bytes": [ | ||
"std", | ||
"vec", | ||
"Vec<u8>" | ||
], | ||
"Prelude.Text": [ | ||
"std", | ||
"string", | ||
"String" | ||
], | ||
"Prelude.Char": [ | ||
"char" | ||
], | ||
"Prelude.Integer": [ | ||
"num_bigint", | ||
"BigInt" | ||
], | ||
"Prelude.Bool": [ | ||
"std", | ||
"primitive", | ||
"bool" | ||
] | ||
}, | ||
"classesConfig": { | ||
"Prelude.Eq": [ | ||
[ | ||
"std", | ||
"cmp", | ||
"PartialEq" | ||
], | ||
[ | ||
"std", | ||
"cmp", | ||
"Eq" | ||
] | ||
], | ||
"Prelude.Json": [ | ||
[ | ||
"lbr-prelude", | ||
"json", | ||
"Json" | ||
] | ||
] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.