#include <stdio.h>
-#include "bbtkInterpreter.h"
-#include "bbtkInterpreterPy.h"
#include "bbtkUtilities.h"
+#include "bbtkInterpreter.h"
+#include "bbtkInterpreterJavaScript.h"
+#include "bbtkInterpreterPython.h"
int main(int argc, char* argv[])
{
if (argc<3)
{
- printf("bbs2 <filename.bbs> <cxx|py>\n");
+ printf("bbs2 <filename.bbs> <cxx|py|js>\n");
return 1;
}
- std::string file,path;
+ std::string fileBase,file,path;
std::string extention( argv[2] );
- file = bbtk::Utilities::ExtractScriptName(argv[1],path);
- file += std::string(".")+extention;
+ fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path);
+ file = fileBase + std::string(".") + extention;
if ( extention.compare("cxx")==0)
{
if ( extention.compare("py")==0)
{
printf("bbs -> py\n");
- bbtk::InterpreterPy::Pointer I = bbtk::InterpreterPy::New();
+ bbtk::InterpreterPython::Pointer I = bbtk::InterpreterPython::New();
I->SetThrow(true);
try
{
I->InterpretFile(argv[1]);
- std::vector<std::string> pythonBBTK= ((bbtk::InterpreterPy*)(I.get()))->pythonBBTK ;
+ std::vector<std::string> pythonBBTK= ((bbtk::InterpreterPython*)(I.get()))->pythonBBTK ;
FILE *ff=fopen(file.c_str(),"w+");
fprintf(ff,"from bbtk.bbtkBlackBox import *\n" );
- fprintf(ff,"class appliTest02:\n" );
+ fprintf(ff,"class %s:\n",fileBase.c_str() );
fprintf(ff," def Run(self):\n" );
- fprintf(ff," mCB = ComplexBlackBox('appliTest02')\n");
+ fprintf(ff," mCBpy = ComplexBlackBox('%s')\n",fileBase.c_str());
int i,size=pythonBBTK.size();
for (i=0; i<size;i++)
{
- fprintf(ff," mCB.%s\n", pythonBBTK[i].c_str() );
+ fprintf(ff," mCBpy.%s\n", pythonBBTK[i].c_str() );
}// for i
- fprintf(ff," mCB.Execute()\n" );
+ fprintf(ff," mCBpy.Execute()\n" );
fclose(ff);
} catch (bbtk::Exception e) {
e.Print();
} // try
- } // py
+ } // if py
+
+ if ( extention.compare("js")==0)
+ {
+ printf("bbs -> js\n");
+ bbtk::InterpreterJavaScript::Pointer I = bbtk::InterpreterJavaScript::New();
+ I->SetThrow(true);
+ try
+ {
+ I->InterpretFile(argv[1]);
+ std::vector<std::string> javascriptBBTK= ((bbtk::InterpreterJavaScript*)(I.get()))->javascriptBBTK ;
+ FILE *ff=fopen(file.c_str(),"w+");
+ fprintf(ff,"import * as bbtk from './bbtk.js' \n" );
+ fprintf(ff,"export class %s{\n",fileBase.c_str() );
+ fprintf(ff," Run(){\n" );
+ fprintf(ff," let mCBjs = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str());
+ int i,size=javascriptBBTK.size();
+ for (i=0; i<size;i++)
+ {
+ fprintf(ff," mCBjs.%s\n", javascriptBBTK[i].c_str() );
+ }// for i
+ fprintf(ff," mCBjs.Execute()\n" );
+ fprintf(ff," } \n" );
+ fprintf(ff,"} \n" );
+ fclose(ff);
+ } catch (bbtk::Exception e) {
+ e.Print();
+ } // try
+ } // if js
return 0;
}