Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dougalm committed Nov 4, 2023
1 parent d80f318 commit 58cbbe1
Show file tree
Hide file tree
Showing 25 changed files with 1,825 additions and 1,921 deletions.
9 changes: 5 additions & 4 deletions src/lib/Algebra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Tuple (swap)

import Builder hiding (sub, add, mul)
import Core
import CheapReduction
import Err
import IRVariants
import MTL1
Expand Down Expand Up @@ -139,8 +140,8 @@ exprAsPoly expr = liftBuilder $ runMaybeT1 $ runSubstReaderT idSubst $ exprAsPol

atomAsPoly :: Atom SimpIR i -> BlockTraverserM i o (Polynomial o)
atomAsPoly = \case
Var v -> atomVarAsPoly v
RepValAtom (RepVal _ (Leaf (IVar v' _))) -> impNameAsPoly v'
Stuck _ (Var v) -> atomVarAsPoly v
Stuck _ (RepValAtom (RepVal _ (Leaf (IVar v' _)))) -> impNameAsPoly v'
IdxRepVal i -> return $ poly [((fromIntegral i) % 1, mono [])]
_ -> empty

Expand Down Expand Up @@ -207,10 +208,10 @@ emitMonomial :: Emits n => Monomial n -> BuilderM SimpIR n (Atom SimpIR n)
emitMonomial (Monomial m) = do
varAtoms <- forM (toList m) \(v, e) -> case v of
LeftE v' -> do
v'' <- Var <$> toAtomVar v'
v'' <- toAtom <$> toAtomVar v'
ipow v'' e
RightE v' -> do
let atom = RepValAtom $ RepVal IdxRepTy (Leaf (IVar v' IIdxRepTy))
atom <- mkStuck $ RepValAtom $ RepVal IdxRepTy (Leaf (IVar v' IIdxRepTy))
ipow atom e
foldM imul (IdxRepVal 1) varAtoms

Expand Down
230 changes: 112 additions & 118 deletions src/lib/Builder.hs

Large diffs are not rendered by default.

Loading

0 comments on commit 58cbbe1

Please sign in to comment.