jitcraft/BytecodeCompiler.cpp
changeset 4 633176823669
parent 2 46fc53b8fd2f
child 6 172dd7799d0a
     1.1 --- a/jitcraft/BytecodeCompiler.cpp	Tue Jun 26 00:58:55 2012 -0700
     1.2 +++ b/jitcraft/BytecodeCompiler.cpp	Wed Jun 27 02:21:56 2012 -0700
     1.3 @@ -152,12 +152,22 @@
     1.4  }
     1.5  
     1.6  void
     1.7 +BytecodeCompiler::visitForALU(Type *needed, Expression *node)
     1.8 +{
     1.9 +    node->accept(this);
    1.10 +    if (needed->isFloat() && !node->type()->isFloat())
    1.11 +        __ cvt_i2f();
    1.12 +}
    1.13 +
    1.14 +void
    1.15  BytecodeCompiler::visit(BinaryExpression *node)
    1.16  {
    1.17 -    node->left()->accept(this);
    1.18 -    node->right()->accept(this);
    1.19 +    visitForALU(node->type(), node->left());
    1.20 +    visitForALU(node->type(), node->right());
    1.21  
    1.22      Opcode op = TokenToOpcode(node->token());
    1.23 +    if (node->type()->isFloat())
    1.24 +        op = (Opcode)(int(op) + (OP_ADD_F - OP_ADD));
    1.25      __ binary(op);
    1.26  }
    1.27  
    1.28 @@ -256,12 +266,18 @@
    1.29  }
    1.30  
    1.31  void
    1.32 -BytecodeCompiler::visit(IntegerLiteralExpression *node)
    1.33 +BytecodeCompiler::visit(IntegerLiteral *node)
    1.34  {
    1.35      __ int_(node->value());
    1.36  }
    1.37  
    1.38  void
    1.39 +BytecodeCompiler::visit(FloatLiteral *node)
    1.40 +{
    1.41 +    __ float_((float)node->value());
    1.42 +}
    1.43 +
    1.44 +void
    1.45  BytecodeCompiler::visit(VariableDeclaration *node)
    1.46  {
    1.47      Variable *var = node->variable();