From c77a6169c7c100e4ee139c98250696861067fc31 Mon Sep 17 00:00:00 2001 From: Dmitry Kashitsyn Date: Tue, 24 May 2016 00:15:19 +0600 Subject: [PATCH] Adds temporary solution for several SmallInt primitives This code need to be refactored properly. In case if both operands are literal, then result may be defined as literal too. Otherwise primitive should "fail" by allowing control flow to pass further. For literal calculation it is best to use existing code for software VM. Issue: #17 --- src/TypeAnalyzer.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/TypeAnalyzer.cpp b/src/TypeAnalyzer.cpp index ea73421..7131434 100644 --- a/src/TypeAnalyzer.cpp +++ b/src/TypeAnalyzer.cpp @@ -421,7 +421,10 @@ void TypeAnalyzer::doPrimitive(const InstructionNode& instruction) { break; } - case primitive::smallIntSub: { + case primitive::smallIntSub: + case primitive::smallIntDiv: + case primitive::smallIntMod: + { const Type& self = m_context[*instruction.getArgument(0)]; const Type& arg = m_context[*instruction.getArgument(1)]; @@ -429,10 +432,14 @@ void TypeAnalyzer::doPrimitive(const InstructionNode& instruction) { const int lhs = TInteger(self.getValue()).getValue(); const int rhs = TInteger(arg.getValue()).getValue(); - primitiveResult = Type(TInteger(lhs - rhs)); + switch (opcode) { + case primitive::smallIntSub: primitiveResult = Type(TInteger(lhs - rhs)); break; + case primitive::smallIntDiv: primitiveResult = Type(TInteger(lhs / rhs)); break; + case primitive::smallIntMod: primitiveResult = Type(TInteger(lhs % rhs)); break; + } } else { // TODO Check for (SmallInt) - primitiveResult = Type(); + primitiveResult = Type(globals.smallIntClass, Type::tkMonotype); } break;