<commit_before>module CalculatorArrow where

import CLaSH.Prelude
import Control.Arrow

type Word = Signed 4
data OPC a = ADD | MUL | Imm a | Pop | Push

(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(f .: g) a b = f (g a b)

infixr 9 .:

alu ADD     = Just .: (+)
alu MUL     = Just .: (*)
alu (Imm i) = const . const (Just i)
alu _       = const . const Nothing

pu alu (op1,op2,cnt) (dmem,Pop)  = ((dmem,op1,cnt-1),(cnt,Nothing))
pu alu (op1,op2,cnt) (dmem,Push) = ((op1,op2,cnt+1) ,(cnt,Nothing))
pu alu (op1,op2,cnt) (dmem,opc)  = ((op1,op2,cnt)   ,(cnt,alu opc op1 op2))

datamem mem (addr,Nothing)  = (mem                  ,mem ! addr)
datamem mem (addr,Just val) = (vreplace mem addr val,mem ! addr)

topEntity :: Comp (OPC Word) (Maybe Word)
topEntity = proc i -> do
    rec (addr,val) <- (pu alu ^^^ (0,0,0 :: Unsigned 3)) -< (mem,i)
        mem        <- (datamem ^^^ initMem)              -< (addr,val)
    returnA -< val
  where
    initMem    = vcopy (snat :: SNat 8) 0

testInput :: [OPC Word]<commit_msg>remove superfluous import from CalculatorArrow example<commit_after>module CalculatorArrow where

import CLaSH.Prelude

type Word = Signed 4
data OPC a = ADD | MUL | Imm a | Pop | Push

(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
(f .: g) a b = f (g a b)

infixr 9 .:

alu ADD     = Just .: (+)
alu MUL     = Just .: (*)
alu (Imm i) = const . const (Just i)
alu _       = const . const Nothing

pu alu (op1,op2,cnt) (dmem,Pop)  = ((dmem,op1,cnt-1),(cnt,Nothing))
pu alu (op1,op2,cnt) (dmem,Push) = ((op1,op2,cnt+1) ,(cnt,Nothing))
pu alu (op1,op2,cnt) (dmem,opc)  = ((op1,op2,cnt)   ,(cnt,alu opc op1 op2))

datamem mem (addr,Nothing)  = (mem                  ,mem ! addr)
datamem mem (addr,Just val) = (vreplace mem addr val,mem ! addr)

topEntity :: Comp (OPC Word) (Maybe Word)
topEntity = proc i -> do
    rec (addr,val) <- (pu alu ^^^ (0,0,0 :: Unsigned 3)) -< (mem,i)
        mem        <- (datamem ^^^ initMem)              -< (addr,val)
    returnA -< val
  where
    initMem    = vcopy (snat :: SNat 8) 0

testInput :: [OPC Word]
{'fraction_non_alphanumeric': 0.1824782187802517, 'fraction_numerical': 0.022265246853823813, 'mean_word_length': 2.594782608695652, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3366884', 'n_tokens_mistral': 877, 'n_tokens_neox': 861, 'n_words': 250}