Add single file runtime binaries

This commit is contained in:
2026-02-25 23:36:42 -06:00
parent 5be9d96b54
commit 572c0ab468
29 changed files with 898 additions and 235 deletions

View File

@@ -1,72 +0,0 @@
#include "CrossLang.hpp"
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc < 2)
{
printf("USAGE: %s <filename.crvm> <args...>\n",argv[0]);
return 1;
}
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
env->LoadFileWithDependencies(&gc, Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[1]));
if(env->HasVariable("WebAppMain"))
{
Args args(argc, argv);
int port = 4206;
for(auto& item : args.options)
{
if(item.first == "port")
{
port = std::stoi(item.second);
}
}
env->EnsureDictionary(&gc,"Net")->SetValue("WebServerPort", (int64_t)port);
TList* args2 = TList::Create(ls);
for(auto& item : args.positional)
{
args2->Add(item);
}
auto res = env->CallFunctionWithFatalError(ls, "WebAppMain", {args2});
auto svr2 = Tesses::CrossLang::ToHttpServer(&gc,res);
if(svr2 == nullptr) return 1;
Tesses::Framework::Http::HttpServer svr(port,svr2);
svr.StartAccepting();
TF_RunEventLoop();
TDictionary* _dict;
TClassObject* _co;
if(GetObjectHeap(res,_dict))
{
_dict->CallMethod(ls,"Close",{});
}
if(GetObjectHeap(res,_co))
{
_co->CallMethod(ls,"","Close",{});
}
TF_Quit();
}
else {
TList* args = TList::Create(ls);
for(int arg=1;arg<argc;arg++)
args->Add(std::string(argv[arg]));
auto res = env->CallFunctionWithFatalError(ls,"main",{args});
int64_t iresult;
if(GetObject(res,iresult))
return (int)iresult;
}
return 0;
}

View File

