mirror of https://github.com/kiwix/libkiwix.git
+ ctpp2 integration continues... it starts to work
This commit is contained in:
parent
cebae645e6
commit
fb570a6a9d
|
@ -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) {
|
||||||
|
|
||||||
|
const STLW::string & sSourceFile = "/tmp/hello.tmpl";
|
||||||
|
VMOpcodeCollector oVMOpcodeCollector;
|
||||||
|
StaticText oSyscalls;
|
||||||
|
StaticData oStaticData;
|
||||||
|
StaticText oStaticText;
|
||||||
|
HashTable oHashTable;
|
||||||
|
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
|
||||||
|
|
||||||
|
// Load template
|
||||||
|
CTPP2FileSourceLoader oSourceLoader;
|
||||||
|
oSourceLoader.LoadTemplate(sSourceFile.c_str());
|
||||||
|
|
||||||
|
// Create template parser
|
||||||
|
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, sSourceFile);
|
||||||
|
|
||||||
|
// Compile template
|
||||||
|
oCTPP2Parser.Compile();
|
||||||
|
|
||||||
VMOpcodeCollector oVMOpcodeCollector;
|
// Get program core
|
||||||
StaticText oSyscalls;
|
UINT_32 iCodeSize = 0;
|
||||||
StaticData oStaticData;
|
const VMInstruction * oVMInstruction = oVMOpcodeCollector.GetCode(iCodeSize);
|
||||||
StaticText oStaticText;
|
|
||||||
HashTable oHashTable;
|
|
||||||
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
|
|
||||||
|
|
||||||
try
|
// Dump program
|
||||||
{
|
VMDumper oDumper(iCodeSize, oVMInstruction, oSyscalls, oStaticData, oStaticText, oHashTable);
|
||||||
// Load template
|
UINT_32 iSize = 0;
|
||||||
CTPP2FileSourceLoader oSourceLoader;
|
const VMExecutable * aProgramCore = oDumper.GetExecutable(iSize);
|
||||||
oSourceLoader.LoadTemplate(search.c_str());
|
|
||||||
|
|
||||||
// Create template parser
|
// Memory core
|
||||||
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, search.c_str());
|
const VMMemoryCore vm_core(aProgramCore);
|
||||||
|
|
||||||
// Compile template
|
// Initiate the VM
|
||||||
oCTPP2Parser.Compile();
|
SyscallFactory oSyscallFactory(100);
|
||||||
}
|
// Load standard library
|
||||||
catch(...)
|
STDLibInitializer::InitLibrary(oSyscallFactory);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue