|
|
|
@ -21,15 +21,20 @@ assembleExpression (constants, ops, lvars) (TypedExpression _ (BinaryOperation o
|
|
|
|
|
cmp_ops = [cmp_op, Opsipush 0, Opgoto 6, Opsipush 1]
|
|
|
|
|
in
|
|
|
|
|
(bConstants, bOps ++ cmp_ops, lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression _ (CharacterLiteral literal)) =
|
|
|
|
|
(constants, ops ++ [Opsipush (fromIntegral (ord literal))], lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression _ (BooleanLiteral literal)) =
|
|
|
|
|
(constants, ops ++ [Opsipush (if literal then 1 else 0)], lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression _ (IntegerLiteral literal))
|
|
|
|
|
| literal <= 32767 && literal >= -32768 = (constants, ops ++ [Opsipush (fromIntegral literal)], lvars)
|
|
|
|
|
| otherwise = (constants ++ [IntegerInfo (fromIntegral literal)], ops ++ [Opldc_w (fromIntegral (1 + length constants))], lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression _ NullLiteral) =
|
|
|
|
|
(constants, ops ++ [Opaconst_null], lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression etype (UnaryOperation Not expr)) = let
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
|
|
|
|
newConstant = fromIntegral (1 + length exprConstants)
|
|
|
|
@ -37,19 +42,112 @@ assembleExpression (constants, ops, lvars) (TypedExpression etype (UnaryOperatio
|
|
|
|
|
"int" -> (exprConstants ++ [IntegerInfo 0x7FFFFFFF], exprOps ++ [Opldc_w newConstant, Opixor], lvars)
|
|
|
|
|
"char" -> (exprConstants, exprOps ++ [Opsipush 0xFFFF, Opixor], lvars)
|
|
|
|
|
"boolean" -> (exprConstants, exprOps ++ [Opsipush 0x01, Opixor], lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression _ (UnaryOperation Minus expr)) = let
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
|
|
|
|
in
|
|
|
|
|
(exprConstants, exprOps ++ [Opineg], lvars)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PreIncrement (TypedExpression dtype (LocalVariable name)))) = let
|
|
|
|
|
localIndex = findIndex ((==) name) lvars
|
|
|
|
|
expr = (TypedExpression dtype (LocalVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opdup]
|
|
|
|
|
in case localIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opistore (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such local variable found in local variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PostIncrement (TypedExpression dtype (LocalVariable name)))) = let
|
|
|
|
|
localIndex = findIndex ((==) name) lvars
|
|
|
|
|
expr = (TypedExpression dtype (LocalVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opdup, Opsipush 1, Opiadd]
|
|
|
|
|
in case localIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opistore (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such local variable found in local variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PreDecrement (TypedExpression dtype (LocalVariable name)))) = let
|
|
|
|
|
localIndex = findIndex ((==) name) lvars
|
|
|
|
|
expr = (TypedExpression dtype (LocalVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opisub]
|
|
|
|
|
in case localIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opistore (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such local variable found in local variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PostDecrement (TypedExpression dtype (LocalVariable name)))) = let
|
|
|
|
|
localIndex = findIndex ((==) name) lvars
|
|
|
|
|
expr = (TypedExpression dtype (LocalVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops, lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opdup, Opsipush 1, Opisub]
|
|
|
|
|
in case localIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opistore (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such local variable found in local variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PreIncrement (TypedExpression dtype (FieldVariable name)))) = let
|
|
|
|
|
fieldIndex = findFieldIndex constants name
|
|
|
|
|
expr = (TypedExpression dtype (FieldVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops ++ [Opaload 0], lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opdup]
|
|
|
|
|
in case fieldIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opputfield (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such field variable found in field variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PostIncrement (TypedExpression dtype (FieldVariable name)))) = let
|
|
|
|
|
fieldIndex = findFieldIndex constants name
|
|
|
|
|
expr = (TypedExpression dtype (FieldVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops ++ [Opaload 0], lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opdup, Opsipush 1, Opiadd]
|
|
|
|
|
in case fieldIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opputfield (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such field variable found in field variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PreDecrement (TypedExpression dtype (FieldVariable name)))) = let
|
|
|
|
|
fieldIndex = findFieldIndex constants name
|
|
|
|
|
expr = (TypedExpression dtype (FieldVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops ++ [Opaload 0], lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opsipush 1, Opiadd, Opisub]
|
|
|
|
|
in case fieldIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opputfield (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such field variable found in field variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression
|
|
|
|
|
(constants, ops, lvars)
|
|
|
|
|
(TypedExpression _ (UnaryOperation PostDecrement (TypedExpression dtype (FieldVariable name)))) = let
|
|
|
|
|
fieldIndex = findFieldIndex constants name
|
|
|
|
|
expr = (TypedExpression dtype (FieldVariable name))
|
|
|
|
|
(exprConstants, exprOps, _) = assembleExpression (constants, ops ++ [Opaload 0], lvars) expr
|
|
|
|
|
incrOps = exprOps ++ [Opdup, Opsipush 1, Opisub]
|
|
|
|
|
in case fieldIndex of
|
|
|
|
|
Just index -> (exprConstants, incrOps ++ [Opputfield (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error("No such field variable found in field variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression _ (FieldVariable name)) = let
|
|
|
|
|
fieldIndex = findFieldIndex constants name
|
|
|
|
|
in case fieldIndex of
|
|
|
|
|
Just index -> (constants, ops ++ [Opaload 0, Opgetfield (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error ("No such field found in constant pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression (constants, ops, lvars) (TypedExpression dtype (LocalVariable name)) = let
|
|
|
|
|
localIndex = findIndex ((==) name) lvars
|
|
|
|
|
isPrimitive = elem dtype ["char", "boolean", "int"]
|
|
|
|
|
in case localIndex of
|
|
|
|
|
Just index -> (constants, ops ++ if isPrimitive then [Opiload (fromIntegral index)] else [Opaload (fromIntegral index)], lvars)
|
|
|
|
|
Nothing -> error ("No such local variable found in local variable pool: " ++ name)
|
|
|
|
|
|
|
|
|
|
assembleExpression _ expr = error ("unimplemented: " ++ show expr)
|
|
|
|
|