@@ -362,7 +362,8 @@ End Slice.
362362Module Ref.
363363 Module Core.
364364 Inductive t (A : Set ) `{Link A} : Set :=
365- | Immediate (value : A)
365+ (** The value is optional for pointers to an enum case that is not the current one. *)
366+ | Immediate (value : option A)
366367 | Mutable {Address Big_A : Set }
367368 (address : Address)
368369 (path : Pointer.Path .t)
@@ -375,7 +376,7 @@ Module Ref.
375376 Definition to_core {A : Set} `{Link A} (ref : t A) : Pointer.Core.t Value.t :=
376377 match ref with
377378 | Immediate value =>
378- Pointer.Core.Immediate (φ value)
379+ Pointer.Core.Immediate (Option.map value φ )
379380 | Mutable address path big_to_value projection injection =>
380381 Pointer.Core.Mutable address path
381382 end .
@@ -403,7 +404,7 @@ Module Ref.
403404 }.
404405
405406 Definition immediate (kind : Pointer.Kind.t) {A : Set } `{Link A} (value : A) : t kind A :=
406- {| core := Core.Immediate value |}.
407+ {| core := Core.Immediate (Some value) |}.
407408
408409 Definition cast_to {A : Set} `{Link A} {kind_source : Pointer.Kind.t}
409410 (kind_target : Pointer.Kind.t) (ref : t kind_source A) :
@@ -495,7 +496,7 @@ Module Ref.
495496 value' = φ value ->
496497 Value.Pointer {|
497498 Pointer.kind := Pointer.Kind.Raw;
498- Pointer.core := Pointer.Core.Immediate value';
499+ Pointer.core := Pointer.Core.Immediate (Some value') ;
499500 |} = φ (immediate Pointer.Kind.Raw value).
500501 Proof .
501502 now intros; subst.
@@ -506,7 +507,7 @@ Module Ref.
506507 OfValue.t value' ->
507508 OfValue.t (Value.Pointer {|
508509 Pointer.kind := Pointer.Kind.Raw;
509- Pointer.core := Pointer.Core.Immediate value';
510+ Pointer.core := Pointer.Core.Immediate (Some value') ;
510511 |}).
511512 Proof .
512513 intros [A].
@@ -564,6 +565,52 @@ Module SubPointer.
564565 Value.write_index (φ a) index (φ sub_a);
565566 }.
566567 End Valid.
568+
569+ Definition apply {A : Set} `{Link A} {index : Pointer.Index.t}
570+ (ref_core : Ref.Core.t A)
571+ (runner : SubPointer.Runner.t A index) :
572+ let _ := runner.(H_Sub_A) in
573+ Ref.Core.t runner.(Sub_A).
574+ Proof .
575+ destruct
576+ ref_core as [| ? ? address path big_to_value projection injection],
577+ runner as [? ? runner_projection runner_injection];
578+ cbn.
579+ { (* Immediate *)
580+ exact (
581+ Ref.Core.Immediate (
582+ match value with
583+ | Some a => runner_projection a
584+ | None => None
585+ end
586+ )
587+ ).
588+ }
589+ { (* Mutable *)
590+ exact (
591+ Ref.Core.Mutable
592+ address
593+ (path ++ [index])
594+ big_to_value
595+ (fun big_a =>
596+ match projection big_a with
597+ | Some a => runner_projection a
598+ | None => None
599+ end
600+ )
601+ (fun big_a new_sub_a =>
602+ match projection big_a with
603+ | Some a =>
604+ match runner_injection a new_sub_a with
605+ | Some new_a => injection big_a new_a
606+ | None => None
607+ end
608+ | None => None
609+ end
610+ )
611+ ).
612+ }
613+ Defined .
567614 End Runner.
568615End SubPointer.
569616
@@ -693,6 +740,9 @@ Module Output.
693740 inr exception' = to_value (Output.Exception (R := R) exception).
694741 Proof . now intros; subst. Qed .
695742 Smpl Add apply of_exception_eq : of_output.
743+
744+ Definition panic {R Output : Set } (message : string) : t R Output :=
745+ Exception (Exception.Panic (Panic.Make message)).
696746End Output.
697747
698748(** For the output of closure calls, where we know it can only be a success or panic, but not a
@@ -716,6 +766,15 @@ Module SuccessOrPanic.
716766 | Success output => Output.Success output
717767 | Panic panic => Output.Exception (Output.Exception.Panic panic)
718768 end .
769+
770+ Definition of_output {Output : Set} (output : Output.t Output Output) :
771+ t Output :=
772+ match output with
773+ | Output.Success output => Success output
774+ | Output.Exception (Output.Exception.Panic panic) => Panic panic
775+ | Output.Exception _ =>
776+ Panic (Panic.Make "unexpected return , break, or continue escaping a function")
777+ end .
719778End SuccessOrPanic.
720779
721780Module Run.
@@ -1082,8 +1141,16 @@ Ltac run_symbolic_pure :=
10821141 repeat smpl of_value
10831142 ).
10841143
1144+ Ltac run_symbolic_state_alloc :=
1145+ unshelve eapply Run.CallPrimitiveStateAlloc; [
1146+ repeat smpl of_value |
1147+ cbn; intros
1148+ ].
1149+
10851150Ltac run_symbolic_state_alloc_immediate :=
1086- unshelve eapply Run.CallPrimitiveStateAllocImmediate; [now repeat smpl of_value |].
1151+ unshelve eapply Run.CallPrimitiveStateAllocImmediate; [
1152+ repeat smpl of_value |
1153+ ].
10871154
10881155Ltac run_symbolic_state_read :=
10891156 eapply Run.CallPrimitiveStateRead;
@@ -1294,7 +1361,11 @@ Ltac rewrite_cast_integer :=
12941361 end .
12951362
12961363Ltac run_symbolic_let :=
1297- unshelve eapply Run.Let ; [repeat smpl of_ty | | cbn; intros []].
1364+ unshelve eapply Run.Let ; [
1365+ repeat smpl of_ty |
1366+ try run_symbolic_state_alloc |
1367+ cbn; intros []
1368+ ].
12981369
12991370Ltac run_symbolic_are_equal_bool :=
13001371 eapply Run.CallPrimitiveAreEqualBool;
0 commit comments