@@ -1,11 +1,11 @@
#include "CrossLang.hpp"
#include <iostream>
using namespace Tesses::CrossLang;
namespace Tesses::CrossLang::Programs {
using namespace Tesses::Framework::Filesystem;
using namespace Tesses::Framework::Streams;
void Help(const char* filename)
static void Help(std::string& filename)
{
printf("USAGE: %s [OPTIONS] <dirasroot> <archive.crvm>\n", filename);
std::cout << "USAGE: " << filename << " [OPTIONS] <dirasroot> <archive.crvm>" << std::endl;
printf("OPTIONS:\n");
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": \"https://example.com/\", \"homepage\": \"https://example.com/\",\"license\":\"MIT\"})\n");
printf(" -I: Set icon name (relative to dirasroot), should be a 128x128 png\n");
@@ -15,7 +15,8 @@ void Help(const char* filename)
printf("Options except for help have flag with arg like this: -F ARG\n");
exit(1);
}
int main(int argc, char** argv)
int64_t CrossArchiveCreate(std::vector<std::string>& argv)
{
Tesses::Framework::TF_Init();
std::string name="out";
@@ -23,40 +24,40 @@ int main(int argc, char** argv)
TVMVersion version;
std::string icon="";
std::vector<std::string> args;
for(int i = 1; i < argc; i++)
for(int i = 1; i < argv.size(); i++)
{
if(strcmp(argv[i],"--help") == 0 || strcmp(argv[i],"-h")==0)
if(argv[i] == "--help" || argv[i] == "-h")
{
Help(argv[0]);
}
else if(strcmp(argv[i], "-i") == 0)
else if(argv[i] == "-i")
{
i++;
if(i < argc)
if(i < argv.size())
{
info = argv[i];
}
}
else if(strcmp(argv[i], "-I") == 0)
else if(argv[i] == "-I")
{
i++;
if(i < argc)
if(i < argv.size())
{
icon = argv[i];
}
}
else if(strcmp(argv[i], "-n") == 0)
else if(argv[i] == "-n")
{
i++;
if(i < argc)
if(i < argv.size())
{
name = argv[i];
}
}
else if(strcmp(argv[i], "-v") == 0)
else if(argv[i] == "-v")
{
i++;
if(i < argc)
if(i < argv.size())
{
if(!TVMVersion::TryParse(argv[i],version))
@@ -90,4 +91,5 @@ int main(int argc, char** argv)
CrossArchiveCreate(sdfs,strm,name,version,info,icon);
return 0;
}
}

View File

@@ -1,34 +1,34 @@
#include "CrossLang.hpp"
#include <iostream>
using namespace Tesses::CrossLang;
namespace Tesses::CrossLang::Programs {
using namespace Tesses::Framework::Filesystem;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
int64_t CrossArchiveExtract(std::vector<std::string>& argv)
{
Tesses::Framework::TF_Init();
if(argc < 3)
if(argv.size() < 3)
{
printf("USAGE: %s <archive.crvm> <dirasroot>\n", argv[0]);
std::cout << "USAGE: " << argv[0] << " <archive.crvm> <dirasroot>" << std::endl;
return 1;
}
auto sdfs= std::make_shared<SubdirFilesystem>(Tesses::Framework::Filesystem::LocalFS,std::string(argv[2]));
FILE* f = fopen(argv[1],"rb");
if(f == NULL)
auto strm= LocalFS->OpenFile(argv[1], "rb");
if(strm->CanRead())
{
printf("ERROR: could not open %s\n", argv[1]);
std::cout << "ERROR: could not open " << argv[1] << std::endl;
return 1;
}
auto strm = std::make_shared<FileStream>(f,true,"rb",true);
auto res = CrossArchiveExtract(strm,sdfs);
auto res = Tesses::CrossLang::CrossArchiveExtract(strm,sdfs);
std::cout << "Crvm Name: " << res.first.first << std::endl;
std::cout << "Crvm Version: " << res.first.second.ToString() << std::endl;
std::cout << "Crvm Info: " << std::endl << res.second << std::endl;
return 0;
}
}

View File

@@ -1,20 +1,20 @@
#include "CrossLang.hpp"
#include <iostream>
using namespace Tesses::CrossLang;
void Ensure(Tesses::Framework::Streams::Stream& strm,uint8_t* buffer, size_t len)
namespace Tesses::CrossLang::Programs {
static void Ensure(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,uint8_t* buffer, size_t len)
{
if(strm.ReadBlock(buffer,len) != len)
if(strm->ReadBlock(buffer,len) != len)
{
throw VMException("Could not read " + std::to_string(len) + " byte(s).");
}
}
uint32_t EnsureInt(Tesses::Framework::Streams::Stream& strm)
static uint32_t EnsureInt(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
{
uint8_t buff[4];
Ensure(strm,buff,sizeof(buff));
return BitConverter::ToUint32BE(buff[0]);
}
std::string EnsureString(Tesses::Framework::Streams::Stream& strm)
static std::string EnsureString(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
{
size_t len = (size_t)EnsureInt(strm);
std::string myStr={};
@@ -22,30 +22,24 @@ std::string EnsureString(Tesses::Framework::Streams::Stream& strm)
Ensure(strm,(uint8_t*)myStr.data(), len);
return myStr;
}
void DumpFile(std::filesystem::path p)
void CrossLangDump(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)
{
if(std::filesystem::is_regular_file(p))
uint8_t main_header[18];
Ensure(strm,main_header,sizeof(main_header));
if(strncmp((const char*)main_header,"TCROSSVM",8) != 0) throw VMException("Invalid TCrossVM image.");
TVMVersion version(main_header+8);
if(version.CompareToRuntime() == 1)
{
try
{
std::cout << "File: " << p.string() << std::endl;
Tesses::Framework::Streams::FileStream strm(p,"rb");
uint8_t main_header[18];
Ensure(strm,main_header,sizeof(main_header));
if(strncmp((const char*)main_header,"TCROSSVM",8) != 0) throw VMException("Invalid TCrossVM image.");
TVMVersion version(main_header+8);
if(version.CompareToRuntime() == 1)
{
throw VMException("Runtime is too old.");
}
TVMVersion v2(main_header+13);
std::cout << "Version: " << v2.ToString() << std::endl;
throw VMException("Runtime is too old.");
}
TVMVersion v2(main_header+13);
std::cout << "Version: " << v2.ToString() << std::endl;
size_t _len = (size_t)EnsureInt(strm);
size_t _len = (size_t)EnsureInt(strm);
std::cout << "SectionCount: " << _len << std::endl;
std::cout << "SectionCount: " << _len << std::endl;
std::vector<std::string> strs;
std::vector<std::string> strs;
std::unordered_map<uint32_t, std::vector<std::string>> funs;
std::vector<std::vector<std::string>> closures;
@@ -177,7 +171,7 @@ void DumpFile(std::filesystem::path p)
}
auto len = EnsureInt(strm);
strm.Seek(len,Tesses::Framework::Streams::SeekOrigin::Current);
strm->Seek(len,Tesses::Framework::Streams::SeekOrigin::Current);
closures.push_back(args);
}
@@ -208,7 +202,7 @@ void DumpFile(std::filesystem::path p)
}
else
{
strm.Seek((int64_t)tableLen,Tesses::Framework::Streams::SeekOrigin::Current);
strm->Seek((int64_t)tableLen,Tesses::Framework::Streams::SeekOrigin::Current);
}
}
if(hasIcon)
@@ -252,22 +246,10 @@ void DumpFile(std::filesystem::path p)
for(auto str : strs) {
std::cout << EscapeString(str, true) << std::endl;
}
}
catch(std::exception& ex)
{
std::cout << "Error when reading file \"" << p.string() << "\" " << ex.what() << std::endl;
}
}
else
{
std::cout << "CrossVM file \"" << p.string() << "\" does not exist." << std::endl;
}
}
int main(int argc, char** argv)
{
Tesses::Framework::TF_Init();
for(int i = 1; i < argc; i++)
{
DumpFile(argv[i]);
}
}
}

