+ ctpp2 integration continues... it starts to work

This commit is contained in:
kelson42 2011-03-15 20:59:59 +00:00
parent cebae645e6
commit fb570a6a9d
2 changed files with 55 additions and 21 deletions

View File

@ -73,32 +73,61 @@ namespace kiwix {
} }
const string Searcher::searchInIndexAndReturnHtml(string &search, const unsigned int resultsCount, const string Searcher::searchInIndexAndReturnHtml(string &search, const unsigned int resultsCount,
const string templatePath, const bool verbose) { const string templatePath, const bool verbose) {
VMOpcodeCollector oVMOpcodeCollector; const STLW::string & sSourceFile = "/tmp/hello.tmpl";
StaticText oSyscalls; VMOpcodeCollector oVMOpcodeCollector;
StaticData oStaticData; StaticText oSyscalls;
StaticText oStaticText; StaticData oStaticData;
HashTable oHashTable; StaticText oStaticText;
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable); HashTable oHashTable;
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
try // Load template
{ CTPP2FileSourceLoader oSourceLoader;
// Load template oSourceLoader.LoadTemplate(sSourceFile.c_str());
CTPP2FileSourceLoader oSourceLoader;
oSourceLoader.LoadTemplate(search.c_str());
// Create template parser // Create template parser
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, search.c_str()); CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, sSourceFile);
// Compile template // Compile template
oCTPP2Parser.Compile(); oCTPP2Parser.Compile();
}
catch(...)
{
}
return ""; // Get program core
UINT_32 iCodeSize = 0;
const VMInstruction * oVMInstruction = oVMOpcodeCollector.GetCode(iCodeSize);
// Dump program
VMDumper oDumper(iCodeSize, oVMInstruction, oSyscalls, oStaticData, oStaticText, oHashTable);
UINT_32 iSize = 0;
const VMExecutable * aProgramCore = oDumper.GetExecutable(iSize);
// Memory core
const VMMemoryCore vm_core(aProgramCore);
// Initiate the VM
SyscallFactory oSyscallFactory(100);
// Load standard library
STDLibInitializer::InitLibrary(oSyscallFactory);
VM * pVM = new VM(&oSyscallFactory);
// Initiate the logger
FileLogger oLogger(stderr);
// Fill data
CDT oData;
oData["hello"] = "Hello, World!";
STLW::string sResult;
StringOutputCollector oDataCollector(sResult);
// Run VM
pVM->Init(&vm_core, &oDataCollector, &oLogger);
UINT_32 iIP = 0;
pVM -> Run(&vm_core, &oDataCollector, iIP, oData, &oLogger);
return sResult;
} }
} }

View File

@ -36,6 +36,11 @@
#include <CTPP2HashTable.hpp> #include <CTPP2HashTable.hpp>
#include <CTPP2VMDumper.hpp> #include <CTPP2VMDumper.hpp>
#include <CTPP2VMOpcodes.h> #include <CTPP2VMOpcodes.h>
#include <CTPP2VM.hpp>
#include <CTPP2VMSTDLib.hpp>
#include <CTPP2StringOutputCollector.hpp>
#include <CTPP2SyscallFactory.hpp>
#include <CTPP2FileLogger.hpp>
using namespace std; using namespace std;
using namespace CTPP; using namespace CTPP;