Skip to content

Commit

Permalink
fix after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Jan 18, 2024
1 parent 9d38d64 commit f7d6369
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Juvix/Compiler/Reg/Translation/FromAsm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ fromAsmInstr funInfo tab si Asm.CmdInstr {..} =
Asm.Return ->
return $ Return InstrReturn {_instrReturnValue = VRef $ VarRef VarGroupLocal ntmps}
where
extraInfo :: Asm.FunctionInfoExtra
extraInfo = fromJust (funInfo ^. Asm.functionExtra)

-- `n` is the index of the top of the value stack *before* executing the
-- instruction
n :: Int
n = si ^. Asm.stackInfoValueStackHeight - 1

-- `ntmps` is the number of temporary variables (= max temporary stack height)
ntmps :: Int
ntmps = funInfo ^. Asm.functionMaxTempStackHeight
ntmps = extraInfo ^. Asm.functionMaxTempStackHeight

-- Live variables *after* executing the instruction. `k` is the number of
-- value stack cells that will be popped by the instruction. TODO: proper
Expand Down Expand Up @@ -270,7 +273,7 @@ fromAsmBranch fi si Asm.CmdBranch {} codeTrue codeFalse =
return $
Branch $
InstrBranch
{ _instrBranchValue = VRef $ VarRef VarGroupLocal (fi ^. Asm.functionMaxTempStackHeight + si ^. Asm.stackInfoValueStackHeight - 1),
{ _instrBranchValue = VRef $ VarRef VarGroupLocal (fromJust (fi ^. Asm.functionExtra) ^. Asm.functionMaxTempStackHeight + si ^. Asm.stackInfoValueStackHeight - 1),
_instrBranchTrue = codeTrue,
_instrBranchFalse = codeFalse
}
Expand All @@ -287,7 +290,7 @@ fromAsmCase fi tab si Asm.CmdCase {..} brs def =
return $
Case $
InstrCase
{ _instrCaseValue = VRef $ VarRef VarGroupLocal (fi ^. Asm.functionMaxTempStackHeight + si ^. Asm.stackInfoValueStackHeight - 1),
{ _instrCaseValue = VRef $ VarRef VarGroupLocal (fromJust (fi ^. Asm.functionExtra) ^. Asm.functionMaxTempStackHeight + si ^. Asm.stackInfoValueStackHeight - 1),
_instrCaseInductive = _cmdCaseInductive,
_instrCaseIndRep = ii ^. Asm.inductiveRepresentation,
_instrCaseBranches =
Expand Down Expand Up @@ -327,7 +330,7 @@ fromAsmSave fi si Asm.CmdSave {} block =
Assign
( InstrAssign
(VarRef VarGroupLocal (si ^. Asm.stackInfoTempStackHeight))
(VRef $ VarRef VarGroupLocal (fi ^. Asm.functionMaxTempStackHeight + si ^. Asm.stackInfoValueStackHeight - 1))
(VRef $ VarRef VarGroupLocal (fromJust (fi ^. Asm.functionExtra) ^. Asm.functionMaxTempStackHeight + si ^. Asm.stackInfoValueStackHeight - 1))
)
: block
}

0 comments on commit f7d6369

Please sign in to comment.