View File

@@ -3,10 +3,12 @@
#include <string>
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Http;
bool Download(Tesses::Framework::Filesystem::VFSPath filename,std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs)
namespace Tesses::CrossLang::Programs
{
static bool Download(Tesses::Framework::Filesystem::VFSPath filename,std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs)
{
while(true)
{
@@ -22,7 +24,7 @@ bool Download(Tesses::Framework::Filesystem::VFSPath filename,std::shared_ptr<Te
if(resp.statusCode == StatusCode::OK)
{
auto strm = resp.ReadAsStream();
CrossArchiveExtract(strm, vfs);
CrossLang::CrossArchiveExtract(strm, vfs);
return true;
}
@@ -46,26 +48,21 @@ bool Download(Tesses::Framework::Filesystem::VFSPath filename,std::shared_ptr<Te
return false;
}
int main(int argc, char** argv)
TObject CrossLangShell(GCList& ls, std::vector<std::string>& argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
Tesses::Framework::Filesystem::VFSPath dir = GetCrossLangConfigDir();
Tesses::Framework::Filesystem::VFSPath filename = dir / "Shell" / "Shell.crvm";
auto p = Tesses::Framework::Platform::Environment::GetRealExecutablePath(Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[0])).GetParent().GetParent() / "share" / "Tesses" / "CrossLang" / "Tesses.CrossLang.ShellPackage-1.0.0.0-prod.crvm";
if(argc == 2 && strcmp(argv[1],"configdir") == 0)
if(argv.size() == 2 && argv[1] == "configdir")
{
std::cout << dir.ToString() << std::endl;
return 0;
}
if(argc > 1 && strcmp(argv[1],"update-shell") == 0)
if(argv.size() > 1 && argv[1] == "update-shell")
{
auto subdir = std::make_shared<Tesses::Framework::Filesystem::SubdirFilesystem>(Tesses::Framework::Filesystem::LocalFS,dir);
@@ -76,7 +73,7 @@ int main(int argc, char** argv)
if(resp.statusCode == StatusCode::OK)
{
auto strm = resp.ReadAsStream();
CrossArchiveExtract(strm, subdir);
CrossLang::CrossArchiveExtract(strm, subdir);
return 0;
}
@@ -97,7 +94,7 @@ int main(int argc, char** argv)
auto strm = Tesses::Framework::Filesystem::LocalFS->OpenFile(p,"rb");
if(strm != nullptr)
{
CrossArchiveExtract(strm, subdir);
CrossLang::CrossArchiveExtract(strm, subdir);
}
else
@@ -113,29 +110,24 @@ int main(int argc, char** argv)
}
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
TStd::RegisterStd(ls.GetGC(),env);
env->LoadFileWithDependencies(&gc, Tesses::Framework::Filesystem::LocalFS, filename);
env->LoadFileWithDependencies(ls.GetGC(), Tesses::Framework::Filesystem::LocalFS, filename);
TList* args = TList::Create(ls);
args->Add(filename.ToString());
for(int arg=1;arg<argc;arg++)
for(size_t arg=1;arg<argv.size();arg++)
args->Add(std::string(argv[arg]));
auto res = env->CallFunctionWithFatalError(ls,"main",{args});
int64_t iresult;
if(GetObject(res,iresult))
return (int)iresult;
return 0;
return env->CallFunctionWithFatalError(ls,"main",{args});
}
}

View File

@@ -0,0 +1,290 @@
#include "CrossLang.hpp"
#include <iostream>
#include <fstream>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Filesystem;
namespace Tesses::CrossLang::Programs {
static void Help(std::string filename)
{
std::cout << "USAGE: " << filename << " [OPTIONS] source_file1 source_file2 source_file_n" << std::endl;
printf("OPTIONS:\n");
printf(" -o: Output directory (OUTDIR, defaults to ./bin)\n");
printf(" -i: Set info (ex {\"maintainer\": \"Mike Nolan\", \"repo\": \"https://example.com/\", \"homepage\": \"https://example.com/\",\"license\":\"MIT\"})\n");
printf(" -I: Set icon resource name (in the resource folder), should be a 128x128 png\n");
printf(" -v: Set version (1.0.0.0-prod defaults to 1.0.0.0-dev)\n");
printf(" -d: Add dependency (DependencyName-1.0.0.0-prod)\n");
printf(" -D: enable debug)\n");
printf(" -t: Declare a tool (ToolName-1.0.0.0-prod)\n");
printf(" -n: Set name (MyAppOrLibName defaults to out)\n");
printf(" -r: Set resource directory (RESDIR defaults to res)\n");
printf(" -h, --help: Prints help\n");
printf(" -e: Set comptime permissions defaults to none, none for no support, \"secure\" for sane without file access, \"secure_file\" for sane with file access to current directory and sub directories, \"full\" has full runtime.\n");
printf("Options except for help have flag with arg like this: -F ARG\n");
exit(1);
}
void CrossLangCompiler(std::vector<std::string>& argv)
{
/*std::ifstream strm(argv[1],std::ios_base::in|std::ios_base::binary);
std::vector<LexToken> tokens;
Lex(argv[1],strm,tokens);
Parser parser(tokens);
CodeGen gen;
gen.GenRoot(parser.ParseRoot());
std::vector<uint8_t> data;
ByteCodeVectorWriter w(data);
gen.Save(std::filesystem::current_path(),w);
*/
TF_InitWithConsole();
std::filesystem::path outputDir = std::filesystem::current_path() / "bin";
std::vector<std::filesystem::path> source;
std::filesystem::path resourceDir = std::filesystem::current_path() / "res";
std::vector<std::pair<std::string, TVMVersion>> dependencies;
std::vector<std::pair<std::string, TVMVersion>> tools;
std::string name="out";
std::string info="{}";
std::string icon="";
std::string comptime="none";
TVMVersion version;
bool debug=false;
for(size_t i = 1; i < argv.size(); i++)
{
if(argv[i] == "--help" || argv[i] == "-h")
{
Help(argv[0]);
}
else if(argv[i] == "-o")
{
i++;
if(i < argv.size())
{
outputDir = argv[i];
}
}
else if(argv[i] == "-r")
{
i++;
if(i < argv.size())
{
resourceDir = argv[i];
}
}
else if(argv[i] == "-e")
{
i++;
if(i < argv.size())
{
comptime = argv[i];
}
}
else if(argv[i] == "-i")
{
i++;
if(i < argv.size())
{
info = argv[i];
}
}
else if(argv[i] == "-I")
{
i++;
if(i < argv.size())
{
icon = argv[i];
}
}
else if(argv[i] == "-d")
{
i++;
if(i < argv.size())
{
std::string str = argv[i];
auto lastDash = str.find_last_of('-');
if(lastDash < str.size())
{
std::string str2 = str.substr(lastDash+1);
if(str2 == "dev" || str2 == "alpha" || str2 == "beta" || str2 == "prod")
{
lastDash = str.find_last_of('-',lastDash-1);
}
std::string str1 = str.substr(0,lastDash);
str2 = str.substr(lastDash+1);
TVMVersion v2;
if(!TVMVersion::TryParse(str2,v2))
{
printf("ERROR: Invalid syntax for version\n");
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
exit(1);
}
dependencies.push_back(std::pair<std::string,TVMVersion>(str1,v2));
}
else
{
printf("ERROR: Dependency must have version\n");
exit(1);
}
}
}
else if(argv[i] == "-t")
{
i++;
if(i < argv.size())
{
std::string str = argv[i];
auto lastDash = str.find_last_of('-');
if(lastDash < str.size())
{
std::string str2 = str.substr(lastDash+1);
if(str2 == "dev" || str2 == "alpha" || str2 == "beta" || str2 == "prod")
{
lastDash = str.find_last_of('-',lastDash-1);
}
std::string str1 = str.substr(0,lastDash);
str2 = str.substr(lastDash+1);
TVMVersion v2;
if(!TVMVersion::TryParse(str2,v2))
{
printf("ERROR: Invalid syntax for version\n");
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
exit(1);
}
tools.push_back(std::pair<std::string,TVMVersion>(str1,v2));
}
else
{
printf("ERROR: Tool must have version\n");
exit(1);
}
}
}
else if(argv[i] == "-n")
{
i++;
if(i < argv.size())
{
name = argv[i];
}
}
else if(argv[i] == "-v")
{
i++;
if(i < argv.size())
{
if(!TVMVersion::TryParse(argv[i],version))
{
printf("ERROR: Invalid syntax for version\n");
printf("Expected MAJOR[.MINOR[.PATCH[.BUILD[-dev,-alpha,-beta,-prod]]]]\n");
exit(1);
}
}
}
else if(argv[i] == "-D" || argv[i] == "--debug")
{
debug = true;
}
else {
source.push_back(argv[i]);
}
}
if(source.empty())
{
Help(argv[0]);
}
std::vector<LexToken> tokens;
for(auto src : source)
{
std::ifstream strm(src,std::ios_base::in|std::ios_base::binary);
int res = Lex(std::filesystem::absolute(src).string(),strm,tokens);
}
GC* gc=nullptr;
GCList* ls=nullptr;
TRootEnvironment* env=nullptr;
if(comptime != "none")
{
gc = new GC();
gc->Start();
ls = new GCList(gc);
env = TRootEnvironment::Create(ls,TDictionary::Create(ls));
if(comptime == "secure")
{
TStd::RegisterConsole(gc,env);
TStd::RegisterClass(gc,env);
TStd::RegisterCrypto(gc,env);
TStd::RegisterDictionary(gc,env);
TStd::RegisterJson(gc,env);
TStd::RegisterRoot(gc,env);
TStd::RegisterIO(gc,env,false);
env->permissions.locked=true;
}
else if(comptime == "secure_file")
{
TStd::RegisterConsole(gc,env);
TStd::RegisterClass(gc,env);
TStd::RegisterCrypto(gc,env);
TStd::RegisterDictionary(gc,env);
TStd::RegisterJson(gc,env);
TStd::RegisterRoot(gc,env);
TStd::RegisterIO(gc,env,false);
env->permissions.locked=true;
auto fs = env->EnsureDictionary(gc,"FS");
fs->SetValue("Local", std::make_shared<SubdirFilesystem>(LocalFS,Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory()));
}
else if(comptime == "full")
{
TStd::RegisterStd(gc,env);
env->permissions.locked=true;
}
}
Parser parser(tokens,gc,env);
parser.debug = debug;
CodeGen gen;
auto sfs = std::make_shared<SubdirFilesystem>(LocalFS,LocalFS->SystemToVFSPath(resourceDir.string()));
gen.embedFS = sfs;
gen.GenRoot(parser.ParseRoot());
gen.name = name;
gen.version = version;
gen.info = info;
gen.icon = icon;
for(auto deps : dependencies)
{
gen.dependencies.push_back(deps);
}
for(auto tool : tools)
{
gen.tools.push_back(tool);
}
std::filesystem::create_directory(outputDir);
{
auto strm = std::make_shared<Tesses::Framework::Streams::FileStream>(outputDir / (name + "-" + version.ToString() + ".crvm"),"wb");
gen.Save(strm);
}
if(gc != nullptr)
{
delete ls;
delete gc;
}
}
}

View File

@@ -4,20 +4,13 @@
#include <sstream>
#include <vector>
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
namespace Tesses::CrossLang::Programs {
TObject CrossLangInterperter(GCList& ls,TRootEnvironment* env,std::vector<std::string>& argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
if(argc > 1)
GC* gc = ls.GetGC();
if(argv.size() > 1)
{
std::ifstream strm(argv[1],std::ios_base::in|std::ios_base::binary);
std::vector<LexToken> tokens;
@@ -32,30 +25,28 @@ int main(int argc, char** argv)
gen.GenRoot(parser.ParseRoot());
std::vector<uint8_t> data;
{
auto strm2 = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
gen.Save(strm2);
auto strm2 = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
gen.Save(strm2);
{
TFile* file = TFile::Create(ls);
{
TFile* file = TFile::Create(ls);
strm2->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
file->Load(&gc,strm2);
strm2->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
file->Load(gc,strm2);
env->LoadFile(&gc, file);
env->LoadFile(gc, file);
}
}
}
TList* args = TList::Create(ls);
for(int arg=1;arg<argc;arg++)
args->Add(std::string(argv[arg]));
TList* args = TList::Create(ls);
for(int arg=1;arg<argv.size();arg++)
args->Add(std::string(argv[arg]));
auto res = env->CallFunctionWithFatalError(ls,"main",{args});
int64_t iresult;
if(GetObject(res,iresult))
return (int)iresult;
return env->CallFunctionWithFatalError(ls,"main",{args});
}
else
@@ -91,7 +82,7 @@ int main(int argc, char** argv)
}
else if(source == "exit")
{
return 0;
return (int64_t)0;
}
else
{
@@ -116,9 +107,9 @@ int main(int argc, char** argv)
TFile* file = TFile::Create(ls);
strm2->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
file->Load(&gc,strm2);
file->Load(gc,strm2);
env->LoadFile(&gc, file);
env->LoadFile(gc, file);
}
@@ -126,4 +117,8 @@ int main(int argc, char** argv)
}
}
return (int64_t)0;
}
}

