-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
454 additions
and
890 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
#include "LessThanFunction.h" | ||
#include "bytecode/instructions/LessThan.h" | ||
#include "bytecode/instructions/LessThanRI.h" | ||
#include "bytecode/instructions/LoadLiteral.h" | ||
#include "exceptions/SyntaxError.h" | ||
|
||
namespace Bytecode::BuiltinFunctions { | ||
void LessThan::compile( | ||
const std::vector<SyntaxTreeNode *> &args, | ||
Program &program, | ||
std::vector<Instruction *> &instructions, | ||
Segment *segment) { | ||
Segment *segment) { | ||
if (args.empty()) { | ||
throw SyntaxError("Invalid number of arguments for function \"<\", Expected at least 1, got 0"); | ||
} | ||
if (args.size() == 1) { | ||
instructions.push_back(new LoadLiteral(new StackObject(true))); | ||
instructions.push_back(new (Instruction){ | ||
Instruction::LoadLiteral, | ||
{.i_param = {StackObject(true)}}, | ||
}); | ||
return; | ||
} | ||
if (args[0]->type == SyntaxTreeNode::TokenNode && | ||
args[1]->type == SyntaxTreeNode::TokenNode && | ||
segment->find_variable(((TokenNode *) args[0])->getName()) != -1) { | ||
if (((TokenNode *) args[0])->token.type == Token::Symbol && | ||
((TokenNode *) args[1])->token.type == Token::Number) { | ||
instructions.push_back( | ||
new Bytecode::LessThanRI( | ||
segment->find_variable(((TokenNode *) args[0])->getName()), | ||
((TokenNode *) args[1])->token.asNumber())); | ||
instructions.push_back(new (Instruction){ | ||
Instruction::LessThanRI, | ||
{.ri_params = { | ||
segment->find_variable(((TokenNode *) args[0])->getName()), | ||
StackObject(((TokenNode *) args[1])->token)}}, | ||
}); | ||
return; | ||
} | ||
} | ||
|
||
args[0]->compile(segment, program, instructions); | ||
args[1]->compile(segment, program, instructions); | ||
instructions.push_back(new Bytecode::LessThan()); | ||
instructions.push_back(new (Instruction){Instruction::LessThan}); | ||
for (int i = 2; i < args.size(); i++) { | ||
args[i]->compile(segment, program, instructions); | ||
instructions.push_back(new Bytecode::LessThan()); | ||
instructions.push_back(new (Instruction){Instruction::LessThan}); | ||
} | ||
} | ||
} | ||
}// namespace Bytecode::BuiltinFunctions |
Oops, something went wrong.