diff --git a/Semantics.fs b/Semantics.fs
index 5e70610..c746e96 100644
--- a/Semantics.fs
+++ b/Semantics.fs
@@ -466,28 +466,6 @@ let rec markMicrocode
traverseMicrocode lt rt
-///
-/// Updates a map from variables to their last marker with the assignments
-/// in a microcode listing.
-///
-let rec updateState
- (state : Map)
- (listing : Microcode, Sym> list)
- : Map =
- let updateOne (s : Map) m =
- // TODO(CaptainHayashi): de-duplicate this
- match m with
- | Symbol _ | Assume _ -> s
- | Assign (lv, rv) ->
- // Assumption: this is monotone, eg. rv >= s.[lv]
- // TODO(CaptainHayashi): check this?
- match (valueOf lv) with
- | Before l | After l | Intermediate (_, l) | Goal (_, l) ->
- s.Add(withType (typeOf lv) l, valueOf lv)
- | Branch (i, t, e) ->
- updateState (updateState s t) e
- List.fold updateOne state listing
-
///
/// Converts a microcode instruction into a two-state Boolean predicate.
///
@@ -571,6 +549,12 @@ let mergeBranch
Seq.foldBack insertMapping (Map.toSeq tMap) ([], [], Map.empty)
+let updateState (st : Map) (vars : CTyped list)
+ : Map =
+ let updateOne (st' : Map) var =
+ st'.Add (unmark var, valueOf var)
+ List.fold updateOne st vars
+
///
/// Normalises and marks an entire microcode routine with variable states.
///
@@ -589,13 +573,6 @@ let processMicrocodeRoutine
: Result<( Microcode, Sym> list
* Map ),
Error> =
- // TODO(CaptainHayashi): flatten into a single list
- // TODO(CaptainHayashi): compose array accesses properly
-
- (* Each item in 'routine' represents a microcode instruction, and has a
- corresponding variable state: the first is Intermediate 0, the second
- Intermediate 1, and so on until the last stage assigns to After. *)
-
(* First, normalise the listing.
This ensures only whole variables are written to, which allows us to
track the assignment later. *)
@@ -604,7 +581,7 @@ let processMicrocodeRoutine
(* Next, we annotate each command with the corresponding state marker.
This is inherently recursive, because the microcode can contain
branches. *)
- let rec markInstructions afterIndex topState instrs
+ let rec markInstructions topState instrs
: Result, Sym> list
* Map,
TraversalError> =
@@ -620,15 +597,10 @@ let processMicrocodeRoutine
fail (Inner (BadSemantics "somehow referenced variable not in scope"))
| Some mv ->
let markedVar = markFun mv
- let pushVarMaybe ctx var =
- match ctx with
- | Vars _ -> pushVar ctx var
- | _ -> ok ctx
-
lift
(fun ctx' ->
(ctx', withType (typeOf var) (varFun markedVar)))
- (pushVarMaybe ctx (withType (typeOf var) markedVar))
+ (tryPushVar ctx (withType (typeOf var) markedVar))
let markRValue state ctx var = markVar id Reg state ctx var
@@ -636,10 +608,6 @@ let processMicrocodeRoutine
: Result