View File

@@ -0,0 +1,61 @@
#include "CrossLang.hpp"
using namespace Tesses::Framework;
namespace Tesses::CrossLang::Programs {
TObject CrossLangVM(GCList& ls,TRootEnvironment* env, std::vector<std::string>& argv)
{
if(argv.size() < 2)
{
std::cout << "USAGE: " << (argv.empty() ? (std::string)"crossvm" : argv[0]) << " <filename.crvm> <args...>" << std::endl;
return 1;
}
env->LoadFileWithDependencies(ls.GetGC(), Tesses::Framework::Filesystem::LocalFS, Tesses::Framework::Filesystem::LocalFS->SystemToVFSPath(argv[1]));
if(env->HasVariable("WebAppMain"))
{
Args args(argv);
int port = 4206;
for(auto& item : args.options)
{
if(item.first == "port")
{
port = std::stoi(item.second);
}
}
env->EnsureDictionary(ls.GetGC(),"Net")->SetValue("WebServerPort", (int64_t)port);
TList* args2 = TList::Create(ls);
for(auto& item : args.positional)
{
args2->Add(item);
}
auto res = env->CallFunctionWithFatalError(ls, "WebAppMain", {args2});
auto svr2 = Tesses::CrossLang::ToHttpServer(ls.GetGC(),res);
if(svr2 == nullptr) return 1;
Tesses::Framework::Http::HttpServer svr(port,svr2);
svr.StartAccepting();
TF_RunEventLoop();
TDictionary* _dict;
TClassObject* _co;
if(GetObjectHeap(res,_dict))
{
_dict->CallMethod(ls,"Close",{});
}
if(GetObjectHeap(res,_co))
{
_co->CallMethod(ls,"","Close",{});
}
TF_Quit();
return 0;
}
else {
TList* args = TList::Create(ls);
for(size_t arg=1;arg<argv.size();arg++)
args->Add(std::string(argv[arg]));
return env->CallFunctionWithFatalError(ls,"main",{args});
}
}
}

