Skip to content

Commit

Permalink
Adds temporary solution for several SmallInt primitives
Browse files Browse the repository at this point in the history
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
  • Loading branch information
0x7CFE committed May 23, 2016
1 parent c50da97 commit c77a616
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/TypeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,25 @@ 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)];

if (isSmallInteger(self.getValue()) && isSmallInteger(arg.getValue())) {
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;
Expand Down

0 comments on commit c77a616

Please sign in to comment.