/* Microsoft stdext::hash_map */ #define __HASH_MAP_MSVC__ 1 /* google::dense_hash_map and google::sparse_hash_map */ #define __HASH_MAP_GOOGLE__ 2 /* The used hashing handler */ #define __USE_HASH_MAP__ __HASH_MAP_GOOGLE__ #undef BIGGEST_FIELD_ALIGNMENT #define BIGGEST_FIELD_ALIGNMENT 4 #include #include #include #include #include #include #include #include #include #ifdef UNIX #define DLLEXPORT(f) f #else #define DLLEXPORT(f) __declspec(dllexport) f #endif #include extern "C" DLLEXPORT(void) RInitTolKernel(void); ////////////////////////////////////////////////////////////////////////////// extern BList R_stack; void R_concat(BList* head, BList* tail); BList R_stack; //---------------------------------------------------------------------------- void R_concat(BList* head, BList* tail) //---------------------------------------------------------------------------- { if (head->Cdr()) { R_concat(head->Cdr(), tail); } else { head->PutCdr(tail); } } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTolCompile(char **name, int *ok) //---------------------------------------------------------------------------- { if(TOLHasBeenInitialized()==0) RInitTolKernel(); char* str_lvalue = (char*)*name; BSyntaxObject * so = GraAnything()->EvaluateExpr(str_lvalue); if (so) { BList* result = NIL; BList* aux = NIL; LstFastAppend(result, aux, so); R_concat(&R_stack, result); *ok = 1; } else { *ok = 0; } } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTolDecompile(char **name) //---------------------------------------------------------------------------- { char* str_name = (char*)*name; BList *P = R_stack.Cdr(), *prev = &R_stack; short found = 0; while (!found && P) { BSyntaxObject * so = (BSyntaxObject*)(P->Car()); const char* object_name = so->Name().String(); if (!strcmp(object_name, str_name)) { prev->PutCdr(P->Cdr()); delete P; DESTROY(so); found = 1; break; } prev = P; P = P->Cdr(); } } ////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTOLVersion(char **version) //---------------------------------------------------------------------------- { *version = (char*)TOLVersion(); } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTOLHasBeenInitialized(int *initialized) //---------------------------------------------------------------------------- { *initialized = TOLHasBeenInitialized(); } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RInitTolKernel(void) //---------------------------------------------------------------------------- { InitTolKernel(NULL, 0, "vA"); LoadInitLibrary(true, true); } ////////////////////////////////////////////////////////////////////////////// //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTolGetReal(char **name, double *value) //---------------------------------------------------------------------------- { if(TOLHasBeenInitialized()==0) RInitTolKernel(); char* str_lvalue = (char*)*name; BSyntaxObject * so = GraReal()->EvaluateExpr(str_lvalue); if (so) { BDat & d = Dat(so); *value = d.Value(); DESTROY(so); } else { error("Real expression '%s' is not valid", str_lvalue); } } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTolGetText(char **name, char **value) //---------------------------------------------------------------------------- { if(TOLHasBeenInitialized()==0) RInitTolKernel(); char* str_lvalue = (char*)*name; BSyntaxObject * so = GraText()->EvaluateExpr(str_lvalue); if (so) { BText & d = Text(so); *value = (char *)(d.String()); DESTROY(so); } else { error("Text expression '%s' is not valid", str_lvalue); } } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTolGetDate(char **name, double *value) //---------------------------------------------------------------------------- { if(TOLHasBeenInitialized()==0) RInitTolKernel(); char* str_lvalue = (char*)*name; BSyntaxObject * so = GraDate()->EvaluateExpr(str_lvalue); if (so) { BDate & d = Date(so); *value = (double)(d.Index()); DESTROY(so); } else { error("Date expression '%s' is not valid", str_lvalue); } } //---------------------------------------------------------------------------- extern "C" DLLEXPORT(void) RTolGetMatrix(char **name, double *value) //---------------------------------------------------------------------------- { if(TOLHasBeenInitialized()==0) RInitTolKernel(); char* str_lvalue = (char*)*name; BSyntaxObject * so = GraMatrix()->EvaluateExpr(str_lvalue); if (so) { BMat & m = Mat(so); int cols = m.Columns(); int rows = m.Rows(); for (int c=0; c