Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Sep 25, 2023
1 parent 3fc428e commit 7141f3b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pact-core/Pact/Core/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ data DesugarError
--
| EmptyDefPact Text
-- ^ Defpact without steps
| LastStepWithRollback QualifiedName
-- ^ Last Step has Rollback error
deriving Show

instance Exception DesugarError
Expand Down Expand Up @@ -183,6 +185,8 @@ instance Pretty DesugarError where
Pretty.hsep ["Invalid Interface attempted to be used as module reference:", pretty mn]
EmptyBindingBody -> "Bind expression lacks an accompanying body"
EmptyDefPact dp -> Pretty.hsep ["Defpact has no steps:", pretty dp]
LastStepWithRollback mn ->
Pretty.hsep ["rollbacks aren't allowed on the last step in:", pretty mn]

-- data TypecheckError
-- = UnificationError (Type Text) (Type Text)
Expand Down
10 changes: 8 additions & 2 deletions pact-core/Pact/Core/IR/Desugar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ desugarDefPact
:: forall i m raw reso. MonadDesugar raw reso i m
=> Lisp.DefPact i
-> m (DefPact ParsedName DesugarType raw i)
desugarDefPact (Lisp.DefPact dpname _ _ [] _ _ i) = throwDesugarError (EmptyDefPact dpname) i
desugarDefPact (Lisp.DefPact dpname _ _ [] _ _ i) =
throwDesugarError (EmptyDefPact dpname) i
desugarDefPact (Lisp.DefPact dpname margs rt (step:steps) _ _ i) =
view reCurrModule >>= \case
Just mn -> do
Expand All @@ -383,7 +384,12 @@ desugarDefPact (Lisp.DefPact dpname margs rt (step:steps) _ _ i) =
<$> desugarStep s
<*> desugarStep rb
<*> desugarMSteps ms
pure $ DefPact dpname args' rt (NE.reverse steps') i

-- In Pact, last steps are not allowed to roll back.
when (hasRollback $ NE.last steps') $
throwDesugarError (LastStepWithRollback (QualifiedName dpname mn)) i

pure $ DefPact dpname args' rt steps' i
Nothing -> error "Defpact is module-less"

desugarDefConst
Expand Down
7 changes: 7 additions & 0 deletions pact-core/Pact/Core/IR/Eval/CEK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ returnCEKValue (StackPopC mty cont) handler v = do
v' <- (`maybeTCType` mty) =<< enforcePactValue v
-- Todo: unsafe use of tail here. need `tailMay`
(esStack %%= tail) *> returnCEKValue cont handler (VPactValue v')
returnCEKValue (PactStepC cont) handler v = do
-- We need to reset the `yield` value of the current pact exection
-- environment to match pact semantics. This `PactStepC` frame is
-- only used as a continuation which resets the `yield`.
setEvalState (esPactExec . _Just . peYield) Nothing
returnCEKValue cont handler v



applyLam
Expand Down
1 change: 1 addition & 0 deletions pact-core/Pact/Core/IR/Eval/Runtime/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ data Cont b i m
| CapBodyC (CEKEnv b i m) (EvalTerm b i) (Cont b i m)
| CapPopC CapPopState (Cont b i m)
| StackPopC (Maybe Type) (Cont b i m)
| PactStepC (Cont b i m)
| Mt
deriving Show

Expand Down
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/IR/Eval/Runtime/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ enforcePactValue = \case
-- viewsCEKEnv :: (MonadEval b i m) => Lens' (EvalEnv b i m) s -> (s -> a) -> m a
-- viewsCEKEnv l f = views f l <$> cekReadEnv f

setEvalState :: (MonadEval b i m) => Lens' (EvalState b i) s -> s -> m ()
setEvalState :: (MonadEval b i m) => Traversal' (EvalState b i) s -> s -> m ()
setEvalState l s = modifyEvalState (set l s)

-- overEvalState :: (MonadEval b i m) => Lens' (EvalState b i) s -> (s -> s) -> m ()
Expand Down
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/Repl/Runtime/ReplBuiltin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ continuePact info b = mkReplBuiltinFn info b \cont handler -> \case
Step s' _ -> toClosure s'
StepWithRollback s' _rb _ -> toClosure s'
setEvalState esPactExec (Just $ over peStep (+1) pe)
returnCEK cont handler v
returnCEK (PactStepC cont) handler v
| otherwise ->
throwExecutionError info (ContinuePactInvalidContext s (toInteger (_peStep pe)) (toInteger (_peStepCount pe)))
_ -> pure (VError "continuation is not a defpact")
Expand Down
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/Syntax/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Defcap :: { SpanInfo -> DefCap SpanInfo }

DefPact :: { SpanInfo -> DefPact SpanInfo }
: defpact IDENT MTypeAnn '(' MArgs ')' MDocOrModel Steps
{ DefPact (getIdent $2) $5 $3 $8 (fst $7) (snd $7) }
{ DefPact (getIdent $2) $5 $3 (reverse $8) (fst $7) (snd $7) }

Steps :: { [PactStep SpanInfo] }
: Steps Step { $2:$1 }
Expand Down

0 comments on commit 7141f3b

Please sign in to comment.