From 05713fc39c2f126bf45dc7119ce05b308b6484db Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Thu, 21 Aug 2025 08:18:29 -0500 Subject: [PATCH] Add custom console and allow runtimes to set the config dir --- include/CrossLang.hpp | 3 +++ src/runtime_methods/class.cpp | 5 ++++- src/runtime_methods/console.cpp | 10 +++++++++- src/runtime_methods/env.cpp | 4 ++++ src/runtime_methods/net.cpp | 2 ++ src/runtime_methods/std.cpp | 2 +- src/runtime_methods/vm.cpp | 10 +++++++--- src/types/associativearray.cpp | 2 ++ src/types/rootenvironment.cpp | 1 + src/vm/vm.cpp | 16 ++++++++++++++++ 10 files changed, 49 insertions(+), 6 deletions(-) diff --git a/include/CrossLang.hpp b/include/CrossLang.hpp index cb803e3..176245f 100644 --- a/include/CrossLang.hpp +++ b/include/CrossLang.hpp @@ -1813,6 +1813,7 @@ class GC { bool canRegisterClass; bool sqlite3Scoped; bool locked; + TDictionary* customConsole =nullptr; }; class TRootEnvironment : public TEnvironment @@ -2565,4 +2566,6 @@ class GC { MarkedTObject CreateMarkedTObject(GCList& gc, TObject o); std::string JoinPeriod(std::vector& p); TObject GetClassInfo(GCList& ls,TFile* f, uint32_t index); + + extern Tesses::Framework::Filesystem::VFSPath CrossLangConfigPath; }; diff --git a/src/runtime_methods/class.cpp b/src/runtime_methods/class.cpp index c228dc9..5e034dc 100644 --- a/src/runtime_methods/class.cpp +++ b/src/runtime_methods/class.cpp @@ -266,7 +266,8 @@ namespace Tesses::CrossLang TClassObject* co; if(GetArgumentHeap(args, 0, co)) { - return TDictionary::Create(ls, + ls.GetGC()->BarrierBegin(); + auto res= TDictionary::Create(ls, { TDItem("Name", co->name), TDItem("File", co->file), @@ -275,6 +276,8 @@ namespace Tesses::CrossLang TDItem("Entries", ClassInstanceToList(ls,co)) } ); + ls.GetGC()->BarrierEnd(); + return res; } return nullptr; }); diff --git a/src/runtime_methods/console.cpp b/src/runtime_methods/console.cpp index 7d902a9..178bb38 100644 --- a/src/runtime_methods/console.cpp +++ b/src/runtime_methods/console.cpp @@ -195,7 +195,15 @@ namespace Tesses::CrossLang { } void TStd::RegisterConsole(GC* gc,TRootEnvironment* env) { - env->permissions.canRegisterConsole=true; + env->permissions.canRegisterConsole=true; + if(env->permissions.customConsole != nullptr) + { + gc->BarrierBegin(); + env->DeclareVariable("Console", env->permissions.customConsole ); + gc->BarrierEnd(); + return; + } + #ifdef CROSSLANG_ENABLE_TERMIOS tcgetattr(0, &orig_termios); atexit(disableRawMode); diff --git a/src/runtime_methods/env.cpp b/src/runtime_methods/env.cpp index 30badda..a59fbc6 100644 --- a/src/runtime_methods/env.cpp +++ b/src/runtime_methods/env.cpp @@ -13,9 +13,13 @@ namespace Tesses::CrossLang static char EnvPathSeperator=':'; #endif + Tesses::Framework::Filesystem::VFSPath CrossLangConfigPath(""); + Tesses::Framework::Filesystem::VFSPath GetCrossLangConfigDir() { + if(!CrossLangConfigPath.path.empty()) + return CrossLangConfigPath; return SpecialFolders::GetConfig() / "Tesses" / "CrossLang"; } diff --git a/src/runtime_methods/net.cpp b/src/runtime_methods/net.cpp index 3f97658..a3598d7 100644 --- a/src/runtime_methods/net.cpp +++ b/src/runtime_methods/net.cpp @@ -480,7 +480,9 @@ namespace Tesses::CrossLang GCList ls2(this->ls->GetGC()); auto res = CreateDictionaryFromServerContext(ls2,&ctx); bool result; + this->ls->GetGC()->BarrierBegin(); auto callableO = clsObj->GetValue("","Handle"); + this->ls->GetGC()->BarrierEnd(); TCallable* callable; if(GetObjectHeap(callableO, callable)) { diff --git a/src/runtime_methods/std.cpp b/src/runtime_methods/std.cpp index 31cb7ba..9474257 100644 --- a/src/runtime_methods/std.cpp +++ b/src/runtime_methods/std.cpp @@ -46,7 +46,7 @@ namespace Tesses::CrossLang if(value == "true") { items.push_back(std::pair(key,true)); } else if(value == "false") { - items.push_back(std::pair(key,true)); + items.push_back(std::pair(key,false)); } else if(value == "null") { items.push_back(std::pair(key,nullptr)); } else { diff --git a/src/runtime_methods/vm.cpp b/src/runtime_methods/vm.cpp index 234502c..28b3b7c 100644 --- a/src/runtime_methods/vm.cpp +++ b/src/runtime_methods/vm.cpp @@ -387,15 +387,19 @@ namespace Tesses::CrossLang }); dict->DeclareFunction(gc, "getRootEnvironment","Get root environment, for reflection purposes",{},[env](GCList& ls2,std::vector args)->TObject {return env;}); dict->DeclareFunction(gc, "getCurrentEnvironment","Get current environment, for reflection purposes",{},VM_getCurrentEnvironment); - dict->DeclareFunction(gc, "CreateEnvironment","Create root environment",{"$dict"},[](GCList& ls,std::vector args)->TObject{ + dict->DeclareFunction(gc, "CreateEnvironment","Create root environment",{"$dict"},[env](GCList& ls,std::vector args)->TObject{ TDictionary* dict; if(GetArgumentHeap(args,0,dict)) { - return TRootEnvironment::Create(ls,dict); + auto renv = TRootEnvironment::Create(ls,dict); + renv->permissions.customConsole = env->permissions.customConsole; + return renv; } else { - return TRootEnvironment::Create(ls,TDictionary::Create(ls)); + auto renv = TRootEnvironment::Create(ls,TDictionary::Create(ls)); + renv->permissions.customConsole = env->permissions.customConsole; + return renv; } }); dict->DeclareFunction(gc, "LoadExecutable", "Load a crossvm executable",{"stream"},[](GCList& ls,std::vector args)->TObject{ diff --git a/src/types/associativearray.cpp b/src/types/associativearray.cpp index de45a9a..19866ff 100644 --- a/src/types/associativearray.cpp +++ b/src/types/associativearray.cpp @@ -105,6 +105,8 @@ namespace Tesses::CrossLang } void TAssociativeArray::Mark() { + if(this->marked) return; + this->marked=true; for(auto& item : this->items) { GC::Mark(item.first); diff --git a/src/types/rootenvironment.cpp b/src/types/rootenvironment.cpp index deac241..9b41f62 100644 --- a/src/types/rootenvironment.cpp +++ b/src/types/rootenvironment.cpp @@ -311,6 +311,7 @@ namespace Tesses::CrossLang { if(this->marked) return; this->marked = true; this->dict->Mark(); + if(this->permissions.customConsole != nullptr) this->permissions.customConsole->Mark(); for(auto defer : this->defers) defer->Mark(); if(this->error != nullptr) this->error->Mark(); } diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index 37a64d2..209c4ad 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -3311,6 +3311,22 @@ namespace Tesses::CrossLang { gc->BarrierEnd(); } } + if(key == "SetCustomConsole") + { + TDictionary* dict; + if(!rootEnv->permissions.locked && GetArgumentHeap(args,0, dict)) + { + gc->BarrierBegin(); + rootEnv->permissions.customConsole = dict; + gc->BarrierEnd(); + } + else if(!rootEnv->permissions.locked && myEnv->permissions.customConsole == nullptr) + { + gc->BarrierBegin(); + rootEnv->permissions.customConsole=nullptr; + gc->BarrierEnd(); + } + } if(key == "RegisterEverything") { if(myEnv->permissions.canRegisterEverything)