Skip to content

Commit

Permalink
add some operations
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Jan 14, 2024
1 parent 86b9607 commit 63e6cd7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lvtrun/src/Run/Vm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,41 @@ execIf cEx@(CurrentExec {ceStack = stack}) = case stackTop stack of
I_32 _ -> throw $ RuntimeError "execIf: bad if statement"
_ -> throw $ RuntimeError "execIf: bad type"

execI32GtS :: CurrentExec -> CurrentExec
execI32GtS cEx@(CurrentExec {ceStack = stack}) =
case (stackPopN stack 2) of

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

View workflow job for this annotation

GitHub Actions / compil-linux

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-macos

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-windows

Pattern match(es) are non-exhaustive
([I_32 val2, I_32 val1], newStack) -> case (val1 > val2) of
True -> cEx { ceStack = stackPush newStack (I_32 1) }
False -> cEx { ceStack = stackPush newStack (I_32 0) }

execI32GeS :: CurrentExec -> CurrentExec
execI32GeS cEx@(CurrentExec {ceStack = stack}) =
case (stackPopN stack 2) of

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

View workflow job for this annotation

GitHub Actions / compil-linux

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-macos

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-windows

Pattern match(es) are non-exhaustive
([I_32 val2, I_32 val1], newStack) -> case (val1 >= val2) of
True -> cEx { ceStack = stackPush newStack (I_32 1) }
False -> cEx { ceStack = stackPush newStack (I_32 0) }

execI32LtS :: CurrentExec -> CurrentExec
execI32LtS cEx@(CurrentExec {ceStack = stack}) =
case (stackPopN stack 2) of

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

View workflow job for this annotation

GitHub Actions / compil-linux

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-macos

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-windows

Pattern match(es) are non-exhaustive
([I_32 val2, I_32 val1], newStack) -> case (val1 < val2) of
True -> cEx { ceStack = stackPush newStack (I_32 1) }
False -> cEx { ceStack = stackPush newStack (I_32 0) }

execI32LeS :: CurrentExec -> CurrentExec
execI32LeS cEx@(CurrentExec {ceStack = stack}) =
case (stackPopN stack 2) of

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

View workflow job for this annotation

GitHub Actions / compil-linux

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-macos

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-windows

Pattern match(es) are non-exhaustive
([I_32 val2, I_32 val1], newStack) -> case (val1 <= val2) of
True -> cEx { ceStack = stackPush newStack (I_32 1) }
False -> cEx { ceStack = stackPush newStack (I_32 0) }

execI32GtU :: CurrentExec -> CurrentExec
execI32GtU cEx@(CurrentExec {ceStack = stack}) =
case (stackPopN stack 2) of

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

View workflow job for this annotation

GitHub Actions / compil-linux

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-macos

Pattern match(es) are non-exhaustive

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

View workflow job for this annotation

GitHub Actions / compil-windows

Pattern match(es) are non-exhaustive
([I_32 val2, I_32 val1], newStack) -> case ((fromIntegral val1) > (fromIntegral val2)) of

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

View workflow job for this annotation

GitHub Actions / compil-linux

• Defaulting the type variable ‘a0’ to type ‘Integer’ in the following constraints

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

View workflow job for this annotation

GitHub Actions / compil-macos

• Defaulting the type variable ‘a0’ to type ‘Integer’ in the following constraints

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

View workflow job for this annotation

GitHub Actions / compil-windows

* Defaulting the type variable `a0' to type `Integer' in the following constraints
True -> cEx { ceStack = stackPush newStack (I_32 1) }
False -> cEx { ceStack = stackPush newStack (I_32 0) }

execOpCode :: VM -> CurrentExec -> Instruction -> CurrentExec
execOpCode _ cEx (Unreachable) = throw $ RuntimeError "execOpCode: unreachable"
execOpCode _ cEx (End) = decrementBlockIdx cEx
Expand All @@ -126,8 +161,17 @@ execOpCode _ cEx (SetLocal localIdx) = execSetLocal cEx localIdx
execOpCode _ cEx (BrIf labelIdx) = execBrIf cEx
execOpCode vm cEx (Call funcIdx) = execCall vm cEx funcIdx
execOpCode _ cEx (If) = execIf cEx
execOpCode _ cEx (I32Gts) = execI32GtS cEx
execOpCode _ cEx (I32Ges) = execI32GeS cEx
execOpCode _ cEx (I32Lts) = execI32LtS cEx
execOpCode _ cEx (I32Les) = execI32LeS cEx
execOpCode _ cEx (I32Gtu) = execI32GtU cEx
execOpCode _ cEx _ = cEx

--IF/ELSE
--LOOP
--BR

execOpCodes :: VM -> [Instruction] -> CurrentExec
execOpCodes vm [] = currentExec vm
execOpCodes vm instructions
Expand Down
3 changes: 3 additions & 0 deletions lvtrun/src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ data Instruction =
| MemorySize
| MemoryGrow
deriving (Eq)
--IF/ELSE
--LOOP
--BR

instance Show Instruction where
show Unreachable = "\n\t\t\t\tunreachable"
Expand Down
Binary file added lvtrun/test/while.wasm
Binary file not shown.

0 comments on commit 63e6cd7

Please sign in to comment.