View File

@@ -0,0 +1,9 @@
#include "CrossLang.hpp"
int main(int argc, char** argv)
{
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
return (int)Tesses::CrossLang::Programs::CrossArchiveCreate(args);
}

View File

@@ -0,0 +1,9 @@
#include "CrossLang.hpp"
int main(int argc, char** argv)
{
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
return (int)Tesses::CrossLang::Programs::CrossArchiveExtract(args);
}

View File

@@ -0,0 +1,25 @@
#include "CrossLang.hpp"
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
auto res = Programs::CrossLangShell(ls, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}

View File

@@ -0,0 +1,23 @@
#include "CrossLang.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
Programs::CrossLangCompiler(args);
return 0;
}

View File

@@ -0,0 +1,28 @@
#include "CrossLang.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
for(int i = 1; i < argc; i++)
{
VFSPath path(argv[i]);
if(LocalFS->FileExists(path))
{
std::cout << "File: " << path.ToString() << std::endl;
auto strm = LocalFS->OpenFile(path, "rb");
Programs::CrossLangDump(strm);
}
else {
std::cout << "File: " << path.ToString() << " does not exist." << std::endl;
}
}
}

View File

@@ -0,0 +1,29 @@
#include "CrossLang.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
auto res = Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}

View File

@@ -0,0 +1,29 @@
#include "CrossLang.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
TF_InitWithConsole();
if(argc > 0)
TF_AllowPortable(argv[0]);
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
auto res = Programs::CrossLangVM(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}

