module CompiletoVm (convert, makeConvert, getString, getList, getDefinedValue, getFnv, getArg) where
import Compiler
import Data.Binary
import Data.Binary.Get
import qualified Data.ByteString.Lazy as BIN
import GHC.Int
import Vm
type DcdStrInt = Either (BIN.ByteString, ByteOffset, String)
(BIN.ByteString, ByteOffset, Int32)
type DcdStrWord8 = Either (BIN.ByteString, ByteOffset, String)
(BIN.ByteString, ByteOffset, Word8)
type DcdStrChar = Either (BIN.ByteString, ByteOffset, String)
(BIN.ByteString, ByteOffset, Char)
makeConvert :: String -> IO Inst
makeConvert :: String -> IO Inst
makeConvert String
path = String -> IO ByteString
BIN.readFile String
path IO ByteString -> (ByteString -> IO Inst) -> IO Inst
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ByteString
filepath ->
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
filepath :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
allfile, ByteOffset
_, Int32
magicNumber)
| (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
magicNumber :: Int32) :: Int)
Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== CompileConstants -> Int
forall a. Enum a => a -> Int
fromEnum CompileConstants
MagicNumber -> ByteString -> Inst -> IO Inst
convert ByteString
allfile []
| Bool
otherwise -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
convert :: BIN.ByteString -> Inst -> IO Inst
convert :: ByteString -> Inst -> IO Inst
convert ByteString
file Inst
inst =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
file :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Inst
inst
Right (ByteString
remainingFile, ByteOffset
_, Word8
opcode) ->
ByteString -> Inst -> Instruction -> IO Inst
convertInstruction ByteString
remainingFile Inst
inst (Int -> Instruction
forall a. Enum a => Int -> a
toEnum (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
opcode))
convertInstruction :: BIN.ByteString -> Inst -> Compiler.Instruction -> IO Inst
convertInstruction :: ByteString -> Inst -> Instruction -> IO Inst
convertInstruction ByteString
remainingFile Inst
inst Instruction
NoOp = ByteString -> Inst -> IO Inst
convert ByteString
remainingFile Inst
inst
convertInstruction ByteString
remainingFile Inst
inst (PushI Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
val) ->
ByteString -> Inst -> IO Inst
convert ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Push (Int -> Value
IntVal (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int))])
convertInstruction ByteString
remainingFile Inst
inst (PushB Bool
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Word8
1) -> ByteString -> Inst -> IO Inst
convert ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Push (Bool -> Value
BoolVal Bool
True)])
Right (ByteString
remfile, ByteOffset
_, Word8
0) -> ByteString -> Inst -> IO Inst
convert ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Push (Bool -> Value
BoolVal Bool
False)])
Right (ByteString
remfile, ByteOffset
_, Word8
_) -> ByteString -> Inst -> IO Inst
convert ByteString
remfile Inst
inst
convertInstruction ByteString
remainingFile Inst
inst (PushStr String
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> ByteString -> Inst -> IO Inst
convert ((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Push (String -> Value
StringVal ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
byteToRead :: Int32) :: Int) ByteString
remfile [])))])
convertInstruction ByteString
remainingFile Inst
inst (PushSym String
_ Maybe [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) ->
ByteString -> Inst -> IO Inst
convert ((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int)
ByteString
remfile [])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [ String -> Instruction
PushEnv ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))])
convertInstruction ByteString
remainingFile Inst
inst (Compiler.PushArg Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
val) ->
ByteString -> Inst -> IO Inst
convert ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushArg (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
convertInstruction ByteString
remainingFile Inst
inst (Compiler.Jump Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
val) ->
ByteString -> Inst -> IO Inst
convert ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.Jump (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
convertInstruction ByteString
remainingFile Inst
inst (Compiler.JumpIfFalse Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
val) ->
ByteString -> Inst -> IO Inst
convert ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.JumpIfFalse (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
convertInstruction ByteString
remainingFile Inst
inst (Compiler.Def {}) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> ByteString -> Int32 -> Inst -> IO Inst
convertDefIntruction ByteString
remfile Int32
val Inst
inst
convertInstruction ByteString
remainingFile Inst
inst (Compiler.Fnv {}) =
ByteString -> Inst -> IO Inst
convert
((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Call =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Ret =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.Ret])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Add =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Add), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Sub =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Sub), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Mul =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Mul), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Div =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Div), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Mod =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Mod), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Eq =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Eq), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Less =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Less), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.LessEq =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.LessEq), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Great =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Great), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.GreatEq =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.GreatEq), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.And =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.And), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Or =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Or), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.XorB =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Xorb)])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Not =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Not), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.ToStr =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.ToString), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Apnd =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Append), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.RemAllOcc =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.RmOcc), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Get =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Get), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Len =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Len), Instruction
Vm.Call])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.PutArg =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.PutArg])
convertInstruction ByteString
remainingFile Inst
inst Instruction
Compiler.Neg =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile Inst
inst
convertInstruction ByteString
remainingFile Inst
inst (Compiler.PushList Int
_ [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> Inst -> IO Inst
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Right (ByteString
remfile, ByteOffset
_, Int32
lenList) ->
ByteString -> Inst -> IO Inst
convert ((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
lenList :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)
ByteString
remfile []) Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)])
convertInstruction ByteString
remainingFile Inst
inst Instruction
_ =
ByteString -> Inst -> IO Inst
convert ByteString
remainingFile Inst
inst
convertDefIntruction :: BIN.ByteString -> Int32 -> Inst -> IO Inst
convertDefIntruction :: ByteString -> Int32 -> Inst -> IO Inst
convertDefIntruction ByteString
remfile Int32
val Inst
inst =
ByteString -> Inst -> IO Inst
convert ((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue Int
nbInst ByteString
fileAfterNbInst []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue Int
nbInst ByteString
fileAfterNbInst []) Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [String -> Instruction
Vm.Define
((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int ) ByteString
remfile []))])
where
afterStr :: ByteString
afterStr = (String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)
ByteString
remfile [])
nbInst :: Int
nbInst = Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
-> Int
getNbInst (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
afterStr :: DcdStrInt)
fileAfterNbInst :: ByteString
fileAfterNbInst = Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
-> ByteString -> ByteString
getRemainingStrAfterInst
(ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
afterStr :: DcdStrInt) ByteString
afterStr
getString :: Int -> BIN.ByteString -> String -> (String, BIN.ByteString)
getString :: Int -> ByteString -> String -> (String, ByteString)
getString Int
0 ByteString
byteString String
str = (String
str, ByteString
byteString)
getString Int
nbytes ByteString
byteString String
s =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Char)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
byteString :: DcdStrChar) of
Right (ByteString
remainingFile, ByteOffset
_, Char
a) ->
Int -> ByteString -> String -> (String, ByteString)
getString (Int
nbytes Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile (String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
a])
Left (ByteString, ByteOffset, String)
_ -> (String
s, ByteString
byteString)
getFnv ::
Int ->
BIN.ByteString ->
[Vm.Instruction] ->
([Vm.Instruction], BIN.ByteString)
getFnv :: Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv Int
0 ByteString
byteString Inst
inst = (Inst
inst, ByteString
byteString)
getFnv (-1) ByteString
byteString Inst
inst = case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
byteString :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
nByteString, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv Int
0 ((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc
Int
nbinstruction ByteString
byteStringafterNbInst []) ) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [ Value -> Instruction
Vm.Push (Inst -> Int -> Value
Vm.Function
((Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc Int
nbinstruction ByteString
byteStringafterNbInst []))
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int))])
where
nbinstruction :: Int
nbinstruction = Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
-> Int
getNbInst (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
nByteString :: DcdStrInt)
byteStringafterNbInst :: ByteString
byteStringafterNbInst = Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
-> ByteString -> ByteString
getRemainingStrAfterInst
(ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
nByteString :: DcdStrInt) ByteString
nByteString
getFnv Int
_ ByteString
byteString Inst
inst = (Inst
inst, ByteString
byteString)
getNbInst :: DcdStrInt -> Int
getNbInst :: Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
-> Int
getNbInst (Left (ByteString, ByteOffset, String)
_) = Int
0
getNbInst (Right (ByteString
_, ByteOffset
_, Int32
value)) = Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
value :: Int32) :: Int
getRemainingStrAfterInst :: DcdStrInt -> BIN.ByteString -> BIN.ByteString
getRemainingStrAfterInst :: Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
-> ByteString -> ByteString
getRemainingStrAfterInst (Left (ByteString, ByteOffset, String)
_) ByteString
nByteString = ByteString
nByteString
getRemainingStrAfterInst (Right (ByteString
afterNbInst, ByteOffset
_, Int32
_)) ByteString
_ = ByteString
afterNbInst
getArg :: Int -> BIN.ByteString -> [Vm.Instruction] ->
([Vm.Instruction], BIN.ByteString)
getArg :: Int -> ByteString -> Inst -> (Inst, ByteString)
getArg Int
0 ByteString
byteString Inst
inst = (Inst
inst, ByteString
byteString)
getArg Int
nbInstruction ByteString
byteString Inst
inst =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
byteString :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remainingFile, ByteOffset
_, Word8
opcode) ->
Int
-> ByteString
-> ByteString
-> Inst
-> Instruction
-> (Inst, ByteString)
getArgFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst
(Int -> Instruction
forall a. Enum a => Int -> a
toEnum (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
opcode))
getArgFromInstruction :: Int -> BIN.ByteString -> BIN.ByteString ->
[Vm.Instruction] ->
Compiler.Instruction -> ([Vm.Instruction], BIN.ByteString)
getArgFromInstruction :: Int
-> ByteString
-> ByteString
-> Inst
-> Instruction
-> (Inst, ByteString)
getArgFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst (PushI Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Int -> Value
IntVal
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int))])
getArgFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst (PushB Bool
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Word8
1) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
True)])
Right (ByteString
remfile, ByteOffset
_, Word8
0) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
False)])
Right (ByteString
_, ByteOffset
_, Word8
_) -> (Inst
inst, ByteString
byteString)
getArgFromInstruction Int
nbInstruction ByteString
byteString
ByteString
remainingFile Inst
inst (Compiler.PushStr String
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int)
ByteString
remfile [])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (String -> Value
StringVal ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile [])))])
getArgFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst
(Compiler.PushSym String
_ Maybe [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int)
ByteString
remfile [])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [String -> Instruction
PushEnv ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))])
getArgFromInstruction Int
nbInstruction ByteString
byteString
ByteString
remainingFile Inst
inst (Compiler.PushList Int
_ [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
lenList) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int) ByteString
remfile [])
Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)])
getArgFromInstruction Int
nbInstruction ByteString
_ ByteString
remainingFile
Inst
inst (Compiler.PushArg Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushArg (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
getArgFromInstruction Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.PutArg =
Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.PutArg])
getArgFromInstruction Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst (Compiler.Fnv {}) =
Int -> ByteString -> Inst -> (Inst, ByteString)
getArg (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
getArgFromInstruction Int
_ ByteString
byteString ByteString
_ Inst
inst Instruction
_ =
(Inst
inst, ByteString
byteString)
getInstructionFunc :: Int -> BIN.ByteString -> [Vm.Instruction] ->
([Vm.Instruction], BIN.ByteString)
getInstructionFunc :: Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc Int
0 ByteString
byteString Inst
inst = (Inst
inst, ByteString
byteString)
getInstructionFunc Int
nbInstruction ByteString
byteString Inst
inst =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
byteString :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remainingFile, ByteOffset
_, Word8
opcode) ->
Int
-> ByteString
-> Inst
-> ByteString
-> Instruction
-> (Inst, ByteString)
getInstFnvFromInst Int
nbInstruction ByteString
byteString Inst
inst
ByteString
remainingFile (Int -> Instruction
forall a. Enum a => Int -> a
toEnum (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
opcode))
getInstFnvFromInst :: Int -> BIN.ByteString -> [Vm.Instruction] ->
BIN.ByteString -> Compiler.Instruction ->
([Vm.Instruction], BIN.ByteString)
getInstFnvFromInst :: Int
-> ByteString
-> Inst
-> ByteString
-> Instruction
-> (Inst, ByteString)
getInstFnvFromInst Int
nbInstruction ByteString
byteString Inst
inst ByteString
remainingFile (PushI Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Int -> Value
IntVal (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int))])
getInstFnvFromInst Int
nbInstruction ByteString
byteString Inst
inst ByteString
remainingFile (PushB Bool
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Word8
1) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
True)])
Right (ByteString
remfile, ByteOffset
_, Word8
0) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
False)])
Right (ByteString
_, ByteOffset
_, Word8
_) -> (Inst
inst, ByteString
byteString)
getInstFnvFromInst Int
nbInstruction ByteString
byteString Inst
inst
ByteString
remainingFile (Compiler.PushStr String
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int)
ByteString
remfile [])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (String -> Value
StringVal ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile [])))])
getInstFnvFromInst Int
nbInstruction ByteString
byteString Inst
inst
ByteString
remainingFile (Compiler.PushSym String
_ Maybe [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile
[])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [String -> Instruction
PushEnv ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile (Compiler.PushList Int
_ [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
lenList) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)
ByteString
remfile []) Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile (Compiler.PushArg Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushArg (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile (Compiler.Jump Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.Jump (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile (Compiler.JumpIfFalse Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.JumpIfFalse (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Add =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Add), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Sub =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Sub), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Mul =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Mul), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Div =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Div), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Mod =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Mod), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Eq =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Eq), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Less =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Less), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.LessEq =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.LessEq), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Great =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Great), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.GreatEq =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.GreatEq), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.And =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.And), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Or =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Or), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.XorB =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Xorb)])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Not =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Not), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.ToStr =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.ToString), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Apnd =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Append), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.RemAllOcc =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.RmOcc), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Get =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Get), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Len =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Len), Instruction
Vm.Call])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.PutArg =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.PutArg])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Ret =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.Ret])
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile (Compiler.Fnv {}) =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
getInstFnvFromInst Int
nbInstruction ByteString
_ Inst
inst ByteString
remainingFile Instruction
Compiler.Call =
Int -> ByteString -> Inst -> (Inst, ByteString)
getInstructionFunc (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.Call])
getInstFnvFromInst Int
_ ByteString
byteString Inst
inst ByteString
_ Instruction
_ = (Inst
inst, ByteString
byteString)
getDefinedValue :: Int -> BIN.ByteString ->
[Vm.Instruction] -> ([Vm.Instruction], BIN.ByteString)
getDefinedValue :: Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue Int
0 ByteString
byteString Inst
inst = (Inst
inst, ByteString
byteString)
getDefinedValue Int
nbInstruction ByteString
byteString Inst
inst =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
byteString :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remainingFile, ByteOffset
_, Word8
opcode) ->
Int
-> ByteString
-> ByteString
-> Inst
-> Instruction
-> (Inst, ByteString)
getDefValueFromInst Int
nbInstruction ByteString
byteString
ByteString
remainingFile Inst
inst (Int -> Instruction
forall a. Enum a => Int -> a
toEnum (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
opcode))
getDefValueFromInst :: Int ->
BIN.ByteString ->
BIN.ByteString ->
[Vm.Instruction] -> Compiler.Instruction ->
([Vm.Instruction], BIN.ByteString)
getDefValueFromInst :: Int
-> ByteString
-> ByteString
-> Inst
-> Instruction
-> (Inst, ByteString)
getDefValueFromInst Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst (PushI Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Int -> Value
IntVal (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int))])
getDefValueFromInst Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst (PushB Bool
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Word8
1) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
True)])
Right (ByteString
remfile, ByteOffset
_, Word8
0) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
False)])
Right (ByteString
_, ByteOffset
_, Word8
_) -> (Inst
inst, ByteString
byteString)
getDefValueFromInst Int
nbInstruction ByteString
byteString ByteString
remainingFile
Inst
inst (Compiler.PushStr String
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (String -> Value
StringVal ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
byteToRead :: Int32) :: Int) ByteString
remfile [])))])
getDefValueFromInst Int
nbInstruction ByteString
byteString ByteString
remainingFile
Inst
inst (Compiler.PushSym String
_ Maybe [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [String -> Instruction
PushEnv ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst
(Compiler.PushList Int
_ [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
lenList) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)
ByteString
remfile []) Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst (Compiler.PushArg Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushArg (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Add =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Add), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Sub =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Sub), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Mul =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Mul), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Div =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Div), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Mod =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Mod), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Eq =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Eq), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Less =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Less), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.LessEq =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.LessEq), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Great =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Great), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.GreatEq =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.GreatEq), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.And =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.And), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Or =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Or), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.XorB =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Xorb)])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Not =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Not), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.ToStr =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.ToString), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Apnd =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Append), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.RemAllOcc =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.RmOcc), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Get =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Get), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Len =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Operator -> Value
Op Operator
Vm.Len), Instruction
Vm.Call])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.PutArg =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.PutArg])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst Instruction
Compiler.Ret =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remainingFile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Instruction
Vm.Ret])
getDefValueFromInst Int
nbInstruction ByteString
_ ByteString
remainingFile Inst
inst (Compiler.Fnv {}) =
Int -> ByteString -> Inst -> (Inst, ByteString)
getDefinedValue (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getFnv (-Int
1) ByteString
remainingFile []))
getDefValueFromInst Int
_ ByteString
byteString ByteString
_ Inst
inst Instruction
_ = (Inst
inst, ByteString
byteString)
getList :: Int -> BIN.ByteString -> [Vm.Instruction] ->
([Vm.Instruction], BIN.ByteString)
getList :: Int -> ByteString -> Inst -> (Inst, ByteString)
getList Int
0 ByteString
byteString Inst
inst = (Inst
inst, ByteString
byteString)
getList Int
nbInstruction ByteString
byteString Inst
inst =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
byteString :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remainingFile, ByteOffset
_, Word8
opcode) ->
Int
-> ByteString
-> ByteString
-> Inst
-> Instruction
-> (Inst, ByteString)
getListFromInstruction Int
nbInstruction ByteString
byteString
ByteString
remainingFile Inst
inst (Int -> Instruction
forall a. Enum a => Int -> a
toEnum (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
opcode))
getListFromInstruction :: Int -> BIN.ByteString -> BIN.ByteString ->
[Vm.Instruction] -> Compiler.Instruction ->
([Vm.Instruction], BIN.ByteString)
getListFromInstruction :: Int
-> ByteString
-> ByteString
-> Inst
-> Instruction
-> (Inst, ByteString)
getListFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst (PushI Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Int -> Value
IntVal (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int))])
getListFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile Inst
inst (PushB Bool
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Word8)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrWord8) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Word8
1) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
True)])
Right (ByteString
remfile, ByteOffset
_, Word8
0) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
ByteString
remfile (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (Bool -> Value
BoolVal Bool
False)])
Right (ByteString
_, ByteOffset
_, Word8
_) -> (Inst
inst, ByteString
byteString)
getListFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile
Inst
inst (Compiler.PushStr String
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int)
ByteString
remfile [])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Value -> Instruction
Vm.Push (String -> Value
StringVal ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString
(Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int) ByteString
remfile [])))])
getListFromInstruction Int
nbInstruction ByteString
byteString ByteString
remainingFile
Inst
inst (Compiler.PushSym String
_ Maybe [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> (Inst
inst, ByteString
byteString)
Right (ByteString
remfile, ByteOffset
_, Int32
byteToRead) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((String, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
byteToRead :: Int32) :: Int)
ByteString
remfile [])) (Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [String -> Instruction
PushEnv ((String, ByteString) -> String
forall a b. (a, b) -> a
fst (Int -> ByteString -> String -> (String, ByteString)
getString (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Int32
byteToRead :: Int32) :: Int) ByteString
remfile []))])
getListFromInstruction Int
nbInstruction ByteString
_ ByteString
remainingFile
Inst
inst (Compiler.PushList Int
_ [[Instruction]]
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
lenList) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
((Inst, ByteString) -> ByteString
forall a b. (a, b) -> b
snd (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int) ByteString
remfile []))
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ (Inst, ByteString) -> Inst
forall a b. (a, b) -> a
fst (Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)
ByteString
remfile []) Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushList (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
lenList :: Int32) :: Int)])
getListFromInstruction Int
nbInstruction ByteString
_ ByteString
remainingFile
Inst
inst (Compiler.PushArg Int
_) =
case (ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, Int32)
forall a.
Binary a =>
ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
decodeOrFail ByteString
remainingFile :: DcdStrInt) of
Left (ByteString, ByteOffset, String)
_ -> ([], ByteString
remainingFile)
Right (ByteString
remfile, ByteOffset
_, Int32
val) -> Int -> ByteString -> Inst -> (Inst, ByteString)
getList (Int
nbInstruction Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ByteString
remfile
(Inst
inst Inst -> Inst -> Inst
forall a. [a] -> [a] -> [a]
++ [Int -> Instruction
Vm.PushArg (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
val :: Int32) :: Int)])
getListFromInstruction Int
_ ByteString
byteString ByteString
_ Inst
inst Instruction
_ = (Inst
inst, ByteString
byteString)