-
Notifications
You must be signed in to change notification settings - Fork 0
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
Core rewrite #21
Open
KubEF
wants to merge
54
commits into
main
Choose a base branch
from
core-rewrite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Core rewrite #21
Changes from 33 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
3a3bcf1
Add Node and Port types with related functions and data
KubEF 5ae3549
Add Reducer
KubEF 03490a2
pin fourmolu version in CI
KubEF f22318b
Delete Example.Project and add simpliest test for Core.Node
KubEF 142fb67
Delete usless comments and complement useful ones
KubEF 076670f
Add loader
KubEF e8c6d4e
Fix fourmolu to process $ correctly
KubEF 396c345
Add lenses and make some style changes
KubEF f20525b
Add tests for isActive and isPortToLoad functions
KubEF 47cdb69
Replace elemIndex to elem in markAllInnerEdges
KubEF c42efc4
Add tests for selectAddresToLoad function
KubEF 957dd8b
Replace repeat to def in handle function
KubEF 69b3439
Add tests for markAllInnerEdges function
KubEF 77a1365
[WIP]Add layout of memory manager
KubEF beb03b7
Redesign Address and add LocalNode
KubEF cb4f812
Add updateRam function
KubEF 9204022
Add IdOfPort
KubEF 28948dc
Add more types and getter port function
KubEF fcc12c1
Add memory manager
KubEF ee84822
Fully redesign reducer
KubEF dfd0921
Comment irrelevant (all) tests
KubEF 503c9a1
Change default json formatter
KubEF 6c44b6a
Add simple vector-based key-value storage
KubEF 8c684c2
Replace Address to AddressNum in Loader and unify LoadedNode with Loc…
KubEF f1d32ac
Rework memory manager update to minimize usage of RAM
KubEF 833d147
Rename Map functions
KubEF 9e0c858
Merge foldls
KubEF 98f2046
Delete updateRam
KubEF d4f2574
Refactor and some doc changes
KubEF 6db019e
Minor refactoring
KubEF 27f82a3
Simplified reducer
KubEF 52030f6
Add handmade agents
KubEF 1918777
Write concrete handmade reduction rule
KubEF fa9b564
Add some doctests in memory manager
KubEF 4afd346
Weakened Index to Unsigned constraint
KubEF fa5f3be
Update simple lambda reduction rule
KubEF ed75dd2
Rewrite indexToUnsigned via resize and bitCoerce
KubEF c8d17af
Add skipping svg files in pre-commit
KubEF 2564570
Fix doctests
KubEF 9fce015
Rename agent constructors
KubEF 3547c90
Rework Port and Node, add Connection type
KubEF 3893e18
Split MemoryManager functionality
KubEF 3262a04
Replace Edge, ActivePair and Delta type
KubEF 7ee225d
Replace types in MemoryManager modules
KubEF be705c9
Rewrite addresses allocated to Vec of Maybe
KubEF 164643d
Add giveActiveAddressNumber function
KubEF 43c3e6f
Fix the case when necessary amount of memory is zero
KubEF 01db43e
Add necessary loading functions
KubEF 9e46b32
Rewrite Reducer
KubEF b685955
[WIP] Add core function
KubEF 2ca782d
Fix pedantic build
KubEF 1240556
Add specific reduce rules for simple lambdas
KubEF 63aa4ef
Add example of initial net
KubEF 462d8d5
Add functions to export list for doctests
KubEF 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
This file contains 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 |
---|---|---|
|
@@ -49,5 +49,8 @@ | |
"editor.rulers": [ | ||
120 | ||
] | ||
}, | ||
"[jsonc]": { | ||
"editor.defaultFormatter": "vscode.json-language-features" | ||
} | ||
} |
This file contains 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 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 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,40 @@ | ||
{- | All modules from Concrete are | ||
1a. Compiled from some dsl in separate file | ||
1b. Compiled from embedded dsl in INet module | ||
2. Written by hands for tests | ||
-} | ||
module Core.Concrete.ReduceRulesLambda where | ||
|
||
import Clash.Prelude | ||
import Control.Lens | ||
import Core.MemoryManager | ||
import Core.Node | ||
import Core.Reducer | ||
import INet.Net | ||
|
||
(|><|) :: | ||
-- forall portsNumber nodesNumber edgesNumber. | ||
-- (KnownNat portsNumber, KnownNat nodesNumber, KnownNat edgesNumber, edgesNumber ~ portsNumber) => | ||
-- Node portsNumber -> | ||
-- Node portsNumber -> | ||
-- ReduceRuleResult nodesNumber edgesNumber portsNumber | ||
Node 2 -> | ||
Node 2 -> | ||
ReduceRuleResult 0 2 2 | ||
lNode |><| rNode = case (lNode ^. nodeType, rNode ^. nodeType) of | ||
(Apply, Abs) -> applyToLambdaRule lNode rNode | ||
(Abs, Apply) -> applyToLambdaRule lNode rNode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be |
||
_ -> error "There is no rule for this active pair in the reduction rules" | ||
where | ||
applyToLambdaRule n1 n2 = | ||
let arisingNodes = def | ||
portToEdgeEnd p = case p ^. nodeAddress of | ||
Nothing -> error "Port must to be connected" | ||
Just addr -> case addr of | ||
ActualAddress addrNum -> EdgeEnd addrNum (p ^. portConnectedToId) | ||
LocalAddress addrNum -> EdgeEnd addrNum (p ^. portConnectedToId) -- Maybe this is should be more complicated | ||
portsToEdgeEnds node = map (maybe (error "All Ports must to be presented") portToEdgeEnd) (node ^. secondaryPorts) | ||
lE = portsToEdgeEnds n1 | ||
rE = portsToEdgeEnds n2 | ||
arisingEdges = zipWith (\l r -> Just $ Edge l r) lE (reverse rE) | ||
in ReduceRuleResult arisingEdges arisingNodes |
This file contains 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,21 @@ | ||
module Core.Loader where | ||
|
||
import Clash.Prelude | ||
import Core.Node | ||
|
||
-- | Get `Node` by his `AddressNumber` from RAM. Actually, preparing to reducer work. | ||
loader :: | ||
( KnownDomain dom | ||
, HiddenClockResetEnable dom | ||
, KnownNat numberOfPorts | ||
) => | ||
(Signal dom AddressNumber -> Signal dom (Node numberOfPorts)) -> | ||
Signal dom (Maybe AddressNumber) -> | ||
Signal dom (Maybe (LoadedNode numberOfPorts)) | ||
loader ram mbAddressNumberToLoad = | ||
mkLoadedNode <$> mbNode <*> mbAddressNumberToLoad | ||
where | ||
mkLoadedNode node address = LoadedNode <$> node <*> address | ||
mbNode = case sequenceA mbAddressNumberToLoad of | ||
Nothing -> pure Nothing | ||
Just n -> sequenceA $ Just (ram n) |
This file contains 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,70 @@ | ||
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} | ||
|
||
{-# HLINT ignore "Eta reduce" #-} | ||
|
||
module Core.Map (Map, find, insertWith, insert) where | ||
|
||
import Clash.Prelude | ||
import Core.Node | ||
|
||
{- $setup | ||
>>> import Clash.Prelude | ||
>>> import Core.Node | ||
-} | ||
|
||
{- | key-value store based on `Vec`. Key is `AddressNumber`, it has linear time to find or change element. | ||
But iterate (such as map or fold) by value and key is easy. | ||
It assumed that `size` is small | ||
-} | ||
type Map (size :: Nat) v = (Vec size (Maybe (AddressNumber, Maybe v))) | ||
|
||
find :: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be done using fold? It should be more efficient. I hope. |
||
(KnownNat size) => | ||
Map size v -> | ||
AddressNumber -> | ||
Maybe v | ||
find dict key = case dict of | ||
Nil -> Nothing | ||
(Just (k, v) `Cons` t) -> if k == key then v else find t key | ||
(Nothing `Cons` t) -> find t key | ||
|
||
{- | Update or insert (by applying function to `Nothing`) value by the key. | ||
|
||
TODO: fix @id@ case. If @func@ is isomorphic to @id@ then @insertWith@ works incorrect | ||
-} | ||
insertWith :: | ||
(KnownNat size, Eq v) => | ||
Map size v -> | ||
(Maybe v -> Maybe v) -> | ||
AddressNumber -> | ||
Map size v | ||
insertWith dict func key = if dict /= updated then updated else inserted | ||
where | ||
updated = update key func dict | ||
inserted = insert key (func Nothing) dict | ||
|
||
-- | Try to update (by applying the function) value by key. It does nothing if there is no value by the key in the `Map` | ||
update :: | ||
AddressNumber -> | ||
(Maybe v -> Maybe v) -> | ||
Map size v -> | ||
Map size v | ||
update key func dict = map (fmap updateIfKeysEquals) dict | ||
where | ||
updateIfKeysEquals (k, v) = if k == key then (k, func v) else (k, v) | ||
|
||
{- | Insert key-value pair in the free space | ||
|
||
>>> insert 1 (Just 1) (def :: Map 2 AddressNumber) | ||
Just (1,Just 1) :> Nothing :> Nil | ||
-} | ||
insert :: | ||
AddressNumber -> | ||
Maybe v -> | ||
Map size v -> | ||
Map size v | ||
insert key value dict = case dict of | ||
h `Cons` t -> case h of | ||
Nothing -> Just (key, value) `Cons` t | ||
Just _ -> h `Cons` insert key value t | ||
Nil -> error "All addresses are written" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not
Concrete
, butExample
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea that in common case this module will generate automatically by Template Haskell and some dsl. It is just example for now, but something more complex in the future