@@ -308,7 +308,7 @@ data CekValue uni fun ann =
308
308
-- Check the docs of 'BuiltinRuntime' for details.
309
309
-- | A constructor value, including fully computed arguments and the tag.
310
310
| VConstr {- # UNPACK #-} !Word64 ! (EmptyOrMultiStack uni fun ann )
311
- | VBinds ! ( ArgStackNonEmpty uni fun ann )
311
+ | VLet ! [ NamedDeBruijn ] ! ( NTerm uni fun ann ) ! ( CekValEnv uni fun ann )
312
312
313
313
deriving stock instance (GShow uni , Everywhere uni Show , Show fun , Show ann , Closed uni )
314
314
=> Show (CekValue uni fun ann )
@@ -640,6 +640,11 @@ dischargeCekValue value0 = DischargeNonConstant $ goValue value0 where
640
640
-- @term@ is fully discharged, so we can return it directly without any further discharging.
641
641
VBuiltin _ term _ -> term
642
642
VConstr ind args -> Constr () ind . map goValue $ argStackToList args
643
+ VLet names body env ->
644
+ Let
645
+ ()
646
+ ((\ (NamedDeBruijn n _ix) -> NamedDeBruijn n deBruijnInitIndex) <$> names)
647
+ (goValEnv env 1 body)
643
648
644
649
-- Instantiate all the free variables of a term by looking them up in an environment.
645
650
-- Mutually recursive with @goValue@.
@@ -670,6 +675,8 @@ dischargeCekValue value0 = DischargeNonConstant $ goValue value0 where
670
675
Error _ -> Error ()
671
676
Constr _ ind args -> Constr () ind $ map (go shift) args
672
677
Case _ scrut alts -> Case () (go shift scrut) $ fmap (go shift) alts
678
+ Let _ names body -> Let () names (go (shift + fromIntegral (length names)) body)
679
+ Bind _ t bs -> Bind () (go shift t) (fmap (go shift) bs)
673
680
674
681
instance (PrettyUni uni , Pretty fun ) => PrettyBy PrettyConfigPlc (CekValue uni fun ann ) where
675
682
prettyBy cfg = prettyBy cfg . dischargeResultToTerm . dischargeCekValue
@@ -706,6 +713,8 @@ data Context uni fun ann
706
713
-- ^ @(constr i V0 ... Vj-1 _ Nj ... Nn)@
707
714
| FrameCases ! (CekValEnv uni fun ann ) ! (V. Vector (NTerm uni fun ann )) ! (Context uni fun ann )
708
715
-- ^ @(case _ C0 .. Cn)@
716
+ | FrameAwaitLetBinds ! (CekValEnv uni fun ann ) ! (NTerm uni fun ann ) ! [NTerm uni fun ann ] ! [CekValue uni fun ann ] ! (Context uni fun ann )
717
+ | FrameMine ! [CekValue uni fun ann ] ! (Context uni fun ann )
709
718
| NoFrame
710
719
711
720
deriving stock instance (GShow uni , Everywhere uni Show , Show fun , Show ann , Closed uni )
@@ -719,6 +728,7 @@ instance (Closed uni, uni `Everywhere` ExMemoryUsage) => ExMemoryUsage (CekValue
719
728
VLamAbs {} -> singletonRose 1
720
729
VBuiltin {} -> singletonRose 1
721
730
VConstr {} -> singletonRose 1
731
+ VLet {} -> singletonRose 1
722
732
{-# INLINE memoryUsage #-}
723
733
724
734
{- Note [ArgStack vs Spine]
@@ -833,6 +843,16 @@ enterComputeCek = computeCek
833
843
-- s ; ρ ▻ error ↦ <> A
834
844
computeCek ! _ ! _ (Error _) =
835
845
throwErrorWithCause (OperationalError CekEvaluationFailure ) (Error () )
846
+ -- ???
847
+ computeCek ! ctx ! env (Let _ names body) = do
848
+ stepAndMaybeSpend BLamAbs
849
+ returnCek ctx (VLet names body env)
850
+ computeCek ! ctx ! env (Bind _ body bs) = do
851
+ -- stepAndMaybeSpend BApply
852
+ -- computeCek (FrameAwaitLetBinds env t bs ctx) env t
853
+ case bs of
854
+ (t : rest) -> computeCek (FrameAwaitLetBinds env body rest [] ctx) env t
855
+ [] -> computeCek ctx env body
836
856
837
857
{- | The returning phase of the CEK machine.
838
858
Returns 'EvaluationSuccess' in case the context is empty, otherwise pops up one frame
@@ -872,6 +892,11 @@ enterComputeCek = computeCek
872
892
SpineLast arg -> applyEvaluate ctx fun (VCon arg)
873
893
SpineCons arg rest -> applyEvaluate (FrameAwaitFunConN rest ctx) fun (VCon arg)
874
894
-- s , [_ V1 .. Vn] ◅ lam x (M,ρ) ↦ s , [_ V2 .. Vn]; ρ [ x ↦ V1 ] ▻ M
895
+ returnCek (FrameMine args ctx) l =
896
+ case l of
897
+ VLet _ body env -> computeCek ctx (foldr Env. cons env args) body
898
+ _ -> error " no"
899
+
875
900
returnCek (FrameAwaitFunValueN args ctx) fun =
876
901
case args of
877
902
LastStackNonEmpty arg ->
@@ -906,6 +931,14 @@ enterComputeCek = computeCek
906
931
Right (HeadOnly fX) -> computeCek ctx env fX
907
932
Right (HeadSpine f xs) -> computeCek (FrameAwaitFunConN xs ctx) env f
908
933
_ -> throwErrorDischarged (StructuralError NonConstrScrutinizedMachineError ) e
934
+ -- returnCek (FrameAwaitLetTerm env bs ctx) e =
935
+ -- case bs of
936
+ -- (next : todo) -> computeCek (FrameAwaitLetBinds env e todo [] ctx) env next
937
+ -- [] -> returnCek ctx e -- no bindings
938
+ returnCek (FrameAwaitLetBinds env l todo done ctx) e =
939
+ case todo of
940
+ (next : todo') -> computeCek (FrameAwaitLetBinds env l todo' (e : done) ctx) env next
941
+ [] -> computeCek (FrameMine (e : done) ctx) env l
909
942
910
943
-- | @force@ a term and proceed.
911
944
-- If v is a delay then compute the body of v;
0 commit comments