00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034  
00035 
00036 
00037 
00038 
00039 
00040 
#ifndef VMatLanguage_INC
00041 
#define VMatLanguage_INC
00042 
00043 
#include "RowBufferedVMatrix.h"
00044 
#include "VMat.h"
00045 
#include <plearn/base/RealMapping.h>
00046 
00047 
00048 
namespace PLearn {
00049 
using namespace std;
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059   class VMatLanguage: 
public Object
00060   {
00061     typedef Object inherited;
00062 
00063     VMat vmsource;
00064     TVec<int> program; 
00065     TVec<RealMapping> mappings;
00066     mutable Vec pstack;
00067     mutable Vec myvec;
00068     mutable Vec mem;
00069 
00070     
00071     
static map<string, int> 
opcodes;
00072     
00074     
static void build_opcodes_map();
00075 
00076     
00077     
void generateCode(
const string& processed_sourcecode);
00078     
void generateCode(istream& processed_sourcecode);
00079 
00080     
00081     
00082     
void preprocess(istream& in, map<string, string>& defines, 
string& processed_sourcecode,
00083                            
vector<string>& fieldnames);
00084     
00085 
public:
00086     VMatLanguage():
vmsource(
Mat()) { 
build_(); }
00087     VMatLanguage(
VMat vmsrc):
vmsource(vmsrc) { 
build_(); }
00088 
00089     
PLEARN_DECLARE_OBJECT(
VMatLanguage);
00090     
static void declareOptions(
OptionList &ol);
00091 
00092     
virtual void build();
00093       
00096     
void run(
const Vec& srcvec, 
const Vec& result, 
int rowindex=-1) 
const;
00097 
00100     
void run(
int rowindex, 
const Vec& result) 
const;
00101 
00102     inline void setSource(
VMat the_source) 
00103     { 
00104       
vmsource = the_source;
00105       
00106       
program.
resize(0);
00107     }
00108 
00109     
00111 
00115     
void compileStream(istream &in, 
vector<string>& fieldnames);
00116     
void compileString(
const string & code, 
vector<string>& fieldnames);
00117     
void compileFile(
const string & filename, 
vector<string>& fieldnames);
00118     
00119     int pstackSize()
 const {
return pstack.
size();}
00120 
00121     
00122     
static bool output_preproc;
00123   
private:
00124       
void build_();
00125   };
00126 
00127 
DECLARE_OBJECT_PTR(VMatLanguage);
00128 
00129 
00130 
00131 
00132 
00133 
00134   class PreprocessingVMatrix: 
public RowBufferedVMatrix
00135   {
00136     typedef RowBufferedVMatrix inherited;
00137 
00138   
protected:
00139     VMat source;
00140     VMatLanguage program;
00141     Vec sourcevec;
00142     vector<string> fieldnames;    
00143 
00144   
public:
00145     PreprocessingVMatrix(){}
00146     
PreprocessingVMatrix(
VMat the_source, 
const string& program_string);
00147 
00148     
PLEARN_DECLARE_OBJECT(
PreprocessingVMatrix);
00149 
00150     
virtual void build();
00151 
00152   
protected:
00153 
00154     
virtual void getNewRow(
int i, 
const Vec& v) 
const;
00155     
static void declareOptions(
OptionList &ol);
00156 
00157   
private:
00158 
00159       
void build_();
00160   };
00161 
00162   
DECLARE_OBJECT_PTR(PreprocessingVMatrix);
00163 
00164   time_t 
getDateOfCode(
const string& codefile);
00165 
00166 } 
00167 
00168 
#endif
00169 
00170