164
src/programs/slim.cpp Normal file
View File

@@ -0,0 +1,164 @@
#include "CrossLang.hpp"
#include "TessesFramework/Filesystem/VFS.hpp"
using namespace Tesses::Framework;
using namespace Tesses::CrossLang;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
//crosslang crossint
//crosslang
//crosslang ...
std::string programName = "crosslang";
TF_InitWithConsole();
if(argc > 0)
{
TF_AllowPortable(argv[0]);
Tesses::Framework::Filesystem::VFSPath path=(std::string)argv[0];
path.RemoveExtension();
programName = path.GetFileName();
}
std::vector<std::string> args(argc);
for(int i = 0; i < argc; i++)
args[i] = argv[i];
if(programName == "crossint")
{
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}
else if(programName == "crossc")
{
Programs::CrossLangCompiler(args);
return 0;
}
else if(programName == "crossarchivecreate")
{
Programs::CrossArchiveCreate(args);
return 0;
}
else if(programName == "crossarchiveextract")
{
Programs::CrossArchiveExtract(args);
return 0;
}
else if(programName == "crossdump")
{
for(size_t i = 1; i < args.size(); i++)
{
VFSPath path = args[i];
if(LocalFS->FileExists(path))
{
std::cout << "File: " << path.ToString() << std::endl;
auto strm = LocalFS->OpenFile(path, "rb");
Programs::CrossLangDump(strm);
}
else {
std::cout << "File: " << path.ToString() << " does not exist." << std::endl;
}
}
return 0;
}
else if(programName == "crossvm")
{
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangVM(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}
else if(args.size() > 1)
{
if(args[1] == "crossint")
{
args.erase(args.begin());
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangInterperter(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}
else if(args[1] == "crossc")
{
args.erase(args.begin());
Programs::CrossLangCompiler(args);
return 0;
}
else if(args[1] == "crossarchivecreate")
{
args.erase(args.begin());
Programs::CrossArchiveCreate(args);
return 0;
}
else if(args[1] == "crossarchiveextract")
{
args.erase(args.begin());
Programs::CrossArchiveExtract(args);
return 0;
}
else if(args[1] == "crossdump")
{
for(size_t i = 2; i < args.size(); i++)
{
VFSPath path = args[i];
if(LocalFS->FileExists(path))
{
std::cout << "File: " << path.ToString() << std::endl;
auto strm = LocalFS->OpenFile(path, "rb");
Programs::CrossLangDump(strm);
}
else {
std::cout << "File: " << path.ToString() << " does not exist." << std::endl;
}
}
return 0;
}
else if(args[1] == "crossvm")
{
args.erase(args.begin());
GC gc;
gc.Start();
GCList ls(gc);
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
TStd::RegisterStd(&gc,env);
auto res= Programs::CrossLangVM(ls, env, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
}
}
GC gc;
gc.Start();
GCList ls(gc);
auto res= Programs::CrossLangShell(ls, args);
int64_t myi64;
if(GetObject(res,myi64))
return (int)myi64;
return 0;
return 0;
}

View File

@@ -354,6 +354,11 @@ namespace Tesses::CrossLang
}
return nullptr;
});
#if defined(CROSSLANG_ENABLE_SUPERSLIM)
dict->SetValue("SuperSlim", true);
#else
dict->SetValue("SuperSlim", false);
#endif
dict->DeclareFunction(gc, "Eval", "Eval source code",{"source"}, VM_Eval);
dict->DeclareFunction(gc, "Compile", "Compile Source",{"dict"},VM_Compile);