Skip to content

Commit

Permalink
fix some norm error
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Jan 14, 2024
1 parent 663d44f commit 26f3ac1
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions lvtrun/src/Run/Vm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,35 @@ execI32Divs cEx@(CurrentExec {ceStack = stack}) =
cEx { ceStack = stackPush newStack (I_32 (val1 `div` val2)) }
_ -> throw $ RuntimeError "exec I32divs: bad type"

execGetLocal :: CurrentExec -> LocalIdx -> CurrentExec
execGetLocal cEx localIdx = cEx { ceStack =
stackPush (ceStack cEx) (getLocalFromId (ceLocals cEx) localIdx)}

execSetLocal :: CurrentExec -> LocalIdx -> CurrentExec
execSetLocal cEx localIdx = cEx { ceStack = newStack,
ceLocals = setLocalWithId 0 (ceLocals cEx) value localIdx}
where (value, newStack) = stackPop (ceStack cEx)

execBrIf :: CurrentExec -> CurrentExec
execBrIf cEx@(CurrentExec {ceStack = stack}) =
case (stackTop stack) of
I_32 0 -> cEx
I_32 _ -> cEx { ceInstIdx = (ceInstIdx cEx) }
_ -> throw $ RuntimeError "exec brIf: bad type"

execCall :: VM -> CurrentExec -> FuncIdx -> CurrentExec
execCall vm cEx funcIdx = do

Check warning on line 98 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-linux

This binding for ‘funcIdx’ shadows the existing binding

Check warning on line 98 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-macos

This binding for ‘funcIdx’ shadows the existing binding

Check warning on line 98 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-windows

This binding for `funcIdx' shadows the existing binding

Check warning on line 98 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / tests

This binding for ‘funcIdx’ shadows the existing binding
let newVm = execFunctionWithIdx vm funcIdx (ceStack cEx)
let newStack = pushResults (ceStack cEx) (vmStack newVm) (ceResults (currentExec newVm))
cEx { ceStack = newStack }

execIf :: CurrentExec -> CurrentExec
execIf cEx@(CurrentExec {ceStack = stack}) = case stackTop stack of
I_32 0 -> goToEndInstruction cEx
I_32 1 -> cEx { crBlockIndents = (crBlockIndents cEx) + 1 }
I_32 _ -> throw $ RuntimeError "execIf: bad if statement"
_ -> throw $ RuntimeError "execIf: bad type"

execOpCode :: VM -> CurrentExec -> Instruction -> CurrentExec
execOpCode _ cEx (Unreachable) = throw $ RuntimeError "execOpCode: unreachable"

Check warning on line 111 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-linux

Defined but not used: ‘cEx’

Check warning on line 111 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-macos

Defined but not used: ‘cEx’

Check warning on line 111 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-windows

Defined but not used: `cEx'

Check warning on line 111 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / tests

Defined but not used: ‘cEx’
execOpCode _ cEx (End) = decrementBlockIdx cEx
Expand All @@ -90,26 +119,11 @@ execOpCode _ cEx (I32Add) = execI32Add cEx
execOpCode _ cEx (I32Sub) = execI32Sub cEx
execOpCode _ cEx (I32Mul) = execI32Mul cEx
execOpCode _ cEx (I32Divs) = execI32Divs cEx
execOpCode _ cEx (BrIf labelIdx) = case stackTop (ceStack cEx) of
I_32 0 -> cEx
I_32 _ -> cEx { ceInstIdx = (fromIntegral labelIdx) }
_ -> throw $ RuntimeError "exec brIf: bad type"
execOpCode vm cEx (Call funcIdx) = do
let newVm = execFunctionWithIdx vm funcIdx (ceStack cEx)
let newStack = pushResults (ceStack cEx) (vmStack newVm) (ceResults (currentExec newVm))
cEx { ceStack = newStack }
execOpCode _ cEx (GetLocal localIdx) = do
let value = getLocalFromId (ceLocals cEx) localIdx
cEx { ceStack = stackPush (ceStack cEx) value }
execOpCode _ cEx (SetLocal localIdx) = do
let (value, newStack) = stackPop (ceStack cEx)
let newLocals = setLocalWithId 0 (ceLocals cEx) value localIdx
cEx { ceStack = newStack, ceLocals = newLocals }
execOpCode _ cEx (If) = case stackTop (ceStack cEx) of
I_32 0 -> goToEndInstruction cEx
I_32 1 -> cEx { crBlockIndents = (crBlockIndents cEx) + 1 }
I_32 _ -> throw $ RuntimeError "execOpCode: bad if statement"
_ -> throw $ RuntimeError "execOpCode: bad type"
execOpCode _ cEx (GetLocal localIdx) = execGetLocal cEx localIdx
execOpCode _ cEx (SetLocal localIdx) = execSetLocal cEx localIdx
execOpCode _ cEx (BrIf labelIdx) = execBrIf cEx

Check warning on line 124 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-linux

Defined but not used: ‘labelIdx’

Check warning on line 124 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-macos

Defined but not used: ‘labelIdx’

Check warning on line 124 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-windows

Defined but not used: `labelIdx'

Check warning on line 124 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / tests

Defined but not used: ‘labelIdx’
execOpCode vm cEx (Call funcIdx) = execCall vm cEx funcIdx

Check warning on line 125 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-linux

This binding for ‘funcIdx’ shadows the existing binding

Check warning on line 125 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-macos

This binding for ‘funcIdx’ shadows the existing binding

Check warning on line 125 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / compil-windows

This binding for `funcIdx' shadows the existing binding

Check warning on line 125 in lvtrun/src/Run/Vm.hs

View workflow job for this annotation

GitHub Actions / tests

This binding for ‘funcIdx’ shadows the existing binding
execOpCode _ cEx (If) = execIf cEx
execOpCode _ cEx _ = cEx

execOpCodes :: VM -> [Instruction] -> CurrentExec
Expand Down

0 comments on commit 26f3ac1

Please sign in to comment.