65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
#include "src/tesseswebserver.hpp"
|
|
TESSESWEBSERVER_STATIC_DECLARATION
|
|
using namespace Tesses::WebServer;
|
|
using namespace Tesses::WebServer::ScriptEngine;
|
|
|
|
|
|
|
|
int main(int argc,char** argv)
|
|
{
|
|
RootEnvironment* rEnv = new RootEnvironment();
|
|
rEnv->print = [](ScriptType arg)-> void {
|
|
|
|
std::cout << ConvertToString(arg);
|
|
};
|
|
|
|
if(argc == 1)
|
|
{
|
|
printf("USAGE: %s myscript.twss <ARGS>\n",argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
List* ls = new List();
|
|
rEnv->SetValue("args",ObjectType(ls));
|
|
|
|
if(argc > 1)
|
|
{
|
|
for(int i = 1;i<argc;i++)
|
|
{
|
|
ls->items.push_back(std::string(argv[i]));
|
|
}
|
|
}
|
|
|
|
BytecodeCompiler bcc(ScriptParser::Parse(argv[1]));
|
|
|
|
bcc.Compile();
|
|
auto rf = bcc.file->rootFunction;
|
|
rf->env = rEnv;
|
|
rf->isRoot=true;
|
|
for(auto f : bcc.file->functions)
|
|
{
|
|
auto rf2 = f.second;
|
|
rf2->env = rEnv;
|
|
rf2->isRoot=false;
|
|
|
|
|
|
|
|
|
|
rEnv->SetValue(f.first,ObjectType(f.second));
|
|
}
|
|
|
|
auto res=rf->Execute(rEnv,{});
|
|
|
|
|
|
delete ls;
|
|
delete rEnv;
|
|
delete bcc.file;
|
|
|
|
|
|
if(std::holds_alternative<int64_t>(res))
|
|
{
|
|
return (int)std::get<int64_t>(res);
|
|
}
|
|
|
|
return 0;
|
|
} |