enhanced compiler extenion system to support new instructions and functions with explicit references

This commit is contained in:
Marc Zinnschlag 2010-07-09 22:01:24 +02:00
parent 69e607e140
commit 71c710f9f6
4 changed files with 73 additions and 29 deletions

View file

@ -5,6 +5,7 @@
#include <stdexcept>
#include "generator.hpp"
#include "literals.hpp"
namespace Compiler
{
@ -44,7 +45,7 @@ namespace Compiler
}
void Extensions::registerFunction (const std::string& keyword, char returnType,
const std::string& argumentType, int segment5code)
const std::string& argumentType, int segment5code, int segment5codeExplicit)
{
assert (segment5code>=33554432 && segment5code<=67108863);
@ -56,12 +57,13 @@ namespace Compiler
function.mReturn = returnType;
function.mArguments = argumentType;
function.mCode = segment5code;
function.mCodeExplicit = segment5codeExplicit;
mFunctions.insert (std::make_pair (code, function));
}
void Extensions::registerInstruction (const std::string& keyword,
const std::string& argumentType, int segment5code)
const std::string& argumentType, int segment5code, int segment5codeExplicit)
{
assert (segment5code>=33554432 && segment5code<=67108863);
@ -72,23 +74,31 @@ namespace Compiler
Instruction instruction;
instruction.mArguments = argumentType;
instruction.mCode = segment5code;
instruction.mCodeExplicit = segment5codeExplicit;
mInstructions.insert (std::make_pair (code, instruction));
}
void Extensions::generateFunctionCode (int keyword, std::vector<Interpreter::Type_Code>& code)
const
void Extensions::generateFunctionCode (int keyword, std::vector<Interpreter::Type_Code>& code,
Literals& literals, const std::string& id) const
{
std::map<int, Function>::const_iterator iter = mFunctions.find (keyword);
if (iter==mFunctions.end())
throw std::logic_error ("unknown custom function keyword");
code.push_back (Generator::segment5 (iter->second.mCode));
if (!id.empty())
{
int index = literals.addString (id);
Generator::pushInt (code, literals, index);
}
code.push_back (Generator::segment5 (
id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
}
void Extensions::generateInstructionCode (int keyword,
std::vector<Interpreter::Type_Code>& code)
std::vector<Interpreter::Type_Code>& code, Literals& literals, const std::string& id)
const
{
std::map<int, Instruction>::const_iterator iter = mInstructions.find (keyword);
@ -96,6 +106,13 @@ namespace Compiler
if (iter==mInstructions.end())
throw std::logic_error ("unknown custom instruction keyword");
code.push_back (Generator::segment5 (iter->second.mCode));
if (!id.empty())
{
int index = literals.addString (id);
Generator::pushInt (code, literals, index);
}
code.push_back (Generator::segment5 (
id.empty() ? iter->second.mCode : iter->second.mCodeExplicit));
}
}