From 18b15136b51d4e04f95de4d3765a3ac9da02daf6 Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Thu, 12 Jun 2025 15:48:37 -0500 Subject: [PATCH] Add GUI Support --- .vscode/c_cpp_properties.json | 5 +- CMakeLists.txt | 1 + include/CrossLang.hpp | 2 + src/runtime_methods/std.cpp | 2 + src/runtime_methods/vm.cpp | 111 ++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 3 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3b67b92..442735f 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -16,11 +16,10 @@ "CROSSLANG_ENABLE_TERMIOS=1", "CROSSLANG_ENABLE_MBED=1", "CROSSLANG_ENABLE_SQLITE=1", - "CROSSLANG_ENABLE_SDL2=1", + "TESSESFRAMEWORK_ENABLE_SDL2=1", "CROSSLANG_ENABLE_PROCESS=1", "CROSSLANG_ENABLE_FFI=1", - "CROSSLANG_ENABLE_SHARED=1", - "CROSSLANG_ENABLE_GOBJECT_FFI=1" + "CROSSLANG_ENABLE_SHARED=1" ], "compilerPath": "/usr/bin/gcc", "cStandard": "c17", diff --git a/CMakeLists.txt b/CMakeLists.txt index 5997f5a..b436c59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,6 +143,7 @@ src/runtime_methods/ogc.cpp src/runtime_methods/path.cpp src/runtime_methods/env.cpp src/runtime_methods/process.cpp +src/runtime_methods/sdl2.cpp src/types/associativearray.cpp src/types/any.cpp src/types/datetime.cpp diff --git a/include/CrossLang.hpp b/include/CrossLang.hpp index bf4211d..eb32fdd 100644 --- a/include/CrossLang.hpp +++ b/include/CrossLang.hpp @@ -1762,6 +1762,7 @@ class GC { bool canRegisterOGC; bool canRegisterEnv; bool canRegisterClass; + bool canRegisterSDL2; bool sqlite3Scoped; bool locked; }; @@ -1821,6 +1822,7 @@ class GC { static void RegisterEnv(GC* gc, TRootEnvironment* env); static void RegisterProcess(GC* gc, TRootEnvironment* env); static void RegisterClass(GC* gc, TRootEnvironment* env); + static void RegisterSDL2(GC* gc,TRootEnvironment* env); }; class TSubEnvironment : public TEnvironment diff --git a/src/runtime_methods/std.cpp b/src/runtime_methods/std.cpp index abfd52e..1f88253 100644 --- a/src/runtime_methods/std.cpp +++ b/src/runtime_methods/std.cpp @@ -933,6 +933,7 @@ namespace Tesses::CrossLang env->DeclareFunction(gc, "TypeIsDateTime","Get whether object is a DateTime",{"object"},TypeIsDateTime); + newTypes->DeclareFunction(gc, "Regex", "Create regex object",{"regex"},[](GCList& ls,std::vector args)->TObject { std::string str; if(GetArgument(args,0,str)) @@ -1075,6 +1076,7 @@ namespace Tesses::CrossLang RegisterOGC(gc, env); RegisterProcess(gc,env); RegisterClass(gc,env); + RegisterSDL2(gc,env); gc->RegisterEverything(env); diff --git a/src/runtime_methods/vm.cpp b/src/runtime_methods/vm.cpp index 95295e5..b35eaf2 100644 --- a/src/runtime_methods/vm.cpp +++ b/src/runtime_methods/vm.cpp @@ -5,6 +5,101 @@ namespace Tesses::CrossLang { + + class OnItterationObj : public TNativeObject + { + private: + GC* gc; + std::vector callables; + std::shared_ptr> fevent; + public: + OnItterationObj(GC* gc) + { + this->gc=gc; + this->fevent = std::make_shared>( + [this](uint64_t n)->void{ + this->Exec(n); + } + ); + Tesses::Framework::OnItteraton += this->fevent; + } + ~OnItterationObj() + { + Tesses::Framework::OnItteraton -= this->fevent; + } + std::string TypeName() + { + return "OnItteration"; + } + TObject CallMethod(GCList& ls, std::string key, std::vector args) + { + if(key == "operator+") + { + TCallable* callable; + if(GetArgumentHeap(args,0,callable)) + { + gc->BarrierBegin(); + bool found=false; + for(auto item : this->callables) + { + if(item == callable) {found=true; break;} + } + if(!found) + { + this->callables.push_back(callable); + } + gc->BarrierEnd(); + } + return this; + } + if(key == "operator-") + { + TCallable* callable; + if(GetArgumentHeap(args,0,callable)) + { + gc->BarrierBegin(); + + for(auto index = this->callables.begin(); index < this->callables.end(); index++) + { + if(*index == callable) { + this->callables.erase(index); + break; + } + } + + gc->BarrierEnd(); + } + return this; + } + if(key == "ToString") + { + gc->BarrierBegin(); + std::string str = "Registered: " + std::to_string(this->callables.size()); + gc->BarrierEnd(); + return str; + } + return Undefined(); + } + void Mark() + { + if(this->marked) return; + this->marked=true; + + for(auto item : callables) item->Mark(); + } + void Exec(uint64_t n) + { + gc->BarrierBegin(); + for(auto item : callables) + { + gc->BarrierEnd(); + GCList ls(gc); + item->Call(ls,{(int64_t)n}); + gc->BarrierBegin(); + } + gc->BarrierEnd(); + } + }; static TObject AstToTObject(GCList& ls,SyntaxNode node) { if(std::holds_alternative(node)) @@ -317,8 +412,24 @@ namespace Tesses::CrossLang dict->DeclareFunction(gc, "getRuntimeVersion","Get the runtime version",{},[](GCList& ls,std::vector args)->TObject { return TVMVersion(TVM_MAJOR,TVM_MINOR,TVM_PATCH,TVM_BUILD,TVM_VERSIONSTAGE); }); + dict->DeclareFunction(gc, "getIsRunning","Is the program still running",{},[](GCList& ls, std::vector args)->TObject { + return Tesses::Framework::TF_IsRunning(); + }); + dict->DeclareFunction(gc, "RunEventLoopItteration","Run Event Loop Itteration",{},[](GCList& ls, std::vector args)->TObject { + Tesses::Framework::TF_RunEventLoopItteration(); + return Undefined(); + }); + dict->DeclareFunction(gc, "RunEventLoop","Run Event Loop",{},[](GCList& ls, std::vector args)->TObject { + Tesses::Framework::TF_RunEventLoop(); + return Undefined(); + }); + gc->BarrierBegin(); + auto ittrobj = TNativeObject::Create(ls,gc); + + + dict->SetValue("OnItteration", ittrobj); env->DeclareVariable("VM", dict); gc->BarrierEnd(); }