Skip to content

Commit

Permalink
Disambiguates subtype fill functions
Browse files Browse the repository at this point in the history
Issue: #17
  • Loading branch information
0x7CFE committed May 31, 2016
1 parent e189b20 commit 3f80561
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions include/inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class Type {

const TSubTypes& getSubTypes() const { return m_subTypes; }

void addSubType(const Type& type, bool compact = true) {
if (!compact || std::find(m_subTypes.begin(), m_subTypes.end(), type) == m_subTypes.end())
void pushSubType(const Type& type) { m_subTypes.push_back(type); }

void addSubType(const Type& type) {
if (std::find(m_subTypes.begin(), m_subTypes.end(), type) == m_subTypes.end())
m_subTypes.push_back(type);
}

Expand Down
16 changes: 8 additions & 8 deletions src/TypeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ void TypeAnalyzer::doSendBinary(const InstructionNode& instruction) {
TSymbol* const selector = globals.binaryMessages[opcode]->cast<TSymbol>();

Type arguments(Type::tkArray);
arguments.addSubType(lhsType, false);
arguments.addSubType(rhsType, false);
arguments.pushSubType(lhsType);
arguments.pushSubType(rhsType);

if (InferContext* const context = m_system.inferMessage(selector, arguments))
result = context->getReturnType();
Expand All @@ -315,7 +315,7 @@ void TypeAnalyzer::doMarkArguments(const InstructionNode& instruction) {

for (std::size_t index = 0; index < instruction.getArgumentsCount(); index++) {
const Type& argument = m_context[*instruction.getArgument(index)];
result.addSubType(argument, false);
result.pushSubType(argument);
}

result.set(globals.arrayClass, Type::tkArray);
Expand Down Expand Up @@ -354,9 +354,9 @@ void TypeAnalyzer::doPushBlock(const InstructionNode& instruction) {
Type& blockType = m_context[instruction];

blockType.set(globals.blockClass, Type::tkMonotype);
blockType.addSubType(origin, false);
blockType.addSubType(Type(TInteger(offset)), false);
blockType.addSubType(Type(TInteger(argIndex)), false);
blockType.pushSubType(origin);
blockType.pushSubType(Type(TInteger(offset)));
blockType.pushSubType(Type(TInteger(argIndex)));
}
}

Expand Down Expand Up @@ -470,10 +470,10 @@ void TypeAnalyzer::doPrimitive(const InstructionNode& instruction) {
const Type& arg = m_context[*instruction.getArgument(1)];

Type arguments(Type::tkArray);
arguments.addSubType(arg);
arguments.pushSubType(arg);

if (instruction.getArgumentsCount() == 3)
arguments.addSubType(m_context[*instruction.getArgument(2)], false);
arguments.pushSubType(m_context[*instruction.getArgument(2)]);

if (InferContext* invokeContext = m_system.inferBlock(block, arguments))
primitiveResult = invokeContext->getReturnType();
Expand Down

0 comments on commit 3f80561

Please sign in to comment.