bytecode #3
@ -43,6 +43,7 @@ data Operation = Opiadd
|
||||
| Opreturn
|
||||
| Opireturn
|
||||
| Opareturn
|
||||
| Opdup_x1
|
||||
| Opinvokespecial Word16
|
||||
| Opgoto Word16
|
||||
| Opsipush Word16
|
||||
@ -111,6 +112,7 @@ opcodeEncodingLength Opaconst_null = 1
|
||||
opcodeEncodingLength Opreturn = 1
|
||||
opcodeEncodingLength Opireturn = 1
|
||||
opcodeEncodingLength Opareturn = 1
|
||||
opcodeEncodingLength Opdup_x1 = 1
|
||||
opcodeEncodingLength (Opinvokespecial _) = 3
|
||||
opcodeEncodingLength (Opgoto _) = 3
|
||||
opcodeEncodingLength (Opsipush _) = 3
|
||||
@ -162,6 +164,7 @@ instance Serializable Operation where
|
||||
serialize Opreturn = [0xB1]
|
||||
serialize Opireturn = [0xAC]
|
||||
serialize Opareturn = [0xB0]
|
||||
serialize Opdup_x1 = [0x5A]
|
||||
serialize (Opinvokespecial index) = 0xB7 : unpackWord16 index
|
||||
serialize (Opgoto index) = 0xA7 : unpackWord16 index
|
||||
serialize (Opsipush index) = 0x11 : unpackWord16 index
|
||||
|
@ -7,6 +7,7 @@ import Data.List
|
||||
import Data.Char
|
||||
import ByteCode.Generation.Builder.Field
|
||||
|
||||
|
||||
assembleExpression :: Assembler Expression
|
||||
assembleExpression (constants, ops, lvars) (TypedExpression _ (BinaryOperation op a b))
|
||||
| elem op [Addition, Subtraction, Multiplication, Division, BitwiseAnd, BitwiseOr, BitwiseXor] = let
|
||||
@ -97,7 +98,7 @@ assembleStatementExpression
|
||||
localIndex = findIndex ((==) name) lvars
|
||||
expr = (TypedExpression dtype (LocalVariable name))
|
||||
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
||||
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opdup]
|
||||
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opdup_x1]
|
||||
in case localIndex of
|
||||
Just index -> (exprConstants, incrOps ++ [Opistore (fromIntegral index)], lvars)
|
||||
Nothing -> error("No such local variable found in local variable pool: " ++ name)
|
||||
@ -119,7 +120,7 @@ assembleStatementExpression
|
||||
localIndex = findIndex ((==) name) lvars
|
||||
expr = (TypedExpression dtype (LocalVariable name))
|
||||
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
||||
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opisub]
|
||||
incrOps = exprOps ++ [Opsipush 1, Opisub, Opdup_x1]
|
||||
in case localIndex of
|
||||
Just index -> (exprConstants, incrOps ++ [Opistore (fromIntegral index)], lvars)
|
||||
Nothing -> error("No such local variable found in local variable pool: " ++ name)
|
||||
@ -141,7 +142,7 @@ assembleStatementExpression
|
||||
fieldIndex = findFieldIndex constants name
|
||||
expr = (TypedExpression dtype (FieldVariable name))
|
||||
(exprConstants, exprOps, _) = assembleExpression (constants, ops ++ [Opaload 0], lvars) expr
|
||||
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opdup]
|
||||
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opdup_x1]
|
||||
in case fieldIndex of
|
||||
Just index -> (exprConstants, incrOps ++ [Opputfield (fromIntegral index)], lvars)
|
||||
Nothing -> error("No such field variable found in field variable pool: " ++ name)
|
||||
@ -163,7 +164,7 @@ assembleStatementExpression
|
||||
fieldIndex = findFieldIndex constants name
|
||||
expr = (TypedExpression dtype (FieldVariable name))
|
||||
(exprConstants, exprOps, _) = assembleExpression (constants, ops ++ [Opaload 0], lvars) expr
|
||||
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opisub]
|
||||
incrOps = exprOps ++ [Opsipush 1, Opisub, Opdup_x1]
|
||||
in case fieldIndex of
|
||||
Just index -> (exprConstants, incrOps ++ [Opputfield (fromIntegral index)], lvars)
|
||||
Nothing -> error("No such field variable found in field variable pool: " ++ name)
|
||||
|
Loading…
Reference in New Issue
Block a user